Hello everyone,
I'm seeking advice on a persistent automation trigger issue related to the dynamic nature of time-based template sensors. I want to understand how the internal Sun component manages its events, and how to replicate that reliability when using adjusted times.
I defined these template sensors to calculate the adjusted time once and use that single entity everywhere (automations, conditions, dashboards, etc.), especially for my customized Day/Night cycle logic.
I am aware of workarounds (like using the standard 'platform: sun' with 'offset', or updating an 'input_datetime' via automation every night), but I am specifically looking for a cleaner, robust solution that allows a time trigger to reliably fire based on the value of a dynamic template sensor.
Time Trigger Reliability
I have an automation designed to switch an 'input_boolean.jour_nuit' based on adjusted sunrise/sunset times, which are calculated using template sensors. The time trigger fails because the sensor's state updates before the time stored in its state is reached, causing the trigger to disarm.
This is a race condition between the time trigger arming and the sensor state updating for the next day. Because the underlying sensor value changes for the next day often before the programmed time is reached, no standard time or template trigger can reliably fire on the current day's value.
My Question
The built-in 'platform: sun' trigger works perfectly using the 'offset:' feature.
How does the internal Home Assistant Sun component handle these time events to avoid the race condition? Is there a recommended, robust method for using a time trigger with a dynamic template sensor that changes daily and avoids the state update causing a disarm?
Thank you for your insights!