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.
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 %}