Files
zorruno-homeassistant/packages/ha_summary.yaml
T
2026-01-24 14:06:52 +13:00

247 lines
9.2 KiB
YAML

# =====================================================================
# Home Assistant Summary - package (ESPHome, Tasmota, ZHA, Zigbee2MQTT)
# Robust Z2M detection using device identifiers containing "zigbee2mqtt".
# =====================================================================
template:
- trigger:
- platform: event
event_type: homeassistant_started
- platform: event
event_type: entity_registry_updated
- platform: event
event_type: device_registry_updated
- platform: event
event_type: area_registry_updated
- platform: event
event_type: core_config_updated
- platform: time_pattern
minutes: "/5"
sensor:
# ---------- Totals and basics ----------
- name: HA Summary - entities total
unique_id: ha_summary_entities_total
state: "{{ states | list | length }}"
unit_of_measurement: "entities"
- name: HA Summary - devices total
unique_id: ha_summary_devices_total
state: >-
{% set ids = namespace(v=[]) %}
{% for s in states %}
{% set did = device_id(s.entity_id) %}
{% if did and did not in ids.v %}
{% set ids.v = ids.v + [did] %}
{% endif %}
{% endfor %}
{{ ids.v | length }}
unit_of_measurement: "devices"
- name: HA Summary - entities broken
unique_id: ha_summary_entities_broken
state: >-
{{ states | selectattr('state','in',['unavailable','unknown']) | list | length }}
unit_of_measurement: "entities"
- name: HA Summary - cameras
unique_id: ha_summary_cameras
state: "{{ states.camera | list | length }}"
unit_of_measurement: "cameras"
- name: HA Summary - areas
unique_id: ha_summary_areas
state: "{{ areas() | list | length }}"
unit_of_measurement: "areas"
- name: HA Summary - scenes
unique_id: ha_summary_scenes
state: "{{ states.scene | list | length }}"
- name: HA Summary - scripts
unique_id: ha_summary_scripts
state: "{{ states.script | list | length }}"
- name: HA Summary - automations
unique_id: ha_summary_automations
state: "{{ states.automation | list | length }}"
# ---------- ESPHome ----------
- name: HA Summary - esphome entities
unique_id: ha_summary_esphome_entities
state: "{{ integration_entities('esphome') | list | length }}"
- name: HA Summary - esphome devices
unique_id: ha_summary_esphome_devices
state: >-
{% set ids = namespace(v=[]) %}
{% for e in integration_entities('esphome') %}
{% set did = device_id(e) %}
{% if did and did not in ids.v %}
{% set ids.v = ids.v + [did] %}
{% endif %}
{% endfor %}
{{ ids.v | length }}
# ---------- Tasmota ----------
- name: HA Summary - tasmota entities
unique_id: ha_summary_tasmota_entities
state: "{{ integration_entities('tasmota') | list | length }}"
- name: HA Summary - tasmota devices
unique_id: ha_summary_tasmota_devices
state: >-
{% set ids = namespace(v=[]) %}
{% for e in integration_entities('tasmota') %}
{% set did = device_id(e) %}
{% if did and did not in ids.v %}
{% set ids.v = ids.v + [did] %}
{% endif %}
{% endfor %}
{{ ids.v | length }}
# ---------- Zigbee via ZHA ----------
- name: HA Summary - zha entities
unique_id: ha_summary_zha_entities
state: "{{ integration_entities('zha') | list | length }}"
- name: HA Summary - zha devices
unique_id: ha_summary_zha_devices
state: >-
{% set ids = namespace(v=[]) %}
{% for e in integration_entities('zha') %}
{% set did = device_id(e) %}
{% if did and did not in ids.v %}
{% set ids.v = ids.v + [did] %}
{% endif %}
{% endfor %}
{{ ids.v | length }}
# ---------- Zigbee via Zigbee2MQTT (robust) ----------
# Match if device identifiers mention "zigbee2mqtt".
# Fallbacks: entity_id or unique_id contains "zigbee2mqtt" or ".z2m_".
- name: HA Summary - z2m entities
unique_id: ha_summary_z2m_entities
state: >-
{% set ent = namespace(v=[]) %}
{% for s in states %}
{% set eid = s.entity_id %}
{% set did = device_id(eid) %}
{% set match = false %}
{% if did %}
{% set ident = device_attr(did,'identifiers') | default([], true) %}
{% if (ident | string | lower) | regex_search('zigbee2mqtt') %}
{% set match = true %}
{% endif %}
{% endif %}
{% if not match %}
{% set uid = state_attr(eid,'unique_id') | default('', true) | string | lower %}
{% if 'zigbee2mqtt' in eid or '.z2m_' in eid or 'zigbee2mqtt' in uid %}
{% set match = true %}
{% endif %}
{% endif %}
{% if match %}
{% set ent.v = ent.v + [eid] %}
{% endif %}
{% endfor %}
{{ ent.v | unique | list | length }}
- name: HA Summary - z2m devices
unique_id: ha_summary_z2m_devices
state: >-
{% set dids = namespace(v=[]) %}
{% for s in states %}
{% set eid = s.entity_id %}
{% set did = device_id(eid) %}
{% if did and did not in dids.v %}
{% set ident = device_attr(did,'identifiers') | default([], true) %}
{% set uid = state_attr(eid,'unique_id') | default('', true) | string | lower %}
{% if (ident | string | lower) | regex_search('zigbee2mqtt') or
'zigbee2mqtt' in eid or '.z2m_' in eid or 'zigbee2mqtt' in uid %}
{% set dids.v = dids.v + [did] %}
{% endif %}
{% endif %}
{% endfor %}
{{ dids.v | length }}
# ---------- Cloud devices/entities (edit list as desired) ----------
- name: HA Summary - cloud entities
unique_id: ha_summary_cloud_entities
state: >-
{% set list_all =
integration_entities('tuya') +
integration_entities('ewelink') +
integration_entities('meross_cloud') +
integration_entities('tapo') +
integration_entities('tplink') +
integration_entities('nest') +
integration_entities('ring') +
integration_entities('arlo') +
integration_entities('wyze') +
integration_entities('myq') +
integration_entities('nuki') +
integration_entities('august') +
integration_entities('switchbot') +
integration_entities('icloud')
%}
{{ list_all | unique | list | length }}
- name: HA Summary - cloud devices
unique_id: ha_summary_cloud_devices
state: >-
{% set dids = namespace(v=[]) %}
{% for e in (
integration_entities('tuya') +
integration_entities('ewelink') +
integration_entities('meross_cloud') +
integration_entities('tapo') +
integration_entities('tplink') +
integration_entities('nest') +
integration_entities('ring') +
integration_entities('arlo') +
integration_entities('wyze') +
integration_entities('myq') +
integration_entities('nuki') +
integration_entities('august') +
integration_entities('switchbot') +
integration_entities('icloud')
) | unique %}
{% set did = device_id(e) %}
{% if did and did not in dids.v %}
{% set dids.v = dids.v + [did] %}
{% endif %}
{% endfor %}
{{ dids.v | length }}
# ---------- Supervisor add-ons (approximate) ----------
# Union of: update entities in hassio integration + updates attributed to Supervisor.
- name: HA Summary - addons
unique_id: ha_summary_addons
icon: mdi:puzzle
state: >-
{% set hassio_updates = (integration_entities('hassio') | list) %}
{% set a = states.update
| selectattr('entity_id','in', hassio_updates)
| map(attribute='entity_id')
| list %}
{% set b = states.update
| selectattr('attributes.attribution','defined')
| selectattr('attributes.attribution','search','Supervisor')
| map(attribute='entity_id')
| list %}
{% set ids = (a + b)
| unique
| reject('search','^update\\.home_assistant_(core|supervisor|operating_system)_update$')
| list %}
{{ ids | length }}
# ---------- HACS updates available (proxy only) ----------
- name: HA Summary - hacs updates
unique_id: ha_summary_hacs_updates
icon: mdi:download
state: >-
{{ states.update
| selectattr('state','eq','on')
| rejectattr('attributes.in_progress','true')
| list | length }}