Automation to turn on lights if any other lights are on at sunset?

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

Could you not create a group helper or similar that holds all the lights you want to track?

1 Like

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.

there are tons of ways of doing this. i’m sure someone will correct me with a better way, but i’d do this:

  1. create a light group:
    Group - Home Assistant
    this group is considered “on” if any of them are on.

  2. in your automation, i’d put the condition in the condition part, not in the action part.

no need for variables.

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
1 Like

just a quick spellcheck :wink:

dunno what you’re talkin about :wink:
(thx!)