From 1b00f851cd2c77c90ef97d6d635babe4ce91df5c Mon Sep 17 00:00:00 2001 From: jessikitty Date: Mon, 5 Jan 2026 17:49:08 +1100 Subject: [PATCH] Add template sensors for device counts per person --- discovered_devices_sensors.yaml | 99 +++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 discovered_devices_sensors.yaml diff --git a/discovered_devices_sensors.yaml b/discovered_devices_sensors.yaml new file mode 100644 index 0000000..db44def --- /dev/null +++ b/discovered_devices_sensors.yaml @@ -0,0 +1,99 @@ +sensor: +- platform: template + sensors: + count_devices_bella: + friendly_name: Bella's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''Bella'') + | list | count }}' + icon_template: mdi:counter + count_blocked_bella: + friendly_name: Bella's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'Bella')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel + count_devices_xander: + friendly_name: Xander's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''Xander'') + | list | count }}' + icon_template: mdi:counter + count_blocked_xander: + friendly_name: Xander's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'Xander')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel + count_devices_william: + friendly_name: William's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''William'') + | list | count }}' + icon_template: mdi:counter + count_blocked_william: + friendly_name: William's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'William')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel + count_devices_jess: + friendly_name: Jess's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''Jess'') + | list | count }}' + icon_template: mdi:counter + count_blocked_jess: + friendly_name: Jess's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'Jess')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel + count_devices_parents: + friendly_name: Parents's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''Parents'') + | list | count }}' + icon_template: mdi:counter + count_blocked_parents: + friendly_name: Parents's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'Parents')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel + count_devices_system: + friendly_name: System's Device Count + value_template: '{{ states.input_select | selectattr(''entity_id'', ''match'', + ''^input_select.device_owner_.*'') | selectattr(''state'', ''eq'', ''System'') + | list | count }}' + icon_template: mdi:counter + count_blocked_system: + friendly_name: System's Blocked Devices + value_template: "\n{% set devices = states.input_select | selectattr('entity_id',\ + \ 'match', '^input_select.device_owner_.*') | selectattr('state', 'eq', 'System')\ + \ | map(attribute='entity_id') | list %}\n{% set blocked = namespace(count=0)\ + \ %}\n{% for device in devices %}\n {% set device_name = device.replace('input_select.device_owner_',\ + \ '') %}\n {% set block_entity = 'input_boolean.block_device_' ~ device_name\ + \ %}\n {% if states(block_entity) == 'on' %}\n {% set blocked.count =\ + \ blocked.count + 1 %}\n {% endif %}\n{% endfor %}\n{{ blocked.count }}" + icon_template: mdi:cancel