I’m struggling to come up with a way to have one button toggle between different states of the light. I’m trying to get it to work in the following way:
The light is off.
First button press toggles the light on, sets the brightness to 50/256 and temperature to 2200 K
Second button press increases the brightness to 150 and changes temperature to 2800 K
Third button press increased the brightness all the way up to 255 and temperature to 3200 K
Fourth button press turns the lift off, so moving back to step 1.
I don’t want to write 4 different automations for this, each with each own condition. I’d like to have one automation. I’m trying this approach (for now only two states):
The syntax isn’t valid though. I’m struggling to come up with a way to have a conditional item in the actions array that would depend on the state. Tried to find a way to do that in Jinja docs, but to no avail. I’d appreciate any pointers. Thanks!
edit: I’ll try to use that over the coming days. As I don’t have much time to play with this, it might take me a while, but I’ll circle back here and mark the answer as a solution if it’ll work.
I’ll try first the choose approach in a script suggested by @Troon, as it doesn’t, hopefully, require me to add a counter. A counter (which I haven’t used yet, so might be wrong) sounds like a new piece of state maintained just for my automation. To keep things robust and simple I’d prefer to rely on the existing state of that light. This way I won’t ever have to worry about the counter not being in sync with the state of the light. But should the choose approach not work, I’ll look at counters more closely, thanks for the tip.
Unsure, I’ll check. It’s an Ikea Styrbar - it has 4 different buttons. But I want to utilise only one to control that light, I need the other 3 buttons to do other things.
Anyway, the choose approach worked. I didn’t even need a separate script. Thank you both for help! Here’s the full automation in case someone else will be trying to figure something similar out: