List all automations not used (triggered) in a long time

I have a sensor that show all entities that are unavailable. Mostly to track any zigbee devices not responding or that someone switched off physically. That sensor works great. Thanks to @petro for that one!

   unavailable:
     friendly_name: 'Enheter utan data'
     value_template: >
       {{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | length }}
     entity_id: sensor.time
     attribute_templates:
       entities: >
         {{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | map(attribute='entity_id') | list | join('\n') }}

Now I’d like track unused automations the same way, with a sensor, counting the number of automation whose last_triggered is for example “now() - 6 weeks”. With the automations fulfilling this criteria in an attribute to that sensor.

Any suggestions?

Here is a starting point for the list of automations (the list will contain the names of automations which never run or triggered before the “target” date (I added a “,” to make the list more readable) + at the end the number of automations meeting the condition)…

{% set entities = states.automation %}
{% set target = as_timestamp("2020-02-23 00:00:00") %}
{% for x in entities if (target |int) > (as_timestamp(x.attributes.last_triggered) | int) %}
    {{- x.entity_id -}} , 
    {%- if loop.last %} Total unused Automations: {{ loop.index }} {% endif -%}
{% endfor %}
1 Like

Thanks a lot, a great start!
Now I am trying to find a way to trim leading spaces and empty rows. Not there yet, but soon :slight_smile:

Edit: Oh, now I see you updated it. Nice work and thanks again!

Edit 2:

This:

{% set entities = states.automation %}
{% set target = as_timestamp("2020-02-23 00:00:00") %}
{% for x in entities if (target |int) > (as_timestamp(x.attributes.last_triggered) | int) %}
{{as_timestamp(x.attributes.last_triggered) | timestamp_custom('%Y-%m-%d')}}: {{x.name}}
{%- if loop.last %}

Total unused Automations: {{ loop.index }} {% endif -%}
{% endfor %}

Gives me this:
2020-01-20: Alarm - Trigger alarm while armed away - immediate
None: Alarm - Warning
2020-02-09: Notify - Brandvarnare har löst ut
2019-08-25: Notify - Säkerställ att UPSen är igång
2019-04-28: Swipe up
2019-04-06: System - Add-ons with delayed startup after restart
2019-04-14: System - Keep Google Home Alive
None: System - Notify before restart
2020-02-05: Temp - Garaget: 6°
2019-09-06: Temp - Kylen: 11°
2019-12-24: Temp - Kylen: 9°

Total unused Automations: 11

…which is just what I wanted.

1 Like