-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathroom_lights_count.yaml
25 lines (25 loc) · 1.02 KB
/
room_lights_count.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
platform: template
sensors:
ROOM_CODE_lights_count:
friendly_name: "ROOM_NAME Lights Count"
value_template: >-
{% if not is_state('light.ROOM_CODE_lights', 'on') and not is_state('light.ROOM_CODE_lights', 'off') %}
{% set value = "0" | int(0) %}
{% else %}
{% set value = states |
selectattr('entity_id','in',state_attr('light.ROOM_CODE_lights','entity_id')) |
selectattr('state','eq','on') | map(attribute='entity_id') | list | count | int(0)
%}
{% endif %}
{{value | int(0)}}
attribute_templates:
total_lights: >-
{% if not is_state('light.ROOM_CODE_lights', 'on') and not is_state('light.ROOM_CODE_lights', 'off') %}
{% set value = "0" | int(0) %}
{% else %}
{% set value = states |
selectattr('entity_id','in',state_attr('light.ROOM_CODE_lights','entity_id'))|
selectattr('state','ne','unavailable') | map(attribute='entity_id') | list | count %}
{% endif %}
{{value|int(0)}}