Add template sensors for device counts per person

This commit is contained in:
2026-01-05 17:49:08 +11:00
parent 56dd553642
commit 1b00f851cd

View File

@@ -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