Hi,
thanks for suggestion, I already tried this but it don’t seem to solve my problem…If I setup 20 minutes, all work fine, but if I setup 20 hours don’t work: I think if I reboot HASSIO in the interval of 20 hours (very likely) it reset the counter…
Ok, so your description was misleading. The automation doesn’t always trigger at '00:00', that’s apparently just an example. Now I see it is triggered by a sensor changing state. Thanks for the clarification. Of course, given this new information, my original suggestion doesn’t make sense anymore.
Yes, you are correct. If during the 20 hour delay HA restarts, or the automation is turned off and back on, or if automations are reloaded, the automation is reset, meaning it will stop and be re-initialized, and of course, not execute the step(s) following the delay.
BTW, if the automation is triggered while it is waiting in the delay from the last trigger, it will immediately about the delay and execute the next step in the action sequence, which is probably also not what you want.
If you want to make this handle those scenarios, I would suggest replacing the delay step in the current automation with a service call that writes the current time into an input_datetime (with both time and date), and then add another automation that triggers when the time reaches (or exceeds) the date/time recorded in that input_datetime, plus 20 hours.
Yeah, what Phil said, except I’d probably store the time 20 hrs from the trigger ie + (20x60x60) do you need it to the second, or is the previous whole minute good enough ?
Currently, delays and timers cannot survive a restart. If either one is mid-way through its countdown when it’s interrupted by a restart, their countdown is lost. The link above shows a way of restoring timers that were active prior to the restart (it can’t restore a delay).
Just wonder if there a better solution than an automation triggered by a template trigger that uses sensor.time and compares it with the stored time?
I use a slightly different approach - run a timer instead of delay (with an automation on timer.finish), and on HA restart I start the timer with adjusted duration (as I know when the timer started and what was its duration).
automation:
alias: "notifica il giorno dopo il ritiro indifferenziata"
trigger:
platform: template
value_template: "{{ states('sensor.date_time').replace(',', '')|as_timestamp >= state_attr('input_datetime.datetime_indifferenziat', 'timestamp') + 20*60*60 }}"
condition: []
action:
- service: notify.famiglia
data:
message: "Attenzione: oggi è giorno di ritiro indifferenziata."
- service: notify.alexa_media
data:
target:
- media_player.echo_dot_di_daniele
data:
type: announce
message: "Attenzione: oggi è giorno di ritiro indifferenziata."
automation:
alias: "notifica il giorno dopo il ritiro indifferenziata"
trigger:
platform: template
value_template: "{{ states('sensor.date_time').replace(',', '')|as_timestamp >= state_attr('input_datetime.datetime_indifferenziat', 'timestamp') + 20*60*60 }}"
condition: []
action:
- service: notify.famiglia
data:
message: "Attenzione: oggi è giorno di ritiro indifferenziata."
- service: notify.alexa_media
data:
target:
- media_player.echo_dot_di_daniele
data:
type: announce
message: "Attenzione: oggi è giorno di ritiro indifferenziata."