Skip to content

Commit ce30b5b

Browse files
sdaguefabaff
authored andcommitted
Fix binary_sensor.template example (home-assistant#2877)
The binary_sensor.template was return states of "On" and "Off", however that doesn't seem to work in 0.47. You need True / False, which makes sense, given that's what the single line evals are going to return. Update the existing example, and add another one about computing composite occupancy from device tracker and motion sensors.
1 parent ed28d46 commit ce30b5b

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

source/_components/binary_sensor.template.markdown

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,40 @@ sensor:
5656
Some movement sensors and door/window sensors will appear as a switch. By using a template binary sensor, the switch can be displayed as a binary sensors. The original switch can then be hidden by [customizing.](/getting-started/customizing-devices/)
5757

5858
```yaml
59-
binary_sensor:
60-
- platform: template
59+
binary_sensor:
60+
- platform: template
6161
sensors:
6262
movement:
6363
value_template: {% raw %}"{{ states.switch.movement.state == 'on' }}"{% endraw %}
6464
device_class: motion
6565
door:
66-
value_template: {% raw %}"{{ states.switch.door.state == 'on' }}"{% endraw %}
66+
value_template: {% raw %}"{{ states.switch.door.state == 'on' }}"{% endraw %}
6767
device_class: opening
6868
```
6969

7070

7171
### {% linkable_title Combining multiple sensors, and using entity_id: %}
7272

73-
This example combines multiple CO sensors into a single overall status. It also shows how to use `entity_id`
73+
This example combines multiple CO sensors into a single overall
74+
status. When using templates with binary sensors, you need to return
75+
`True` or `False` explicitly. `entity_id` is used to limit which
76+
sensors are being monitored to update the state, making computing this
77+
sensor far more efficient.
7478

7579
```yaml
76-
binary_sensor:
77-
- platform: template
80+
binary_sensor:
81+
- platform: template
7882
sensors:
7983
co:
8084
friendly_name: 'CO'
8185
device_class: 'gas'
8286
value_template: {% raw %}>-
83-
{%- if is_state("sensor.bedroom_co_status", "Ok")
87+
{%- if is_state("sensor.bedroom_co_status", "Ok")
8488
and is_state("sensor.kitchen_co_status", "Ok")
8589
and is_state("sensor.wardrobe_co_status", "Ok") -%}
86-
Off
90+
False
8791
{%- else -%}
88-
On
92+
True
8993
{%- endif %}{% endraw %}
9094
entity_id:
9195
- sensor.bedroom_co_status
@@ -104,5 +108,41 @@ sensor:
104108
friendly_name: 'Day/Night'
105109
value_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}Day{% else %}Night{% endif %}'{% endraw %}
106110
icon_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}mdi:weather-sunny{% else %}mdi:weather-night{% endif %}'{% endraw %}
107-
111+
```
112+
113+
### {% linkable_title Is anyone home? %}
114+
115+
This example is determining if anyone is home based on the combination
116+
of device tracking and motion sensors. It's extremely useful if you
117+
have kids / baby sitter / grand parrents who might still be in your
118+
house that aren't represented by a trackable device in home
119+
assistant. This is providing a composite of wifi based device tracking
120+
and z-wave multisensor presence sensors.
121+
122+
```yaml
123+
binary_sensor:
124+
- platform: template
125+
sensors:
126+
people_home:
127+
value_template: >-
128+
{%- if is_state("device_tracker.sean", "home")
129+
or is_state("device_tracker.susan", "home")
130+
or is_state("binary_sensor.office_124", "on")
131+
or is_state("binary_sensor.hallway_134", "on")
132+
or is_state("binary_sensor.living_room_139", "on")
133+
or is_state("binary_sensor.porch_ms6_1_129", "on")
134+
or is_state("binary_sensor.family_room_144", "on")
135+
-%}
136+
True
137+
{%- else -%}
138+
False
139+
{%- endif %}
140+
entity_id:
141+
- device_tracker.sean
142+
- device_tracker.susan
143+
- binary_sensor.office_124
144+
- binary_sensor.hallway_134
145+
- binary_sensor.living_room_139
146+
- binary_sensor.porch_ms6_1_129
147+
- binary_sensor.family_room_144
108148
```

0 commit comments

Comments
 (0)