oonam
June 20, 2024, 5:09am
1
Hi All,
Could you help me, I would like to customize a simple wall mounted button (with a smart relay), that
first press: Light 01
second press: Light 02
third press: Light 03
fourth press: all off
Hardwares and circuits are ok, but the programming in HA doesn’t work. I have tried If-Then blocks and Numeric state, but nothing.
Can you give me any idea?
Thanks
Troon
(Troon)
June 20, 2024, 6:17am
2
In future, to save us making it all up, please provide the entity IDs for relevant entities (the button and the three lights, here).
After the third press, should light 03 be the only one that is on, or do you want 01, 02 and 03 to be on?
Assuming you want the lights to come on incrementally and that there is no other mechanism for turning them on or off:
trigger:
- platform: state
entity_id: button.the_button
action:
- variables:
the_lights:
- light.light_01
- light.light_02
- light.light_03
- if:
- "{{ is_state(the_lights[-1], 'on') }}"
then:
- service: light.turn_off
target:
entity_id: "{{ the_lights }}"
else:
- service: light.turn_on
target:
entity_id: "{{ the_lights[(the_lights|map('states')|list).index('off')] }}"
Replace the button and light entity IDs with your own.
Triggers off a button press. If the last light in the list is on
, turns them all off
; otherwise turns on
the first one in the list that is currently off
.
2 Likes
In addition to that answer, there is likely something in the blueprint exchange already written by another community member that could work for you as well.
Tips on Searching for Answers & Duplicate Topics in the Forum .