Here’s what I’m attempting to do: When I open a door, I want to look at the state of three lights, if any of them are off, I want to turn them on, then off 5 min later (leaving any of the three on that were on to begin with).
What I have works to select only the lights that were off, but I’m not sure how to ‘remember’ which set of lights I turned on so that I only turn those off.
Here’s what I have so far:
- alias: Dog Potty Lights
trigger:
- platform: state
entity_id: binary_sensor.back_door
from: 'off'
to: 'on'
condition:
condition: or # 'when dark' condition: either after sunset or before sunrise
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
- service: switch.turn_on
data_template:
entity_id: >
{% set my_list = [states.switch.garage_outside_light,
states.switch.back_door_light,
states.switch.patio_lights]
| rejectattr('state','equalto','on')
| map(attribute='entity_id' )
| join(', ') %}
{{my_list}}
- delay: 0:05:00
- service: switch.turn_off
data_template:
entity_id: {{ my_list }}
That last line is the part that doest work because my_list
is no longer defined.
I’m relatively new to HA, so any help would be appreciated!