trigger:
- platform: time
at: "00:00"
- platform: time
at: "02:00"
- platform: time
at: "10:00"
- platform: time
at: "20:00"
condition:
- condition: template
value_template: "{{(states('sensor.meteonetwork_daily_rain')|int |default(0)) <= 30}}"
action:
[something]
Please remember that is an example.
In real life the “conditional” code is much more complex.
My goal is manage when the automation:
is not yet triggered
is not triggered (example for power problem)
is triggered but not fired (for condition respect)
is triggered and fired
So I thought I’d create a input_select for each trigger time :
test02:
options:
- automation fired
- automation not yet triggered
At 00:00 time tha automation set the input_select to: automation not yet triggered
In this way I can manage points 1 and 4.
Points 2 and 3 remain unsolved for which the input select would always remain on: automation not yet triggered
Point 2 because the automation not start;
Point 3 because the automation trigger but not fire (It would be useful to create an attribute last_fired for the automation).
Do you know of any way to check if the automation has triggered but not fired without having to make an automation that checks the automation?
What does manage mean? The last_triggered attribute can be used to see if it hasn’t triggered since some other point in time. There are infinite things that can happen without triggering the automation. You cannot “manage” that.
Best I can think of is to make a list of all entities involved, and if any of them change and the automation does not fire, it must have been stopped by a condition. But still, I fail to see what it manages. What do you hope to accomplish?
An automation’s last_triggered attribute indicates the time when the automation executed its actions. In other words, one of the automation’s triggers has fired and the automation’s condition has been met and the automation proceeds to execute its action. A trace is produced.
If one of the automation’s triggers fires but its condition is not met then last_triggered is not updated. A trace is produced. Beyond that, there’s no other other record of the event.
@Pico1965 First of all, your terminology is rather incorrect.
Point #1 cannot be determined:
is not yet triggered
and why would you want to know this?? If for some reason unbeknownst to me you do, you’d need another mechanism to check for example if the time is after 00:00 but before 02:00 then next execution should occur at 02:00. Same for after 02:00 but before 10:00, after 10:00 but before 20:00, after 20:00 but before 23:59:59.
As for points 2, 3 and 4, they should be worded like this:
2. was not triggered - I.e. HA was not running or restarting and the time trigger was missed
3. was triggered but did not complete execution (for condition respect)
4. was triggered and execution completed
Have a look at this example I put together which has two different ways of dealing with the 4 time triggers.
Just substitute your input_select(s) for the fire_event calls where needed.
Or, you can retain those fire_event calls and in another automation (or automations) you can listen for those events and update your input_selects, or whatever…
As for point #2, you’d need an automation triggered by homeassistant start:
- platform: homeassistant
event: start
id: HA Start
and another choice option that figures out what to do in that case.
I.e. if time is after 00:00 but before 02:00 and input_select for automation_at_00:00 is not executed, then do those steps. Ditto for the next three time windows. Note though: when executed at 00:00, set input_select for 00:00 to triggered followed by executed. When 02:00 fires, it needs to set input_select for 00:00 back to not_triggered in addition to input_select for 02:00 to triggered and then executed, and so on and so forth.
It might be easier to have 4 different scripts of actions to perform (if there are different steps needed) for the 4 different time triggers and then the HA Start trigger can execute the appropriate script if the current time is after xx:xx but before xx:xx and the state of input_select shows not_executed.
If time < 02:00 and 00:00 is not_triggered then run that script of conditions and actions.
If time < 10:00 and 02:00 is not_triggered then run that script of conditions and actions
If time < 20:00 and 10:00 is not_triggered then run that script of conditions and actions
If time < 23:59:59 and 20:00 is not_triggered then run that script of conditions and actions
Then at 23:59:59 set then all to not_triggered.
The phases would be 1. not_triggered, 2. triggered, and 3. completed, then, rather than having a central condition to fail the automation steps to complete them, you’ll need to first perform an action of setting the input_select to triggered then followed by the conditional execution of desired actions ending with setting input_select to completed.