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”
WHEN the button is clicked
CONDITION White is ON and Red is OFF
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.
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