How To Cycle Through Scenes

Hi everyone. I had a similar issue that I fixed creating a custom component.

My situation is that I have momentary push wall switches that I want to use a single button to cycle between my room scenes. I wanted something that I could call and cycle between the scenes but also jump to the last scene(That in my case is ALL OFF) if a timeout has elapsed. So I create the Scene Sequencer(GitHub - 0x3333/scene_sequencer: Home Assistant custom component that cycles through a series of scenes sequentially).

It also check if the timeout has elapsed and the lights already match the state in the last scene so it goes directly to the first one, this avoid issues with external devices managing lights(like HomeKit), so the user doesn’t need to double press the switch in case the lights have been turned off outside my component.

Hope it helps someone.

Example of automation with it:

alias: TV Room - Switch 1
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.social_tv_switch_1
    from: "off"
    to: "on"
conditions: []
actions:
  - action: scene_sequencer.cycle
    metadata: {}
    data:
      scenes:
        entity_id:
          - scene.tv_all_on
          - scene.tv_afternoon
          - scene.tv_movies
          - scene.tv_all_off
      go_to_last_timeout: 5
mode: single

Every switch activation will cycle to the next scene, unless that the timeout(go_to_last_timeout) has elapsed, in this case, it will go to the last one(scene.tv_all_off).

I usually use 5 seconds so it will allow user to change scenes but allow turning off everything with another push to the switch.

Best,

Ps.: You can install it using HACS.