Simple automation that turns on targets by <label> at sunset?

New to HA (migrating from UDI/ISY; Hoping to setup a simple automation that turns on all my at sunset based on their labels - so I don’t have to go back and update the automation every time I add/update a switch or outdoor device? I have about a dozen s so far out of several hundred devices in the config.
I have all my outdoor lights configured with a label and was hoping I could do a simple automation to turn them all on at sunset/ and one for turning them all off at sunrise?

What i did was to put all lights (for a room say) in a group and control the group. The other advantage is that it is easy to swap out a light if it is faulty just by modifiying the group members.

- id: 'outdoor_light_label_sunrise_sunset_0001'
  alias: "Outdoor Lights Sunrise/Sunset"
    - alias: Sunset trigger
      platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 0
      id: 'on'
    - alias: Sunrise trigger
      platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: 0
      id: 'off'
  condition: []
    - service: homeassistant.turn_{{ }}
        label_id: my_example_label
      data: {}

If all your entities are in the same domain i.e. light or switch you can use the domain-specific service, but to keep it so that it will work across the board you need to use the generic services as shown above.

Thank you - trying that using my label “Outdoor Lights”. I just paste that to the end of the “configuration.yaml”?
My lights are a variety of lights, switches, outlets, and plug-ins so I like having just the one entry to track!

No, it is better to put it into automations.yaml so that it is editable from the frontend. I have edited to configuration above so that it should work in automations.yaml.

You can also create your automation in the GUI Automation Editor and just use the configuration above as a roadmap.

1 Like