One button more operates

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? :slight_smile:

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:

  - platform: state
    entity_id: button.the_button
  - variables:
        - light.light_01
        - light.light_02
        - light.light_03
  - if:
      - "{{ is_state(the_lights[-1], 'on') }}"
      - service: light.turn_off
          entity_id: "{{ the_lights }}"
      - service: light.turn_on
          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.


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.