Automation based on Time Events

Hi
I have 2 automations base on “time event” that seemed to be working fine until last update.

1 was to turn on a few lights at offset -1hr of sunset… currently seems to be triggering at sunset

2 was to turn off those lights at 6am . currently doesnt operate at all…

Suggests what the issue might be?

I am running my Home Assistant on an Unix Virtual Machine on a windows 10 machine…

Regards
mrrcomp

Post your automation in YAML format.

@123
thanks for your response this is the first one

Trigger

trigger: sun
event: sunset
offset: "-01:00:00"

Action

type: turn_on
device_id: 5c020e7193d642d73f21885ef5fa1753
entity_id: e400e515e6429a073633565cebfdac9b
domain: switch

The second one
trigger

trigger: time
at: "06:00:00"

Action

type: turn_off
device_id: 5c020e7193d642d73f21885ef5fa1753
entity_id: e400e515e6429a073633565cebfdac9b
domain: switch

Thanks for your help
mrrcomp

Copy-paste the following template into the Template Editor and confirm it reports the correct current time and next sunset time.

{{ now() }}

{{ states('sensor.sun_next_setting') | as_datetime | as_local }}

Is the automation disabled? If it’s enabled, does it have any traces? If it does, when was the last trace?

@123

Thanks what i see from the template is

2025-02-04 23:23:04.565769+02:00

2025-02-05 17:17:31+02:00

So what now??

Regards
mrrcomp

Those two times appear to be valid so we know that the system clock and timezone are correct. In other words, they will properly trigger a Time Trigger and Sun Trigger.

Awaiting answers to my other questions.

@123
I had recreated the “off” automation last night . Its now 6:20am it hasn’t triggered and there are no traces found…

The “on” automation trace shows it was triggered last night at 5:34PM (which is sunset but didn’t take into account the offset of -1 .hr

regards

Meir

Post the full automations in YAML, not just parts of them.

i edited the “off” automation at 6:15 to trigger at 6:45 and it just triggered as requested. Perhaps the “on hour” doesn’t work ? i will try to edit it for :5:45 tomorrow and see if that works better… and keep you updated if i still have issues

Thanks for your help

mrrcomp

Any valid time works.

The fact it worked but only after you changed the time implies there’s something not quite right but what exactly is unclear. Effectively, the automation worked after it had been modified and saved.

Did you originally create the second automation using the Automation Editor or with a text editor? The reason why I ask is that if an automation is created or modified with a text editor, the changes aren’t registered until the automation integration is reloaded (Developer Tools → YAML → Reload Automations).

1 Like

@123

I used the Automation Editor … both on the older one and the newer one

In that case, I can’t think of a reason why the following Sun Trigger would fail to trigger at 1 hour before sunset.

alias: example 1
triggers:
  - trigger: sun
    event: sunset
    offset: "-01:00:00"
conditions: []
actions:
  - type: turn_on
    device_id: 5c020e7193d642d73f21885ef5fa1753
    entity_id: e400e515e6429a073633565cebfdac9b
    domain: switch
mode: single

Nor is there any reason to prevent this automation from triggering at 06:00:00.

alias: example 2
triggers:
  - trigger: time
    at: "06:00:00"
conditions: []
actions:
  - type: turn_off
    device_id: 5c020e7193d642d73f21885ef5fa1753
    entity_id: e400e515e6429a073633565cebfdac9b
    domain: switch
mode: single

How do you have HA installed? There have been quite a few issues in the past with accurate time-based triggers on systems that used certain VM software. It often boils down to an issue with either the lack of an RTC, issues with Network Time Protocol, or incorrect paravirtualization settings.

Yes it on vm

FWIW, the OP had mentioned using a VM so my first question was to have him confirm that current time and next_setting time are correct. Apparently they are correct which adds to the mystery of why two time-related triggers are either misbehaving (triggers at sunset but without the offset) or failing (doesn’t trigger at 06:00:00).

Especially odd that the Time Trigger started working after its time value was modified. This isn’t behaving like a healthy system.