I have created an automation to use when a button is pressed on my switch. If the light (one light in a group of Hue lights in that Hue room) is On, turn it off, if the light is off, turn it on.
So far so good, nice and easy.
I have 20+ switches at home for which I would need to create the exact same thing. So I’m thinking I should be able to use a template or a blueprint (not clear yet on the difference) where the inputs would be
the switch to setup
the light to test
the helper to use
And it could create those 2 automations (one based on the blueprint, the other to be used when it triggers) for me directly.
I was going to write a python script to put those inputs in a csv and generate the yaml brute force but I’m pretty sure there is a more elegant way !
All help welcome
EDIT: realize this is clearly a blueprint which I need
First, as a general practice, either place the action in the blueprinted automation or use a script not a second automation. Automations without triggers have a history of causing issues.
As to your specific question…
You will likely need to forego the first blueprint so that you can trigger off multiple event entities in the same automation.
I have a separate automation for my indicator lights because I want them to reflect state, not when I pushed a button.
My little rant here is I find it odd that the developers decided to generate code like this. If you know the ID of the entity why not use the entity_id (the abstract name for that)?
The buttons are also in fact hardware switches but I have decoupled them and locked them to make sure the lights are always reachable.
I want to be able to also use the hue app to potentially turn the lights on or off so toggle would not really work in that case since I also want to keep the led light on the switch itself in sync. The way I have setup the automation, the led will reflect state the next time the switch is pressed but your comment made me realize there might be a better way indeed.
How would you recommend setting it up instead ? Are you linking the on/off state of groups of lights to the led on the switch ? Would be keen to see an example if you have one handy.
Agreed on device and entity id not using the easily readable version but I can modify that when I build the blueprint I guess ?
Could you explain a bit more about that first sentense?
And for that second point, that’s why you have the indicators trigger on what the state of the light is, not when you push the button.
Is your goal to be able to press any of the light switches and turn on all the lights in the group?
Or is it just to have indicator lights show up. (My light indicator lights show up when the light is off so I can find the button in the dark. When the overhead light is on I kind of know it’s on so the indicator isn’t really useful in that case. )
so @busman I went your way and it’s a lot simpler indeed.
My only issue is that to check if a group of lights is on or off, I have to choose a single one in the group so some cases might arise when the led on the switch is not in sync with the group if the specific light I have chosen to represent that group is turned on/off independently from the group (in the hue app for example).
Think I can live with that but curious how you handle that case (short of doing all the possible combinations of on/off lights in a group and deciding case by case if you want led on or off…) ?
Could you explain a bit more about that first sentense?
I am using the Aqara H2 switches which you can use in both relay control or decoupled.
(My light indicator lights show up when the light is off so I can find the button in the dark. When the overhead light is on I kind of know it’s on so the indicator isn’t really useful in that case. )
I agree with you but I was told by the boss (aka my wife) that she prefers it the other way. Not difficult to change if we realize it makes more sense the other way around
Thanks for sharing. I am not sure where I would put this though. You have a single automation handling all the switches in your house ? Triggered by pressing any button in your house and then you go to the right action based on the snippet you shared ?
Re: your point on not decoupling → How do you handle 2 way switches ? If someone turns off the relay and you want to turn the lights on by using the second switch which controls the same group of lights ?
Kind of, yes. But it’s just for the “special” case of when I use the scene feature of the switch (e.g. double or triple tap, hold-down, etc.). Initially I had an automation for everything and it just got to be too many to handle. As you noted you have to start repeating the same thing over and over.
In that snippet I was just showing how I use variables to define actions to run – more than just always on/off of a light.
You mean like if you have a z-wave or bluetooth battery operated button that you want to also run the lights? That’s why I use light.toggle, or am I not understanding your question?
BTW, I’ve reduced the number of small automations over time, and now do most things in packages as then I can group related things together (e.g. HVAC, irrigation, security) that have template sensors, automations and scripts. I think I use only one Blueprint.
Kind of, yes. But it’s just for the “special” case of when I use the scene feature of the switch (e.g. double or triple tap, hold-down, etc.). Initially I had an automation for everything and it just got to be too many to handle. As you noted you have to start repeating the same thing over and over.
Yes OK got you. So for the button which controls the relay you just use whatever was the last scene which was set on the lights the relay controls I guess.
In that snippet I was just showing how I use variables to define actions to run – more than just always on/off of a light.
My plan (which you’ve thrown a spanner in ) was to setup all the top buttons to do a simple on/off and then use the bottom buttons to do fancy cycling through scenes, change intensity by holding down etc. Now I’m not sure !
You mean like if you have a z-wave or bluetooth battery operated button that you want to also run the lights? That’s why I use light.toggle, or am I not understanding your question?
If you don’t decouple your switches and someone turns the relay off, your second z-wave switch becomes useless basically because it can’t reach the lights it’s supposed to turn on ? Maybe I can add a choice and if the relay is off, turn it on first before triggering the scene.
My setup is a bit weird in that, in my kitchen for example I have several switches which physically (through the relay) control only one portion of the lights I want to turn on/off. So i kind of have to decouple them otherwise I would have to go to 3 switches to turn all the lights in the kitchen on or off. Does that make sense ?
Hum. Isn’t the relay controllable via Home Assistant?
I use Zooz wall switches that can be wired as 3-way (or 4+ way) so my lights work just like they did before HA was added to the mix. I left it that way in a long hall where it’s important that it works if HA is down.
Other palces where I just wanted to add an additional switches I use a remove z-wave button and have it toggle the same light, scene, or group.
An automation won’t do anything without a trigger.
If this is the path you want, look into scripts, which are basically automations without triggers, but these have fields that you can pass data to them as a bonus.
I use Zooz wall switches that can be wired as 3-way (or 4+ way) so my lights work just like they did before HA was added to the mix. I left it that way in a long hall where it’s important that it works if HA is down.
Yes I could have done that but I didn’t even plug them in as 2 ways, thinking I would just do one properly wired, controlling the relay, and the other side of the room a “pure” smart switch.
It’s only one area of the house though so I might have to live with the possibility that, when the server is down, some lights in this specific area won’t work anymore.
Thanks again for the insights, I have a clearer idea of what I want to do now and I won’t need any automation where the switch controls a set of lights which are all on the same relay.
I will just have now to figure out how to cycle through my Hue scenes for each room but that’s a topic for another thread