Inconsistent Automations

So I have an automation that sets the lights in the morning at sunrise. It’s supposed to readjust every minute, then turn warm in the evening. When it works, it works the whole way. But more than half the time, it’s like the automation simply doesn’t run. Here are some code snippets.

Light adjusting automation

alias: "managed_morning"
initial_state: 'on'
trigger:
  platform: time
  minutes: '/1'
  seconds: 00
condition:
  condition: sun
  after: sunrise
  before: sunset
action: 
  service: script.matchlights

Automation that enables the automation above (as well as the evening one)

alias: "Managed Lighting"
initial_state: 'on'
trigger:
  platform: sun
  event: sunrise
  offset: '-00:45:00'
condition:
  condition: sun
  after: sunrise
  before: sunset
action: 
  - service: automation.turn_on
    entity_id: automation.managed_morning
  - service: automation.turn_on
    entity_id: automation.managed_evening

The reason for this odd structure is that I have it disable the light management when I activate a theme. That way, the lights don’t revert back a minute later. So the second automation re-enables the light management automations 45min before sunrise, that way it is always activated in the morning and helps me wake up.

But like I said, it’s only working half the time or less.

Any clues? How consistent are automations generally?

trigger:
  platform: sun
  event: sunrise
  offset: '-00:45:00'
condition:
  condition: sun
  after: sunrise
  before: sunset

As I understand it, the trigger is before sunrise, but the condition imposes that you are after sunrise.
You could simply check in your log if the automation “Managed Lighting” has ever been executed. If not, the offset is the issue.

The easiest fix is to delete the condition altogether, because if you are 45min before sunrise it is obviously before sunset too, and delete the after sunrise because you can’t obviously be in the same time before and after the sunrise :wink:

For the explanation of why it works some time and doesn’t other times, I think it only depends on when you activate scene (and therefore turn off the automation). If the automation is anytime off, it will never turn on again. And if you restart HASS, it will turn on by default and then your automation “managed_morning” will work as long as you do not activate any scene.

Wow, how did I miss that one? Why do I even have those conditions there? Must have been a copy-paste issue.

I’m surprised it even works at all. “Turn on 45 minutes before sunrise…so long as it is AFTER sunrise”. That’s why you don’t code past midnight.

I’ll change this and give it a try. Thanks!