Trying to make a script that will turn off every light except my night stand (once it works I will also have it set my night stand to a dim warm light), but right now it is turning off every light, could someone let me know what I did wrong? Thank you!
alias: Good Night
sequence:
- service: light.turn_off
target:
entity_id: "{{ lights }}"
variables:
lights: |
{{ expand(states.light)
| rejectattr('entity_id', 'in', ['light.night_stand'])
| selectattr('state', '==', 'on') | map(attribute='entity_id') | list }}
mode: single
icon: mdi:bed
Did you test the Jinja template in the developer tools to see what it is returning?
I wonder if the variable is for some reason not being created before the sequence leading to an empty list?
I tested in my dev tools and it correctly removes the light I don’t want targeted.
So my suggestion would be to define the variable lights, IN the sequence list immediately before the call to turn the lights off.