HI All,
I have been using HA for a few months now, when I started out I watched multiple YouTube Videos and got a working solution. I have Several Lights and an Ikea E2002 “4 Way” Switch.
The Automation is a series of “When’s With Trigger ID’s” With “Then Do’s” hanging off the triggers.
I have been looking back over my automation and trying to work out if there is a better way to do it.
Can any one suggest an alternative method or point to a guide to help, my code is as below.
why do you have it all in one automation? the different blocks aren’t benefitting from each other for the most part.
also you have repeat while trigger id… that looks like it should be an infinite loop since the trigger id doesn’t change. does that actually do what you want it to do?
looks to me like the move-up condition and move-down will loops forever until the brightness is all the way up or all the way down (then actually continue to loop thereafter still). am i misreading?
here’s one way of improving the button-door up/down to turn up/down the dineing_room (sp? … ‘dining’) light by 10% each button press:
ill look through your code and try to understand it…
To answer your questions:
I used one automation as I have mutiple rooms with the same setup, so I can just copy/paste the code for each room quickly.
The repeat, while, id… it was my understanding that “id” acts like a Boolean, if the action is being triggerd its True so the loop will repeat. The thing here is that the actions "brightness_move_down "and up are only triggered when holding down / up (on/off). “brightness_stop” is sent when you release Down or Up
you shouldn’t copy/paste a bunch of code… but as you see above you can reduce the code down to nearly nothing.
if i were you, i would put similar functions together. ie, have 1 function that down on/off for all rooms. similar to how i did {{ trigger.id }} to specify on or off, it’s possible for your to use variables to specify entities or areas. so instead of area_id: dining_room, you could have area_id: {{ current_area }}… and that {{ current_area }} is set depending on which button is pressed.
wrt trigger.id, when it enters that automation, trigger id will be set and it will not change for the life of that run of the automation. so therefore it is always matching or always not matching. so that means in this code block of yours:
it will only enter te sequence if trigger.id == “Move-Up”… you’re guaranteed for it tobe “Move-Up”. therefore when it goes into the repeat, since you are guarantted it is “Move-Up”, and because you are guarantteed it will not change, it will loop in that repeat forever…
or at least until the automation is restarted by some other button being pressed (because you have mode:restart).
still, stepping back, the question is… what is your intent here? did you want it to loop forever? are you trying to have that button to a fade all the way to 0 or all the way to 100% and then stop? what are you trying to do with that repeat?
I will often create a basic automation using someone’s blueprint, It usually covers my requirements but if it’s not enough or is too much, I can always modify the YAML manually to add or remove functionality.
There are many blueprints for this device that have been used by many community members and improved over time. You may find one of those as a good starting point for making an automation, as well as being able to manage it in the Home assistant user interface.
Most of these have the functionality to handle the dimming actions of these switches (but may require you to create a number or text helper to temporarily store the level of the dimmer control)
Malte (Documentation) - ZHA - IKEA four button remote (Styrbar) for lights (E2001, E2002) https://tinyurl.com/yc4zund5