How to use a script as a condition depending when it was last triggered

Hi guys,

Find this hard to figure out.

I want to have a an automation which will only run if another script was run prior. If said script has not run then the automation should not be triggered.

Basically, Automation A should only run if script X was run. IF Automation A does run because script X was run then Automation A should not run again until after script X has run.

Hopefully I don’t sound like an idiot and someone understands me

Any advice on how to do this?

Hi,
You can set binary_input helper on the end of script an use it as a trigger in automation. Then at the begin of the automation, reset binary_input back.

Scripts and automations have an attribute called last_triggered which can be used in a template condition as follows:

condition:
  - alias: Script X ran within the last 2 minutes
    condition: template
    value_template: >
      {% set last_t = state_attr('script.X', 'last_triggered') 
      | default(as_datetime(0) ,1) %}
      {{ now() - last_t <= timedelta( minutes=2 ) }}