Leviton wifi switches & dimmers

Good points.

The <system>-<device> naming was to prevent naming collisions. In other drivers I have written, it made sense to have multiple 'system' devices. Here is doesn't, so I'll shorten it to just <device>.

On the current state checking, also good point. But I'm inclined to use the cached value in Hubitat rather than doing a round trip ping to Leviton, because as you said that could add a lot of latency. The risk is that the status might be stale in Hubitat, but hopefully that is rare and would resolve on the refresh interval. What do you think about using the locally cached status on Hubitat to determine whether an update should be sent to Leviton? It would mitigate the issue you brought up.

EDIT: just read your response again, and you already made the same suggestion I did about comparing against cached values. I'll go with that.

FYI I just added this block of code to the top of the lev_update_switch function and it seems to work well...

if(power == 'ON' && device.currentValue("switch") == 'on')
{
    if(brightness != null)
    {
        if(device.currentValue("level") == brightness)
        {
            logDebug("${device.getName()} is already set to ${brightness}")
            return
        }
    }
    else
    {
        logDebug("${device.getName()} is already on")
        return
    }
}
else if(power == 'OFF' && device.currentValue("switch") = 'off')
{
    logDebug("${device.getName()} is already off")
    return
}

That's similar to what I had in mind.

I checked in both changes -- child device naming improvements and filtering out unnecessary update requests. Could you give them a try and let me know if they work as expected?

I looked at your source on GIT and the logic looks fine. I already made my change on my end and it's working, so I'm not going to bother updating right now. But your code looks fine to me.

FYI my combination of this driver and IFTTT is working good. There is only a 3-8 second delay in IFTTT updating the switch state and this code is at most allowing one duplicate call. So for example I can set up an automation tied to one of the switches being turned on/off and if I flick the switch manually it fires within 8 seconds or so even though I have the poll interval of the driver set to 60. (I might actually raise that up now, since it's not as crucial with this setup) The only issue is that setting these up using the IFTTT UI is tedious. I have 22 switches and have to set up separate on/off commands for each. I've only done half a dozen so far. Gonna have to set aside an hour or some to just plug away at it. (I wish they had a better UI)

1 Like

I think this one should be a device preference on each child device, with a global preference on the parent device which will be the default value when new child devices are created. Consider the case where a switch is meant to be an action instead of a trigger. Let's say I have a rule set up that says "When X happens, turn off switch S". Now assume the following sequence of events starting at time T, with a 1 minute refresh:

T+0: switch S is off
T+5s: switch S is turned on physically (Hubitat still thinks it is off since there has been no poll yet)
...
T+40s: X happens -> sends instruction to turn off S -> ignored because Hubitat doesn't know S is actually on

I agree. I added it as a selectable option, which requires updating the child switch/dimmer driver code.

Until there is built-in way to get more timely updates (quicker than the refresh interval), I agree that the default value for this option would be to not filter duplicates, so that is the default option in the driver.

I had a contact with someone at Leviton and got an answer on why Hubitat developers aren't receiving Dev Status -

"Unfortunately, our Wifi API is restricted to approved partners only. I spoke to our Leviton program manager, and he has had conversations with the Hubitat community. Thus far the business case for integrating our Wifi products are not sufficient to support the cost of integration. "

Hopefully, Hubitat will get popular enough to change their minds...

1 Like

That is interesting. Do you think he realizes that there would be little cost to them? The ask isn't necessarily for Leviton to provide a polished integration. If they provided whatever developer docs are available, the proposition is that the community will create and maintain the integration.

Hey there,
Have tried the Leviton WiFi solution you provided; still not able to get anywhere.
Refresh brings up an error; no child devices listed.

Have tried many times.

Any ideas?

Hello @cuirbear. What is the error? Could you provide a debug log of the output when you set your username and password and then save settings (PM is fine if you prefer)?

FYI, I recently added support for installation via Hubitat Package Manager, so you might consider installing from there just to ensure your installation stays updated and that there are no unexpected issues with having all of the needed code.

2 Likes

FYI this guy figured out how to connect to Leviton via websockets for his Homebridge plugin. No need for polling and status is updated instantly. I'm currently in the middle of a big project for my real job, but I thought maybe you might be interested in updating your Hubitat pulgin to use the same technique...

3 Likes

Thanks for the tip! It looks pretty straightforward in his code, so I'll take a stab at adding it to my driver.

2 Likes

@dsegall and I collaborated on version 1.2.0, which moves to cloud events for updates. Should be much faster (and hopefully more reliable).

1.2.0 - @tomw + @dsegall - Update device statuses from websocket events. No more polling.

This is updated on GitHub and the version was updated in my HPM listing.

Hi @tomw

I have been using your drivers since end of last year and they have worked well for my needs — thank you!

Recently, however I noticed issues with trying to dim the lights with Alexa. I tracked it down to March driver update.

The issue: “canSetlevel” will randomly flicker between true/false when switch goes on/off or when level changes. If it lands in false, I can no longer change brightness level for dimmer. If I refresh, the canSetLevel will flip back to true usually and then I can set level once or twice before it blocks again.

I reverted back to the previous driver version and the everything is functioning well. The canSetlevel is staying on true now...

Is this variable needed? Can we force it to true?

It sounds like the reporting from the leviton system is flaky or that we might need to tighten up the logic in the driver (or both). A possible quicker/easier solution might be to just make canSetLevel more sticky. For example, if it was ever set, never un-set it again for that device.

Unfortunately I don't have a system to test this on to debug. @dsegall, what are your thoughts on the best way to fix this?

Is there any logging @jordanD can turn on so we can see the message traffic?

Yes, @jordanD, if you enable logging in Hubitat for the system/parent virtual device, you can get debug logs of the event messages. You may also want to enable logging on the specific dimmer device that is experiencing this issue. Please share a capture showing the chain of traffic that results in a failure.

I have a little bit of work to finish up, and then I will re-update my driver and try logging for you. Post back in a bit - thanks!

1 Like

@tomw & @dsegall ,

I followed the following outlined steps in order to generate the log attached further below. Hopefully this gives you enough to follow -- let me know if there is anything more specific I can do to help track it down. Thank you both for all the work you've put into this!

  1. Started with Kitchen Dimmer Off (last level 100%), “cansetlevel=false”.
  2. Set level 50% - nothing
  3. Turn light on, cansetlevel flicker to true and then false
  4. Set level 60% - nothing
  5. Set level 50% - nothing
  6. Refresh – cansetlevel changes to true.
  7. Set level 50% - works, but canSetlevel changes back to false.
  8. Set level 80% - nothing
  9. Refresh – cansetlevel changes back to true.
  10. Set level 80% - works.

Events from Device (Kitchen Dimmer):

canSetLevel false DEVICE 2021-06-20 06:26:18.895 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:18.577 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:18.538 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:18.258 PM EDT
level 80 DEVICE digital 2021-06-20 06:26:18.234 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:18.234 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:17.992 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:17.924 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:15.578 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:01.717 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:01.444 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:01.390 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:01.112 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:01.022 PM EDT
level 50 DEVICE digital 2021-06-20 06:26:01.021 PM EDT
canSetLevel true DEVICE 2021-06-20 06:26:00.801 PM EDT
canSetLevel false DEVICE 2021-06-20 06:26:00.767 PM EDT
canSetLevel true DEVICE 2021-06-20 06:25:56.955 PM EDT
canSetLevel false DEVICE 2021-06-20 06:25:39.786 PM EDT
canSetLevel true DEVICE 2021-06-20 06:25:39.242 PM EDT
switch on DEVICE digital 2021-06-20 06:25:39.120 PM EDT

.
Hubitat Logs:

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:18.880 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"chgReason":3,"lastUpdated":"2021-06-20T22:26:14.705Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.574 pm [**debug**](http://///Local IP////device/edit/310)respData = [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:80, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:26:14.356Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.564 pm [**debug**](http://///Local IP////device/edit/310)httpAsyncCallback **with** status = 200 **from** data = null

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:18.532 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"fadeOnTime":0,"fadeOffTime":0,"lastUpdated":"2021-06-20T22:26:14.356Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.359 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[fadeOnTime:0, fadeOffTime:0]])

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.316 pm [**debug**](http://///Local IP////device/edit/310)restoreFadeTime **with** data=[state:ON, level:80, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.262 pm [**debug**](http://///Local IP////device/edit/310)Scheduling restoreFadeTime **for** 0s **with** data=[state:ON, level:80, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.250 pm [**debug**](http://///Local IP////device/edit/310)fadeDone **with** status = 200 **from** data = [state:ON, level:80, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:18.226 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"power":"ON","brightness":80,"lastUpdated":"2021-06-20T22:26:14.022Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:18.022 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[power:ON, brightness:80]])

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:17.990 pm [**debug**](http://///Local IP////device/edit/310)fadeStart **with** status = 200 **from** data = [state:ON, level:80, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:17.918 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"fadeOnTime":0,"fadeOffTime":0,"lastUpdated":"2021-06-20T22:26:13.741Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:17.693 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[fadeOnTime:0, fadeOffTime:0]])

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.585 pm [**debug**](http://///Local IP////device/edit/5)updating child: Kitchen Dimmer **with** power: ON **and** brightness: 50

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.574 pm [**debug**](http://///Local IP////device/edit/5)found existing child: Kitchen Dimmer

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.572 pm [**debug**](http://///Local IP////device/edit/5)manageChildDevice(Kitchen Dimmer, 406587)

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.568 pm [**debug**](http://///Local IP////device/edit/5)thisSwitch = [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:50, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:58.000Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.552 pm [**debug**](http://///Local IP////device/edit/5)updating child: Living Room Dimmer **with** power: ON **and** brightness: 100

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.549 pm [**debug**](http://///Local IP////device/edit/5)found existing child: Living Room Dimmer

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.546 pm [**debug**](http://///Local IP////device/edit/5)manageChildDevice(Living Room Dimmer, 388409)

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.542 pm [**debug**](http://///Local IP////device/edit/5)thisSwitch = [name:Living Room Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_000B_D1F4, version:1.5.72; CP 1.13, minLevel:10, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:, buttonData:, linkData:, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.20, created:2019-08-24T01:13:49.000Z, lastUpdated:2021-06-20T21:56:43.000Z, random:false, isRandomEnabled:false, rssi:-33, residenceId:229239, residentialRoomId:275242, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153696769, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-0C-F0-09, logging:0, resOcc:0, customType:dimmer, iotBridgeId:null, iotBridgeSerial:null, id:388409]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.534 pm [**debug**](http://///Local IP////device/edit/5)resp.data = [[name:Living Room Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_000B_D1F4, version:1.5.72; CP 1.13, minLevel:10, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:, buttonData:, linkData:, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.20, created:2019-08-24T01:13:49.000Z, lastUpdated:2021-06-20T21:56:43.000Z, random:false, isRandomEnabled:false, rssi:-33, residenceId:229239, residentialRoomId:275242, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153696769, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-0C-F0-09, logging:0, resOcc:0, customType:dimmer, iotBridgeId:null, iotBridgeSerial:null, id:388409], [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:50, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:58.000Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:15.207 pm [**debug**](http://///Local IP////device/edit/5)httpGetExec([uri:https://my.leviton.com/api/Residences/229239/iotSwitches, headers:[Authorization:///authorization token removed by me///], contentType:application/json])

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:01.703 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"chgReason":3,"lastUpdated":"2021-06-20T22:25:57.524Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.444 pm [**debug**](http://///Local IP////device/edit/310)respData = [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:50, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:57.209Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.413 pm [**debug**](http://///Local IP////device/edit/310)httpAsyncCallback **with** status = 200 **from** data = null

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:01.384 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"fadeOnTime":0,"fadeOffTime":0,"lastUpdated":"2021-06-20T22:25:57.209Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.216 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[fadeOnTime:0, fadeOffTime:0]])

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.185 pm [**debug**](http://///Local IP////device/edit/310)restoreFadeTime **with** data=[state:ON, level:50, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.123 pm [**debug**](http://///Local IP////device/edit/310)Scheduling restoreFadeTime **for** 0s **with** data=[state:ON, level:50, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:01.110 pm [**debug**](http://///Local IP////device/edit/310)fadeDone **with** status = 200 **from** data = [state:ON, level:50, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:01.014 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"power":"ON","brightness":50,"lastUpdated":"2021-06-20T22:25:56.839Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:00.842 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[power:ON, brightness:50]])

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:00.796 pm [**debug**](http://///Local IP////device/edit/310)fadeStart **with** status = 200 **from** data = [state:ON, level:50, currFadeOnTime:0, currFadeOffTime:0, duration:0]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:26:00.760 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"fadeOnTime":0,"fadeOffTime":0,"lastUpdated":"2021-06-20T22:25:56.584Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:26:00.575 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[fadeOnTime:0, fadeOffTime:0]])

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.952 pm [**debug**](http://///Local IP////device/edit/5)updating child: Kitchen Dimmer **with** power: ON **and** brightness: 100

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.949 pm [**debug**](http://///Local IP////device/edit/5)found existing child: Kitchen Dimmer

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.946 pm [**debug**](http://///Local IP////device/edit/5)manageChildDevice(Kitchen Dimmer, 406587)

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.942 pm [**debug**](http://///Local IP////device/edit/5)thisSwitch = [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:36.000Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.927 pm [**debug**](http://///Local IP////device/edit/5)updating child: Living Room Dimmer **with** power: ON **and** brightness: 100

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.924 pm [**debug**](http://///Local IP////device/edit/5)found existing child: Living Room Dimmer

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.921 pm [**debug**](http://///Local IP////device/edit/5)manageChildDevice(Living Room Dimmer, 388409)

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.918 pm [**debug**](http://///Local IP////device/edit/5)thisSwitch = [name:Living Room Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_000B_D1F4, version:1.5.72; CP 1.13, minLevel:10, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:, buttonData:, linkData:, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.20, created:2019-08-24T01:13:49.000Z, lastUpdated:2021-06-20T21:56:43.000Z, random:false, isRandomEnabled:false, rssi:-33, residenceId:229239, residentialRoomId:275242, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153696769, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-0C-F0-09, logging:0, resOcc:0, customType:dimmer, iotBridgeId:null, iotBridgeSerial:null, id:388409]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.909 pm [**debug**](http://///Local IP////device/edit/5)resp.data = [[name:Living Room Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_000B_D1F4, version:1.5.72; CP 1.13, minLevel:10, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:, buttonData:, linkData:, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.20, created:2019-08-24T01:13:49.000Z, lastUpdated:2021-06-20T21:56:43.000Z, random:false, isRandomEnabled:false, rssi:-33, residenceId:229239, residentialRoomId:275242, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153696769, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-0C-F0-09, logging:0, resOcc:0, customType:dimmer, iotBridgeId:null, iotBridgeSerial:null, id:388409], [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:36.000Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]]

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:56.708 pm [**debug**](http://///Local IP////device/edit/5)httpGetExec([uri:https://my.leviton.com/api/Residences/229239/iotSwitches, headers:[Authorization:///authorization token removed by me///], contentType:application/json])

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:39.775 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"chgReason":3,"lastUpdated":"2021-06-20T22:25:35.599Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:25:39.226 pm [**debug**](http://///Local IP////device/edit/310)respData = [name:Kitchen Dimmer, power:ON, identify:0, ota:false, cloud_ota:false, downloaded:0.0.0, brightness:100, manufacturer:Leviton Manufacturing Co., Inc., model:DW6HD, serial:1000_0006_DDBF, version:1.5.72; CP 1.9, minLevel:1, maxLevel:100, fadeOnTime:0, fadeOffTime:0, presetLevel:0, dimLED:3, statusLED:255, loadType:1, canSetLevel:true, isAlexaDiscoverable:true, includeInRoomOnOff:true, timeZone:-300, lat:36.19, long:-79.19, env:3, programData:AAAAAA==, buttonData:null, linkData:null, dstStart:1615705200, dstEnd:1636264800, dstOffset:60, autoOffTime:0, connected:true, localIP:192.168.86.38, created:2019-09-27T20:26:42.000Z, lastUpdated:2021-06-20T22:25:34.937Z, random:false, isRandomEnabled:false, rssi:-55, residenceId:229239, residentialRoomId:null, deleted:false, blink:0, onTime:0, position:null, connectedTimestamp:1624153889329, timeZoneName:America/New_York, apply_ota:0, otaStatus:2, lang:null, audio_cue:null, mic_mute:null, configuredAmazon:null, resKey:3971697493, allowLocalCommands:null, mac:00-07-A6-07-EB-10, logging:0, resOcc:0, customType:null, iotBridgeId:null, iotBridgeSerial:null, id:406587]

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:25:39.215 pm [**debug**](http://///Local IP////device/edit/310)httpAsyncCallback **with** status = 200 **from** data = null

[dev:5](http://///Local IP////logs#dev5)2021-06-20 06:25:39.114 pm [**debug**](http://///Local IP////device/edit/5)parse: {"type":"notification","notification":{"event":"saved","modelName":"IotSwitch","modelId":406587,"data":{"power":"ON","lastUpdated":"2021-06-20T22:25:34.937Z"}}}

[dev:310](http://///Local IP////logs#dev310)2021-06-20 06:25:38.901 pm [**debug**](http://///Local IP////device/edit/310)httpPutExec([uri:https://my.leviton.com/api/IotSwitches/406587, headers:[Authorization:///authorization token removed by me///], contentType:application/json, body:[power:ON]])

So I hacked a fix to make it work for my purposes for now — not sure if this will have unintended consequences for basic switches as I only have dimmers. Perhaps it will help lead you to a more general fix?

On line 184, I modified this line to end in True

def canSetLevel = switchData.canSetLevel ? switchData.canSetLevel.toBoolean() : false

Now the canSetLevel stays True, never flips to false at all.