Hi, I have 2 sets of lights that are controlled by a smart button. I want to have an automation that turns on both sets of lights if both were off and only one if the other one was already on. This I managed to achieve. However, I want the second press to turn off both if both were off before the first press and only one if the other one was on before the first click.
So 1st click - turn on both if both were off and only one if one was on.
2nd click - turn off both if both were off and only one if one was on.
Currently, I have this automation set up:
It works fine at the first click but will only turn off one of the lights on the second click as the state was already āonā. I feel like I should use from_state somehow but I canāt figure out the logic.
My gut says Iād ārecordā the state of the two lights in a scene at the beginning of the automation and then turn one or both on with the 1st click and then ārestoreā that scene on the 2nd click - but Iām mostly commenting to see what solutions the pros will actually come up with
I feel like maybe helpers, and specifically input booleans could help? There must be a bunch of ways to do what you want, but I believe thatās how I would do it.
Would this work? I probably would use a text helper.
Sorry for the horrible pseudocode formatting. (Iād rather type in javascript tbh )
When button triggered:
- IF light1 OR light2 is off:
- IF light1 is off AND light2 is on - SET text helper = "light1"
- IF light1 is on AND light2 is off - SET text helper = "light2"
- ELSE clear text helper
- Turn light1 AND light2 on
- ELSE:
- IF text helper == 'light1' - turn off light1
- ELSE IF text helper == 'light2' - turn off light2
- ELSE turn both lights off
- clear text helper
Thanks! Thatās a bit too advanced templating for me to understand but I tried it and nothing happens when I press the button. Any variables I need to update?
did you create the group? Are those lights actually lights, e.g. I just copied light.kuche_1 from your automation. Usually there will be errors in the logs if there are issues with the automations
All correct. When I replace group.kuche_lights with light.kuche_lights the two lights turn on but not the light strip and on second press nothing happens.
your initial explanation said just the 2 lights. So you want 3 lights? If yes, just add the 3rd light to the group.
As for the second press, the group has to turn on, and the group will turn on when all entities report their state as on. If your lights take a minute to respond w/ a state, your second press wont work if you click it too fast. You can most likely adjust that by changing your transition time so the state reports fast instead of reporting when it gets to the full brightness. FYI using scenes wonāt correct this either. This is hardware related. So youād have to correct that by changing your transition time to 0 if your hardware supports that.
Thanks a lot for your help! And sorry if my initial explanation was confusing. Itās 2 lights but one of the lights has 2 bulbs. I was able to solve it with a helper and multiple nested if statements in the end. Here is the script: