I have automations that trigger when time is equal to a timestamp-class sensor. In this case, it’s a sensor managed by an integration that tells me the start time of my free power for the day. sensor.hour_of_free_power_start
The sensor occasionally becomes unavailable, like when the integration wants me to log back in. If the sensor is unavailable at the time the automation would otherwise trigger, the automation doesn’t trigger. No surprises there.
The sensor is a device_class: timestamp and is reset by the integration each day, and includes the date in the sensor value. 2024-07-26T18:00:00+00:00
The time portion of the timestamp does not typically change. i.e. the free power starts at typically the same time each day, so the date is somewhat superfluous. It might take me a day or two to realise that the sensor is unavailable and ‘fix it’ by re-authenticating the integration.
My original thinking was to create a cache version of the sensor that could be included in the automation trigger if the original sensor was unavailable. In fact as a general strategy I thought it made sense to have a cache of the last value of every sensor that could become unavailable, so that if a sensor becomes unavailable, I can at least use it’s last value as a trigger for an automation (or something else).
For the specific use case of the timestamp for starting my free power (sensor.hour_of_free_power_start), I’ve run into my first problem with this strategy. Because the timestamp includes the date, then a cached version of this sensor would not trigger at the same time the following day. I really only want to cache/use the time component of that sensor. And I don’t practically know how to capture, save and then use only the time portion in the automation trigger.
So, my questions for the community are as follows:
- Am I approaching the problem of ‘automations missing their triggers when timestamp sensors become unavailable’ all wrong? Or does this approach seem sensible (I’m sceptical its the best one)
- If somehow using a ‘last value’ cached version of a sensor is a good way to approach it, how would I practically save the ‘last value’ cache.
- And if I had a ‘last value’ cache version of a timestamp sensor, how could I extract and use the time component as an automation trigger.