Media player state condition not working

Hello, I’m trying to automate my lights and part of that is that I don’t want them to turn off when we’re watching TV. I’ve tried a state condition and a template condition with no success. Currently I have the below:

- id: '1575647713901'
  alias: Living Room Off PIR
  description: ''
  trigger:
  - entity_id: binary_sensor.living_room_pir_sensor_occupancy
    for: 00:15:00
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: template
    value_template: "{{ states('media_player.living_room_shield') == 'off' }}"
  action:
  - data:
      entity_id: light.living_room
    service: light.turn_off

Testing the template in the developer tools returns False but when I trigger the automation, the lights still turn off. I’ve got Home Assistant running on my RPi3 using docker and the version/build is 0.101.0.dev20191018.

Please help!

If you mean the TRIGGER button in the more-info dialog, this will bypass every condition and run the action.

3 Likes

Ah, I was not aware of that! Is there a way to trigger the automation without bypassing the conditions, so I can make sure it is working as expected?

Edit: Also, thank you very much for getting back to me, this was really driving me nuts!

You can comment out the ‘for’ option in the trigger for testing.
I always test automations by going to Dev Tools/states, click the trigger entity, type in the desired state and press ‘Set State’.

yes, you can add the conditions to the action block.
This has the advantage the automations last_triggered is actually set, where this doesn’t happen when the condition is in the condition block and prevents the action from firing.

- id: '1575647713901'
  alias: Living Room Off PIR
  description: ''
  trigger:
    platform: state
    entity_id: binary_sensor.living_room_pir_sensor_occupancy
    from: 'on'
    to: 'off'
    for: '00:15:00'
  condition: []
  action:
    - condition: template
      value_template: >
        {{ states('media_player.living_room_shield') == 'off' }}
    - service: light.turn_off
      entity_id: light.living_room
1 Like

Yes, I’ve been doing this more and more recently.
I’m starting to wonder what the condition block is actually good for!!