How to check if an automation has finished?

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 :wink:

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.