How to use multiple from states (OR) in automation trigger

I have somehow specific problem to be solved related to automation of my blinds on harmony activity state change. Basically when I switch off any activity I use harmony remote state change to: PowerOff to trigger opening the blinds. The problem is that when hassio is restarted harmony integration is also changing state from Unknown to PowerOff triggering unwanted opening of the blinds. I tried to filter out this situation by using not state_is Unknown in condition, but it does not work - seems condition is checked after the trigger, so state is already PowerOff and it is not preventing automation to run. So seems solution it to use conditional from in trigger… but I have no clue how to make it, if possible at all. Here is my current code ( not working properly, as described above):

- alias: "Open blinds on turn off"
  initial_state: true
  trigger:
    platform: state
    entity_id: sensor.tv_room_harmony_activity
    to: 'PowerOff'
  condition:
    condition: template
    value_template: >
      {{ not is_state('sensor.tv_room_harmony_activity', 'Unknown') }}
  action:
    - service: shell_command.blinds_up

What I need is something like (do not even know what notation would look like):

- alias: "Open blinds on turn off"
  initial_state: true
  trigger:
    platform: state
    entity_id: sensor.tv_room_harmony_activity
    from: OR
      "Apple TV"
      "Smart TV"
      "Games"
      "Cable TV"
    to: 'PowerOff'
  action:
    - service: shell_command.blinds_up

Is it possible? Could templates be used here somehow? Otherwise the solution would be to have 4 different automations for each scenario…

I think you should be able to use the trigger.from_state.state in a template condition something like this:

condition:
  condition: template
  value_template: "{{ trigger.from_state.state != 'Unknown' }}"

@Burningstone, finally I had a chance to test your solution, but unfortunately it does not work… I mean it properly handle all state changes from any state to PowerOff, but change from Unknown to PowerOff still triggers blinds up… But I think it is good direction and I’ll dig a bit more into this direction.

My template is wrong, it should be ‘unknown’ with a lowercase “u”, and not ‘Unknown’. Sorry for this.
Please try like this:

- alias: "Open blinds on turn off"
  initial_state: true
  trigger:
    platform: state
    entity_id: sensor.tv_room_harmony_activity
    to: 'PowerOff'
  condition:
    condition: template
    value_template: "{{ trigger.from_state.state != 'unknown' }}"
  action:
    - service: shell_command.blinds_up

Thanks a lot for help! It is working perfectly fine now!

1 Like