Automation: Turn off lights at a specific time

Hi there,

im new to HA and have some trouble with one automation:
This automation should turn on a light on after sunset and should switch it off at 11pm. The part where the light is switched on works just fine. But the part where it should be switched off isn´t. Had it in one automation and followed the advise from some posts, to split it in 2 automations. Same result.
For me as a newbie, the genereated part in the YAML File looks fine (similiar to what i found in the forum). Any advice is appreciated

alias: 04 dining light off
  description: ''
  trigger:
  - platform: time
    at: '23:00:00'
  condition: []
  action:
  - type: turn_off
    device_id: 1a7af4433e1d044f196086c90b5bdff8
    entity_id: light.l_iris_1
    domain: light
  mode: single

regrads

You and I are about on par with each other regarding automations. But I would like to see your working (turn on) automation.
Did you create the automation in the UI then change to “edit in YAML” to get the YAML that you posted? The reason I ask is because none of my automations made through the UI have a “device_id:”

Like you, I find separate automations to be a lot easier to understand.

Here is my automation to turn the porch light on five minutes before sunset:

alias: Porch Light On at sunset
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '-00:05:00'
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.porchlight
mode: single

And to turn it off four hours after subset:

alias: Porch Light Off at sunset+4
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '+04:00:00'
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.porchlight
mode: single

Hope this helps…

Yes, I use the UI to create the automations. As a noob, it’s easier for me right now. And the automations I have so far have not had to be touched in the YAML code so far.
Here’s my YAML code for it (changed the light for the auto turnoff to a light right beside my desk). And its genereating device IDs

I will try your approach to turn off the light. Its an nice idea for a less predictable “vacation mode”. I would like to have a specific time or i have to touch this automation many times a year :slight_smile:

  alias: 03 Dining light on at sunset
  description: ''
  trigger:
  - platform: sun
    event: sunset
    offset: 0
  condition:
  - condition: device
    type: is_off
    device_id: 5bca1596cb07f452b52de21f5b263a24
    entity_id: light.nightstand_right
    domain: light
  - condition: device
    type: is_off
    device_id: 17ff1be45bde11bbe071ecfa92de3013
    entity_id: light.nightstand_left
    domain: light
  - condition: device
    type: is_off
    device_id: 1ebc5ad37e46314f1c7dd22d1180550b
    entity_id: light.strip_eat
    domain: light
  action:
  - type: turn_on
    device_id: 5bca1596cb07f452b52de21f5b263a24
    entity_id: light.nightstand_right
    domain: light
    brightness_pct: 30
  - type: turn_on
    device_id: 17ff1be45bde11bbe071ecfa92de3013
    entity_id: light.nightstand_left
    domain: light
    brightness_pct: 30
  - type: turn_on
    device_id: 1ebc5ad37e46314f1c7dd22d1180550b
    entity_id: light.strip_eat
    domain: light
    brightness_pct: 30
  mode: single
- id: '1649099529899'

waht i ever i try to do with the time trigger. It doenst work. No scenes, no messages to my phone…nothing. No clue…

Try using the Call Service: Turn off light

Here is an automation that turns teh porch lights n at sunset and turns them back off at sunrise.

alias: Porch Lights
description: ''
trigger:
  - platform: sun
    event: sunrise
    offset: '0'
    id: Sunrise
  - platform: sun
    event: sunset
    offset: '0'
    id: Sunset
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Sunrise
        sequence:
          - type: turn_off
            device_id: 87ffce0f469cfb82ade4540eb360b9c4
            entity_id: switch.switch
            domain: switch
          - type: turn_off
            device_id: 668299180b077f8474db16de6ff7635e
            entity_id: switch.back_porch_light
            domain: switch
      - conditions:
          - condition: trigger
            id: Sunset
        sequence:
          - type: turn_on
            device_id: 87ffce0f469cfb82ade4540eb360b9c4
            entity_id: switch.switch
            domain: switch
          - type: turn_on
            device_id: 668299180b077f8474db16de6ff7635e
            entity_id: switch.back_porch_light
            domain: switch
    default: []
mode: single
1 Like

Thx for your reply. Never heard of it. Guess i have some stuff to read the upcomming days

ok Thx, poor translation in the UI. Tried it, doesnt work as well. It seems like nothing with a time trigger will work or im just too dump to get it. Tried it with a device as well as an entity

Tried what?, which part doesn’t work as well, is your TZ set correctly?, you can add the “time_date” sensor to confirm your system is using the correct time, I have many time triggered automations that work as expected, have you checked your logs or the automation trace to see which part is failing?

One example:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: time
    at: '23:00:00'
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.blue_led

What I am really using is a turn off at sunset plus a random time between 3 and 4 hours. But I didn’t want to further confuse the situation.

You really need to find the log files. Config/settings/logs to see is there’s an error.

Thx, for your replies.
Switched to a new housing for my PI today and was shutting down the system completly. After that, its working now. Same Automation without any changes. Time Zone was set correctly.