#Best way to trigger on automation enable/disable?

1 messages ยท Page 1 of 1 (latest)

neat sphinx
#

I have been trying to build an automation that triggers if an automation is enabled or disabled (any automation).

I have a working setup, but I am mainly worried about performance issues with this setup. The ony way I could get this to work was doing:

    trigger:
      - platform: event
        event_type: state_changed

Which triggers like 10 times a second.

Is there any way to filter at the trigger level or trigger on in a better way for automations?

I tried something like:

 trigger:
      - platform: event
        event_type: state_changed
        event_data:
          entity_id: automation.*

But HA doesn't like the asterisk.

   trigger:
      - platform: state
        entity_id:
          - automation.example1
          - automation.example2

This isn't scalable. It's not really helpful to list everything manually, I would prefer labels/tags.

I already have a fast fail condition, but, am ony worried about the trigger situation.

opaque bronze
#

I would create a template sensor that counts the number of enabled automations:
{{ states.automation|selectattr('state', 'eq', 'on')|list|count}}

#

then make an automation with a state trigger based on the state of that template sensor entity changing

neat sphinx
#

Hm, that might, wouldn't this require tracking in some way or is there a way to have HA provide better feedback on what automation was enabled/disabled?

Because the end goal I have here, is to re-enable an automation that was disabled, only if it has specific labels attached. Think of it like a watch dog.

#

The current code I have works, with the all events situation. But thinking about the way you are describing, I am just having a hard time figuring out how I would determine what state was actually changed based on the trigger.

What you are suggesting would only trigger on if count goes down, right?

opaque bronze
#

you said "any automation" ๐Ÿ™‚

neat sphinx
#

Haha, well, any automation in a broad sense. ๐Ÿ™‚

opaque bronze
#

yes, it's more complicated if you care which one, but you can do that fairly easily now with some new template functions that were just added

neat sphinx
#

Hm... which template functions were just added? ๐Ÿ˜… I might need to update then. haha

karmic void
#

The real question is why are you turning off automations. IE is there a better way to accomplish what you are doing.

neat sphinx
#

Because I am being stubborn on some automations that are trying to help me. ๐Ÿ˜„

#

When you "know the system" ad know how to "evade the system", it's easy to "evade the system" by turning off some of those automations

opaque bronze
#

What you are suggesting would only trigger on if count goes down, right?
No, it reacts to any change in the number of enabled automations