HI,
I’m trying make an automation using trigger.to_state.state
, but ran into trouble.
As I understood, trigger.to_state.state
should return the new state that triggered trigger.
But in below simple automation, automation works correctly only when I change values in inverted (as shown).
i.e. without inverting (‘on’ to ‘off’ and ‘off’ to ‘on’), when state of motion sensor changes to ‘on’ (detected), switches turns off and and vice versa.
trigger:
- platform: state
entity_id: binary_sensor.occupancy
action:
- choose:
- conditions: >
{{ trigger.to_state.state == 'off' }}
sequence:
- service: switch.turn_on
target:
entity_id:
- switch.l1
- switch.l2
- conditions: >
{{ trigger.to_state.state == 'on' }}
sequence:
- service: switch.turn_off
target:
entity_id:
- switch.l1
- switch.l2
Is this correct behavior or bug?