[solved with a template] Automation w/ IF-THEN action: if trigger.to_state.state = on -> action

I want to use the trigger to state to on as a condition to run an action.
In the same automation I have 2 triggers

  • from on → off
  • from off → on

How can I use the on to off as a condition to run an action in a template?

Thanks for any help!

There are a few ways to do it depending on the end actions in question, personal preference, and comfort with templating. Here is one option using a Choose action…

....
action:
  - choose:
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'on' }}"
      sequence:
        .....
    - conditions:
        - condition: template
          value_template: "{{ trigger.to_state.state == 'off' }}"
      sequence:
        .....
2 Likes