Turn Lights on at Sunset, Turn Off at Midnight

Is there a way to use one automation to turn on a light at sunset (or sunset -01:00 hours) and turn it off at midnight?

Currently I have this as two automations, but I’m trying to consolidate things.

Thanks!

@ericnix ,Yes sure, introduction of trigger id makes HA more versatile .

- id: 'your_id_here'
  alias: Schedule Bedroom Lamp(winter)
  description: ''
  trigger:
  - platform: sun
    event: sunset
    id: 'on'
  - platform: time
    id: 'off'
    at: 00:00
  condition: []
  action:
  - service: light.turn_{{ trigger.id }}
    target:
      entity_id: light.your_light_here
  mode: single
2 Likes

Thanks @naijaping . The ‘your_id_here’ is a custom ID, right?

Also, the automation that HA’s configuration system created has the target as device_id with a long string. I’m assuming I don’t need to change that, correct?

If I want to do this with multiple lights, could I list multiple device_id or entity_id’s?

Thanks again!

Also, I’m assuming there’s no way of doing this via the Automation Editor?

Put whatever you want there.

Yes, though is better to create a light group.

Can I create a light group via the UI or am I required to manually create them by editing the groups.yaml file?

They go in the light section, not the group section. It’s yaml only.

Lights section? As in a lights.yaml file? Sorry, I’m very new to HA. Learning a lot over the past 2 weeks though!

https://www.home-assistant.io/integrations/light.group/

1 Like

You can. Create two triggers and give each an id by clicking on hamburger stack and selecting “edit id”. Give sunset an “on” id, give midnight the “off” id.

add a “choose between” action like below

and then an similar off

Yaml comes out to be essentially what was posted on the original answer.

1 Like