Dimming duration values not sent to bound devices when switching on/off

After digging in deeper to a related issue in another thread, I think the inovelli switch and Juno lights are both following the ZigBee spec, but the ZigBee spec results in undesired/unintuitive behavior. Especially annoying is the fact that the “On” and “Off” commands don’t have parameters for a duration.

Unfortunately, the solution I proposed to that other thread won’t work for generic bound zigbee lights, since we can’t change their behavior, and in truth can only kind of hope they mostly follow the spec. But I’ve got an idea that would bring the observed behavior in line with what I’d expect to happen, inspired by @mamber’s workaround in the hubitat driver.

This is assuming my idea in the other thread is implemented first/at the same time.

When sending commands to a bound zigbee device, use different behavior depending on whether both OnOff and LevelControl are bound, or just OnOff. If only OnOff is bound, just do current behavior.
If both are bound:

  • On receipt of an “on” command which the existing logic decides should be sent to bound devices, instead of sending “on”,
    • First send “move to level” with a level equal to the switch’s CurrentLevel from the LevelControl cluster, and a duration of 0. I’m not sure if “Move to Level” or “Move to Level with On/Off” would be better here. It seems like it would probably be a good idea to set the ExecuteIfOff bit to 1 on the OptionsMask and OptionsOverride fields for this command.
    • Next send a “Move to Level with On/Off” command with the target level and duration set to the value the internal dimmer is moving to, according to the existing logic or what I specified in the other thread.
  • On receipt of an “off” command which the existing logic decides should be sent to bound devices:
    • Send a “Move to level with On/Off” command, with a target level of 0, and a duration set according to the existing logic for the internal dimmer.

I think the “Move to level 0 with On/Off” should be sufficient to leave the CurrentLevel of the bound light(s) at either 0 or 1, which means that no matter how they’re turned on, they’ll start their fade from off.