Sunrise Event Automation Help Needed

All,

I need help getting my automation to work. Super simple turn-on the light at sunset and off at sunrise. No conditions. One entity.

Off at sunset works perfectly. On at sunrise does not work. I have two automations setup. Used the GUI. Yaml follows:

- id: '1598842852244'
  alias: Street Lamp On at Sunset
  description: ''
  trigger:
  - event: sunset
    platform: sun
  condition: []
  action:
  - data: {}
    entity_id: switch.street_lamp
    service: homeassistant.turn_on
  mode: single
- id: '1598842852243'
  alias: Street Lamp Off at Sunrise
  description: ''
  trigger:
  - event: sunrise
    platform: sun
  condition: []
  action:
  - data: {}
    entity_id: switch.street_lamp
    service: homeassistant.turn_off
  mode: single

  • Pressing the “Execute” button on the automation turns off the light correctly.
  • Logbook shows 6:36:24 AM [Street Lamp Off at Sunrise] has been triggered correctly

I’ve used multiple services with same result (homeassistant.turn_off, switch.turn_off) and Device action with same result.

What am I missing?

Dave

Looks ok. Did you maybe try with switch.toggle instead of switch.off ?
And if log says that it has been triggered and sunrise, then automation itself did run fine.
What switch is it?

Try this it works for me.

- alias: "Hallway Night Light On"
  initial_state: True
  trigger:
     platform: sun
     event: sunset
  action:
    service: light.turn_on
    entity_id: light.hallway_night_light

- alias: "Hallway Night Light Off"
  initial_state: True
  trigger:
     platform: sun
     event: sunrise
  action:
    service: light.turn_off
    entity_id: light.hallway_night_light

All the switching options I tried work manually. None work in the automation. It’s a Tasmotized sonoff.

Thank you - The only differences I see are the initial_state and lack of empty condition and data brackets. I’m going to test with those changes and see what happens…

I don’t think you need “initial_state” anymore it was one of my first automations and I have not touched it since.

1 Like

Update - changes to my automation made no difference. Further logbook review shows:
6:38:24 AM [Street Lamp] turned on
6:38:24 AM [Sun] has risen
6:36:24 AM [Street Lamp] turned off
6:36:24 AM [Street Lamp Off at Sunrise] has been triggered

…So, this automation is working perfectly at 6:36.24 AM. But it appears the sun.sun platform is shutting it back off again two minutes later. I have scrubbed all of my automations thoroughly and cannot find any sun.sun automations.

Any ideas on how to find the culprit?

Change your logging level to debug and trace what is happening in the logs. Or wait until 0.115 which has context (cause) next to the logbook entries. Or try the 0.115 beta now. It’s pretty stable but there are a lot of changes. Make sure you backup before trying it if you go that way. And read the beta release notes.

.115 will be helpful. Thank you. In the meantime, I put a 4 minute offset in the automation to make sure the light is off in the day. The automation works perfectly. The logbook is revealing:

6:44:25 AM [Street Lamp] turned off
6:44:25 AM [Street Lamp Off at Sunrise]has been triggered
6:42:25 AM [Street Lamp] turned on
6:42:25 AM [Sun} has risen
6:40:25 AM [Street Lamp]turned of

It is confusing that:

  1. something turns off the light at 6:40:25. This corresponds to the sun event platform time. (I no longer have an automation for this)
  2. something turns on the light at 6:42:25. The sun.sun state platform sunrise is 6:42:25. (I don’t have any sun.sun automations and i don’t understand the reason for the time difference)
  3. the automation I created with the 4 minute delay is working perfectly.

Is there a way that previous automations could be cached somewhere and need to be cleaned? Not sure how to fix this.

Dave