Dim from off state command results in immediate set, instead of ramp
In my test setup, I have five Qubino dimmers connected to the Hubitat. After a few attempts, I got these appearing in Home Assistant by publishing them as Dimmers, Lights and Ramp Control.
When the light is already on, if I send the Dim command to set a new dimming level, the bulb fades to the new dimming level. But if the light is off, sending a dim level causes it to jump straight to the new level, with no transition. This happens, even if I just send the command via MQTT Explorer:
homie/hubitat/testroom-dimmer4/dim/set
99
However, if the bulb is already on, sending a new dim value does cause the dimmer to ramp smoothly to the new value. It looks like if I use the ramp command via MQTT then this does work better:
homie/hubitat/testroom-dimmer4/ramp/set
{"level":99, "ramp": 2}
However, I can't convince HA to issue ramp commands like that. This is different to what happens in Hubitat's dashboard UI. If I set a dimming level from the off state, the bulb always ramps up to the new value smoothly.
Any idea how I can fix this?
This is probably caused by the 'on' command being sent as well as a level command when the device transitions from 'off' to 'on'. It may depend on which order these are sent in too. It is a design decision that a platform (HA and HE) and device (Quibino) implement. The key aspect is can a dimmable light be 'on' at 0 brightness or 'off' at 50 brightness ? These are both useful in allowing different features but often overridden.
Let me have a think if you can do anything to achieve what you want. You can of course send any MQTT payload from HomeAssistant but not in an integrated way with the on/off control. There is no way to enter a 'ramp time' is there from HA ?
Do you by any chance use NodeRED with HA as that could act as an intermediary to achieve what you want ?
Just to clarify - sending the ramp command to MQTT when the light is off does work correctly for you ?
homie/hubitat/testroom-dimmer4/ramp/set
{"level":99, "ramp": 2}
Yes, if the light is off, the ramp command does do the transition.
If I just send the dim command from the Off state using MQTT explorer, it doesn’t.
It’s a bit strange, as it seems that in both cases the MQTT app does generate an on event before generating the dim event.
I’m seeing some inconsistent results on on/off activation too. I haven’t been able to pin it down to a specific thing yet. It’s like the commands get lost somewhere, but I’m not sure where yet.
So, I've got a simple fix for my issue. Referring to the mqtt light documentation here, we can set the on_command_type to "brightness", so that HA only sends the Dim command to turn the light on. I also added a parameter to choose the ramp time, as in my test setup, turning from 0 to 100 was still too aggressive.
Would you accept a PR for this?
Interesting, well spotted - let me have a read and check it's not going to mess anything up. As long as it doesn't of course I'll accept a PR but let me also see how difficult it would be for me to patch it myself. The PR needs to be against a later version than you have (beta3e) but I can point you to that repository.
That's an easy change however.. does it not impact people using just on/off control in the 'default' way i.e the device would operate as you desire but maybe not as they are used to ? I'm thinking 'last' or 'brightness' would need to be a configurable option..
Have you actually implemented it and it meets both needs ?
Yes:
Added HACommandOnType here:
section ("<b>MQTT Publish Formats</b>", hideable: true, hidden: true){
//input "HEBasic", "bool", title: "<b>Hubitat basic MQTT</b>", required: true, defaultValue: false, submitOnChange: false
input "homiePublish", "bool", title: "<b>homie 3 protocol</b>", required: true, defaultValue: true, submitOnChange: false
input "minHomie", "bool", title: "<b>Complete & compliant homie topics</b>", required: true, defaultValue: true, submitOnChange: false
input "homieStatesPersist","bool",title: "<b>    ... retain homie states</b>", required: false, defaultValue: true, submitOnChange: false
input "HADiscovery", "bool", title: "<b>Home Assistant MQTT discovery protocol (requires homie3 publish enabled)</b>", required: true, defaultValue: false, submitOnChange: false
input name: "HADiscoveryTopic", type: "text", title: "<b>Home Assistant Discovery Topic</b>", description: " as configured in HA", required: false, displayDuringSetup: true, submitOnChange: false
input "HARemember", "enum", title: "<b>Home Assistant MQTT discovered devices</b>", required: false, defaultValue: "Remember",options: ["Forget", "Remember"], submitOnChange: false
+ input "HAOnCommandType", "enum", title: "<b>Home Assistant On Command order for Dimmers", required: false, defaultValue: "first", options: ["first", "last", "brightness"], submitOnChange: false
}
And then, line 2913:
if (type=="light") {
+- pOnType = ",\"on_command_type\":\"${settings.HAOnCommandType}\""
pBriState = ',"brightness_state_topic":"' + sDimTopic + '"'