My goal is to have a sunset automation to check if any lights are currently on (in lieu of an occupancy type sensor), and if so, also turn on my living room light group. Is there a more efficient way to do that than I have here? Thank you!
alias: Living Room at Sunset
description: Turns on the living room 30 minutes after sunset if other lights are on.
trigger:
- platform: sun
event: sunset
offset: "00:30:00"
condition: []
action:
- if:
- condition: template
value_template: "{{ lightsThatAreOn | count > 0 }}"
then:
- service: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 100
variables:
lightsThatAreOn: |
{{ expand(states.light)
| selectattr('state', '==', 'on')
| map(attribute='entity_id')
| list }}
mode: single
True, my thought was to keep it so a list/group didn’t have to be maintained, if any light is on, someone is home, so turn the living room on.
Though that could end up needing its own exclusion list as well, say if I add an outdoor light or some other automation that may turn lights on when no one is home.
I think adding a group of core lights that would mean someone is home may be better. Thank you.
alias: Living Room at Sunset
description: Turns on the living room 30 minutes after sunset if other lights are on.
trigger:
- platform: sun
event: sunset
offset: "00:30:00"
condition:
- condition: state
entity_id: light.your_group
state: "on"
action:
- service: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 100