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.
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