Support OR statement in state triggers

Currently, automation state triggers in the UI allow to/from one state, to/from any state, or any state change. There isn’t an easy way to discern changes to/from multiple states without several permutations of trigger blocks.

For example, if I want to use a “wait for trigger” block based on the state-change of an entity which has gone unavailable, I can specify the trigger as “from: unavailable”, but practically, if the state changes from unavailable to unknown, the automation won’t function correctly. Ideally you’d be able to specify “from: unavailable, to: on OR off” (for a switch or light). Likewise, specifying a change “from: unavailable or unknown” would also be useful in triggering the correct sequence.

alias: example
trigger:
  - platform: state
    entity _id: switch.foo
    from: 'unavailable'
    to:
      - 'on'
      - 'off'
condition: []
action:
  ... etc ...

Reference: State Trigger

Already possible and it can be any to any, one to any, any to one, plus there’s not_to and not_from for additional ability to specify the exact kind of state-changes the State Trigger should detect.

2 Likes

Amazing, thanks! I understand just about anything is possible in YAML, but idiots like myself still rely on the UI in HA sometimes.

FWIW, the Automation Editor, in Visual mode, doesn’t implement everything that’s possible with Home Assistant’s scripting language. Some of that omission is by design, to insulate the user from the wide array of features available (i.e. avoid cluttering the UI) and focus on the most widely used.

Quick question on this same thread– how would you specify a list of states NOT to trigger? For example, if you want to trigger based on any state change from ‘Off’, but not ‘Off’ to ‘Unavailable’ or ‘Uknown’?

alias: example
trigger:
  - platform: state
    entity _id: switch.foo
    from: 'off'
    not_to:
      - 'unavailable'
      - 'unknown'
condition: []
action:
  ... etc ...

As @123 mentioned, the not_to and not_from options don’t appear in the UI editor but they are valid and are described in the docs

Thanks so much! Apologies, even reading the docs, it’s hard to parse the correct syntax when you’re just learning the language.