Hi brettig,
Did you solve this? I am in a kind of similar situation and I cannot make this work the way I want it to..
I have my pushbuttons connected to a PLC and I have programmed this to send up one pulse for single click which then triggers light toggle function, this works fine so I am now trying to get push and hold to dim the lights up and down.
I am using IKEA Trådfri lightbulbs and zigbee2mqtt in home assistant to control these.
First I created a ramp function in the PLC which is starting at the current brightness and then ramping up to 255 and then back down again. I then used a function block in node red to pass that ramp as the brightness, like this:
msg.payload = {
domain: 'light',
service: 'turn_on',
data: { entity_id: 'light.bedroom_bed_right', brightness: msg.payload }
};
return msg;
That was not stable at all, I guess that was because the IKEA lights, the zigbee2mqtt bridge or home assistant was not able to process so many commands so I then tried to send a boolean from the PLC instead and attempted to ramp up and down in node red. I could not get this to work either, I noticed that the
data.new_state.attributes.brightness
Immediately gets set to the new brightness command, not the actual state of the lightbulb. So I cannot use this value to decide when to ramp back down for example.
The way I have this working now is like this:
I get the current brightness from home assistant and send that to the PLC.
Once someone activates the push&hold function I use that value, add (or subract) a number from that and send to node red. I then get the current brightness in node red, add a delay of one second to that and send it back to the PLC. When the PLC sees that the actual brightness = brightness command AND push&hold is still activated I add another number to the actual value and send that as a new command.
And if I reach 255 or 1 I reverse the direction.
And if the push&hold is released at any time the last command is kept.
But this is also unstable, quite often the lightbulb does not want to play along and also the light is not at all smoothly dimmed up and down.
I would very much like to have the actual brightness of the lightbulb as a variable that can be used, I mean a value that is ramped up and down according to the actual light. Not just immediately getting the new setpoint.