You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: source/_components/binary_sensor.template.markdown
+50-10Lines changed: 50 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -56,36 +56,40 @@ sensor:
56
56
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/)
57
57
58
58
```yaml
59
-
binary_sensor:
60
-
- platform: template
59
+
binary_sensor:
60
+
- platform: template
61
61
sensors:
62
62
movement:
63
63
value_template: {% raw %}"{{ states.switch.movement.state == 'on' }}"{% endraw %}
64
64
device_class: motion
65
65
door:
66
-
value_template: {% raw %}"{{ states.switch.door.state == 'on' }}"{% endraw %}
66
+
value_template: {% raw %}"{{ states.switch.door.state == 'on' }}"{% endraw %}
67
67
device_class: opening
68
68
```
69
69
70
70
71
71
### {% linkable_title Combining multiple sensors, and using entity_id: %}
72
72
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.
74
78
75
79
```yaml
76
-
binary_sensor:
77
-
- platform: template
80
+
binary_sensor:
81
+
- platform: template
78
82
sensors:
79
83
co:
80
84
friendly_name: 'CO'
81
85
device_class: 'gas'
82
86
value_template: {% raw %}>-
83
-
{%- if is_state("sensor.bedroom_co_status", "Ok")
87
+
{%- if is_state("sensor.bedroom_co_status", "Ok")
84
88
and is_state("sensor.kitchen_co_status", "Ok")
85
89
and is_state("sensor.wardrobe_co_status", "Ok") -%}
86
-
Off
90
+
False
87
91
{%- else -%}
88
-
On
92
+
True
89
93
{%- endif %}{% endraw %}
90
94
entity_id:
91
95
- sensor.bedroom_co_status
@@ -104,5 +108,41 @@ sensor:
104
108
friendly_name: 'Day/Night'
105
109
value_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}Day{% else %}Night{% endif %}'{% endraw %}
106
110
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")
0 commit comments