Using Enabled/Disabled as Automation Trigger

Do state triggers for automation being enabled and disabled work on the same automation? The triggers do fire when my test automation is enabled or disabled but no conditions or actions run, and no trace is generated either.

alias: Foo
trigger:
  - platform: state
    entity_id:
      - automation.foo
    to: "on"
  - platform: state
    entity_id:
      - automation.foo
    to: "off"
...

They don’t. A trace is produced when an automation is triggered and no traces are produced when the following automation is enabled/disabled.

alias: Foo
description: ""
trigger:
  - platform: state
    entity_id:
      - automation.foo
    to: "on"
  - platform: state
    entity_id:
      - automation.foo
    to: "off"
condition: []
action:
  - service: notify.persistent_notification
    data:
      message: "{{ trigger.to_state.state }}"

When the automation’s state changes from off to on, the State Trigger is functional only after the state-change is complete. Therefore it cannot detect the state-change.

When the automation’s state changes from on to off, the State Trigger ceases to be functional after the state-change is complete. Therefore it cannot detect it.

I see. I was suspecting that that was the workflow. However, the GUI highlights the trigger as firing. I guess it’s a false positive.

I see that too but it’s misleading; it’s reported exclusively by the Automation Editor (basically, it’s a bug).

No matter how many times you enable/disable that automation, it will never report it was ever triggered.

Fair enough. Ended up simply using the state of an input_boolean as condition for execution.

I don’t know if something changed since this post was solved, but you can trigger an automation by itself being enabled and then self disable.

alias: NotNowCatToy
trigger:

  • platform: state
    entity_id:
    • automation.notnowcattoy
      to: “on”
      condition:
      action:
  • service: mqtt.publish
    data:
    qos: 0
    retain: false
    topic: home/esp32s3/toy
    payload: “0”
  • service: automation.turn_off
    metadata: {}
    data:
    stop_actions: false
    target:
    entity_id: automation.notnowcattoy
    mode: single

For me, all I had to do was disable the ‘stop_actions’… I guess otherwise it stops its own deactivation before desactivating itself.