HI,
we can check if and when an automation has been triggered by the last_triggered attribute. Im looking for a way however to check if it has finished. No attributes of that kind are available i believe?
For testing purposes and feedback I mostly end an automation with some kind of notification, but that tends to run me into the notification threshold per day
Would be really nice if we had a automation attributes.has_finished boolean or timestamp.
Or is there another way of easily doing this?
Thx,
Marius
In general itās better (IMHO) to put all your actions in scripts and then call the script from the automation. (I even sometimes have the automation first cancel the script, in case it was already running, and then call it.) If you do, you get the added benefit of having a way to tell if the script is finished - itās āonā when itās running, and itās āoffā when itās done. Just be aware there might be a slight delay from calling the script until its state actually changes to āonā.
thatās a very interesting and rather fundamental paradigm (change). Makes many of the automations much shorter ā¦
would you please give me an example of one such automation? If possible even one that passes the trigger values from the automaton to the scripts?
Sure. This is close, but it doesnāt exactly pass the trigger values to the script:
- alias: Nest Thermostat
trigger:
platform: state
entity_id: input_select.home_mode
condition:
condition: template
value_template: >
{{ trigger.from_state.state in ['Home', 'Returning'] and
trigger.to_state.state in ['Away', 'Vacation'] or
trigger.from_state.state in ['Away', 'Vacation'] and
trigger.to_state.state in ['Home', 'Returning'] }}
action:
- service: script.turn_off
entity_id:
- script.nest_eco_on
- script.nest_eco_off
- script.nest_eco_check
- service_template: >
{% if trigger.to_state.state in ['Away', 'Vacation'] %}
script.nest_eco_on
{% else %}
script.nest_eco_off
{% endif %}
This automation calls the appropriate script to turn my Nest thermostat to ECO mode when we leave, or to return it to its previous mode when we are returning or have returned. Thereās a third script that those scripts call to make sure the change has actually occurred (since sometimes it doesnāt. But that was mostly before the HA Nest integration changed to Nestās Streaming REST API.)
Anyway, you can see that it first cancels all three scripts in case any of them were running, and then based on the new āhome modeā it calls the appropriate script.
Ok , thats nice and tidy indeed, thanks. Im using the service_templates quite often already, but had not met the need for this. Ill recheck my automations if they should be adapted this way.
Ill check Help! Light brightness by lux level automation - #16 by petro for the variable passing, in @petro 's example.