Id like to know how many times my various automations get used. I think it would be useful to have a counter attribute by default for all automations (and scripts for that matter) that we can see how many times they are run, as well as the last-triggered which we currently have.
Further to the above, would anyone know a way of achieving this, short of having to set up a counter for each automation?
So this counter attribute would record the number of times the automation was triggered from the moment it was created?
Can you provide two examples of a practical application of this information?
The value has to be stored somewhere that isn’t lost when Home Assistant restarts (such as a counter or input_text). It can even be an automation that publishes a value (as a retained message) to an MQTT topic displayed by an MQTT Sensor.
To be honest, no, I would struggle to provide examples of how to use this data. Other than the fact that it is interesting for the end user. I would find this information informative and it would allow me to look to imporve efficiency on my most used automations.
Yes, i could store a counter in an input_text, but with a large number of automations this would be very tiresome creating a counter for each corresponding automation and then having to edit each automation to add a step of increasing its counter by one. I was hoping for something a bit more autonomous than that if anyone has ideas?
Well, without having a practical application for the data makes it far less likely to attract a developer’s attention.
The Logbook already shows you when an automation has executed so you can already see how often it occurs. Frankly, the frequency of execution is tied directly to the triggers you have assigned to the automation; it’s a predictable metric.
For anyone that would like this functionality without the hassle of setting up counters for each automation and triggering an increment in each automation, I have created the following automation.
It will automatically create a MQTT sensor for each automation the first time an automation is run. It will then increment the count each subsequent time the automation is run but there is no need to create any inputs or edit any existing automations.
I have a practical use for your code (thank you btw). I have an automation that lowers my blinds if the room gets too hot. The blinds have 2 intermediate positions - so I want to run the automation a max of 2 times in a day. I’m experimenting with your code now … That all works Any idea how I’d reset all / selected counters at the end of the day?
Practical use for counting automation events: warning of switch, pumps, power etc failures and providing information to extend component lifetime.
My subfloor fan power supply just died after 12 months use (just at the warranty end) and now I want to know how often it’s power was switched on and off and would happily reduce the number of times it’s switched if that might extend its life.
Quite new to this but already surprised that an automation run counter does not exist as basic functionality. I can think of multiple use cases for this, specifically cases of measuring and catching anomalies and use patterns of devices, humans or pets.
In my case I want to know (and graph) how often the cats have visited the litter boxes, using motion sensors and a number of terms. My automation also starts the air purifier at full speed for a couple of minutes after every visit.
I’ll try the suggested workaround for now, thanks!
Is it possible to apply the automation alias as the friendly name for the sensors created so “counter_automation_trash_pickup” friendly name becomes “Trash Pickup”?