Automation / Transient between triggers

I have two lights (let’s call light white and light red) and one button I want to use to cycle among the four states:

State 1: White off, Red Off
State 2: White ON, Red Off
State 3: White ON, Red ON
State 4: White off, Red ON

For this solution I don’t want to use input/select with the “next” position; I wish to create four automation, all of them triggered by the button.

Example: “Automation from State 2 to State 3”

  1. WHEN the button is clicked
  2. CONDITION White is ON and Red is OFF
  3. THEN turn White ON and turn Red ON

In theory, this works… but, it happens that the turn on/turn off in the 3) THEN goes to validate the 2) CONDITION in another tranisition, so I have some flashes (turn on/off/on again) in my lights.

I thought that changing only one light during the transition between one state “and the next” should fix this issue, but it doesn’t.

Do you have any suggestion?

One automation with a choose action:

triggers:
  - trigger: state  # or however your button triggers this
    entity_id: event.button
    not_from: unavailable
    not_to: unavailable
actions:
  - choose:
      - conditions:  # if currently in state 1
          - condition: state
            entity_id: light.white
            state: 'off'
          - condition: state
            entity_id: light.red
            state: 'off'
        sequence: # change to state 2
          - action: light.turn_on
            target:
              entity_id: 
                - light.white
      - conditions: # if currently in state 2
          - condition: state
            entity_id: light.white
            state: 'on'
          - condition: state
            entity_id: light.red
            state: 'off'
        sequence: # change to state 3
          - action: light.turn_on
            target:
              entity_id: 
                - light.red
      - conditions: # if currently in state 3
          - condition: state
            entity_id: light.white
            state: 'on'
          - condition: state
            entity_id: light.red
            state: 'on'
        sequence: # change to state 4
          - action: light.turn_off
            target:
              entity_id: 
                - light.white
      - conditions: # if currently in state 4
          - condition: state
            entity_id: light.white
            state: 'off'
          - condition: state
            entity_id: light.red
            state: 'on'
        sequence: # change to state 1
          - action: light.turn_off
            target:
              entity_id: 
                - light.red

Thank you! It seems very interesting… I’ll study it! Thank you again!

Guys,
tell me it’s a joke… this is worst than python, I have to manually add spaces… please, let’s jump on xml or json…

No.

Why not… we can fork it… no?

Yaml is for humans. xml and json are for machines.

Apparently you can use json for your config by the way.