Skip to content

Commit 190646e

Browse files
authored
Refactor template sensor configuration for clarity
1 parent dd02042 commit 190646e

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

examples/water_monitor_package.yaml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,26 @@ input_datetime:
7575
has_date: true
7676
has_time: true
7777

78-
###############################
79-
# Template Sensors (optional) #
80-
###############################
81-
sensor:
82-
- platform: template
83-
sensors:
84-
water_monitor_any_leak_active:
85-
friendly_name: Water Monitor Any Leak Active
86-
unique_id: water_monitor_any_leak_active
87-
value_template: >
88-
{% set leaks = states.binary_sensor | selectattr('state','eq','on')
89-
| selectattr('attributes.device_class','defined')
90-
| selectattr('attributes.device_class','eq','problem')
91-
| selectattr('entity_id','search','_low_flow_leak|_tank_refill_leak|_intelligent_leak') | list %}
92-
{{ 'on' if leaks|length > 0 else 'off' }}
93-
attribute_templates:
94-
active_leaks: >
95-
{% set leaks = states.binary_sensor | selectattr('state','eq','on')
96-
| selectattr('attributes.device_class','defined')
97-
| selectattr('attributes.device_class','eq','problem')
98-
| selectattr('entity_id','search','_low_flow_leak|_tank_refill_leak|_intelligent_leak') | list %}
99-
{{ leaks | map(attribute='entity_id') | list }}
78+
###################
79+
# Template Sensors#
80+
###################
81+
template:
82+
sensor:
83+
- unique_id: water_monitor_any_leak_active
84+
name: Water Monitor Any Leak Active
85+
state: >
86+
{% set leaks = states.binary_sensor | selectattr('state','eq','on')
87+
| selectattr('attributes.device_class','defined')
88+
| selectattr('attributes.device_class','eq','problem')
89+
| selectattr('entity_id','search','_low_flow_leak|_tank_refill_leak|_intelligent_leak') | list %}
90+
{{ 'on' if leaks|length > 0 else 'off' }}
91+
attributes:
92+
active_leaks: >
93+
{% set leaks = states.binary_sensor | selectattr('state','eq','on')
94+
| selectattr('attributes.device_class','defined')
95+
| selectattr('attributes.device_class','eq','problem')
96+
| selectattr('entity_id','search','_low_flow_leak|_tank_refill_leak|_intelligent_leak') | list %}
97+
{{ leaks | map(attribute='entity_id') | list }}
10098
10199
102100
#############################################

0 commit comments

Comments
 (0)