I’m struggling with using a value_template
condition on an if-then-else action in an automation, where I want to use a variable to provide the entity to get the state from.
Here’s the automation thus far:
trigger:
- platform: state
entity_id:
- binary_sensor.parents_bedroom_channel_1_input
- binary_sensor.parents_bedroom_channel_2_input
condition: []
action:
- if:
- condition: template
value_template: >
{{ is_state("{{ light }}", 'on') }}
then:
- if:
- condition: time
after: "21:00:00"
then:
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: light.turn_off
target:
entity_id: "{{ light }}"
else:
- service: light.turn_on
target:
entity_id: "{{ light }}"
mode: single
variables:
light: "{{ 'light.parents_fan' if trigger.entity_id 'binary_sensor.parents_bedroom_channel_1_input' else 'light.parents_downlights' }}"
I have a variable, light
that I want to use the is_state
test against, but I’m not sure how to use a variable within a value_template
.
Edit there was also a bug in my automation for creating the variable, I missed the ==
in the if
statement.