Attempting to combine Z-Wave Switch and ESP8266 Relay Control

Disclaimer: I’m a very amateur coder…

I’m attempting to combine two working device handlers (Built-in Generic Z-Wave Switch & Custom ESP8266 Relay Controller) into one so that I can address it as a single device in ST. The use case is that I have a Hunter ceiling fan with no separate fan wire, so I zombified my remote with the ESP8266 and a relay board. The fan is wired to a GE Z-Wave Switch for on/off, and works fine as is. After cobbling together a device handler for the ESP8266, I was able to use ST as a virtual remote to control fan speed.

I’ve tried to extract all relevant code from the Z-Wave Switch Device Handler template and insert/modify into my custom device handler, but I must be missing something with state and I cannot figure out what.

Steps to reproduce:

  1. Delete existing devices (ESP8266 and Z-Wave Switch) from ST config

  2. Add new thing from ST app, pair Z-Wave Switch

  3. Change device handler in IDE to custom handler GitHub

  4. Use in-app device setup to add IP/Port URL parameters needed to connect to ESP8266

  5. Device now responds to on/off control from app as seen in log:

  6. Click any of the fan speed control buttons in app

  7. Z-Wave switch stops responding to on/off commands from app

  8. ESP8266 continues to respond to fan speed commands from app

Please let me know if I left out any relevant info, or if this is not the appropriate place to post.