That’s indeed nicer than my PoC syntax. I’d however suggest selectattr('attributes.current', 'gt', 0) instead of selectattr('attributes.current', 'eq', 1), cause automations can run parallel, and most likely setting the current to more than 1.
I wanna thank you for this, both 123 and Recte. 123’s answer could/should be marked as solution/answer for this topic.
I was looking for the same thing and I’m happy to find this topic. I want to push this one step further:
"Give me the number of automations which have been triggered (were running) during the last 24 hours"
Can I achieve this by a simple template sensor? I guess I would somehow need to cross-check/compare the last_triggered time with the (current minus 24 hours) time, right? Anyone with a syntax PoC for this?
The reason it doesn’t work likely is that “you” are comparing two different types.
If you enter {{ states.automation | map(attribute="attributes.last_triggered") | list}} you will notice that it shows something like:
Without that test it will include automations that lack a last_triggered attribute (new automations that have never been triggered have no last_triggered). As a consequence, the template will fail when it processes the new automation while testing if its non-existent last_triggered is greater than today_at().
EDIT
Correction. New, never-triggered automations do have a last_triggered attribute but its value is null (none). It’s unavailable automations that lack a last_triggered attribute (a rare category of automations).
You’re right; my mistake. The issue arises for automations whose state is unavailable and genuinely don’t have a last_triggered attribute (it doesn’t occur for automations that have never been triggered because they do actually have a last_triggered attribute but its value is simply null).
Here’s what happens when the template encounters an unavailable automation:
I had a similar question that @tom_l answered. His answer includes a “Missing Automations” section and I do have 1 listed in there. And I am puzzled. I believe it’s an old automation that I ended up replacing by another automation (renamed? or created a new one? don’t remember). So I guess my question is, why is this automation “missing” and how can I make it go away?