Skip to content

Commit c752427

Browse files
grillpcgarwood
authored andcommitted
Added 'availability_template' to Template Binary Sensor platform (home-assistant#10313)
* Added 'availability_template' to all Template Binary Sensor platform * Fixed as requested. * Update source/_components/binary_sensor.template.markdown Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Added Accidentally remove d 'attribute_tempalte' * Removed optional parameter from example config
1 parent 822a45b commit c752427

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

source/_components/binary_sensor.template.markdown

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ other entities. The state of a Template Binary Sensor can only be `on` or
1818
Here is an example of adding a Template Binary Sensor to the `configuration.yaml` file:
1919

2020
{% raw %}
21+
2122
```yaml
2223
# Example configuration.yaml entry
2324
binary_sensor:
@@ -28,6 +29,7 @@ binary_sensor:
2829
value_template: >-
2930
{{ state_attr('sun.sun', 'elevation')|float > 0 }}
3031
```
32+
3133
{% endraw %}
3234
3335
{% configuration %}
@@ -58,6 +60,11 @@ sensors:
5860
description: The sensor is `on` if the template evaluates as `True` and `off` otherwise. The actual appearance in the frontend (`Open`/`Closed`, `Detected`/`Clear` etc) depends on the sensor’s device_class value
5961
required: true
6062
type: template
63+
availability_template:
64+
description: Defines a template to get the `available` state of the component. If the template returns `true`, the device is `available`. If the template returns any other value, the device will be `unavailable`. If `availability_template` is not configured, the component will always be `available`.
65+
required: false
66+
type: template
67+
default: true
6168
icon_template:
6269
description: Defines a template for the icon of the sensor.
6370
required: false
@@ -118,6 +125,7 @@ sensor of `furnace` that provides a current reading for the fan motor, we can
118125
determine if the furnace is running by checking that it is over some threshold:
119126

120127
{% raw %}
128+
121129
```yaml
122130
binary_sensor:
123131
- platform: template
@@ -127,6 +135,7 @@ binary_sensor:
127135
device_class: heat
128136
value_template: "{{ states('sensor.furnace')|float > 2.5 }}"
129137
```
138+
130139
{% endraw %}
131140

132141
### Switch as Sensor
@@ -137,6 +146,7 @@ original switch can then be hidden by
137146
[customizing](/getting-started/customizing-devices/).
138147

139148
{% raw %}
149+
140150
```yaml
141151
binary_sensor:
142152
- platform: template
@@ -148,6 +158,7 @@ binary_sensor:
148158
device_class: opening
149159
value_template: "{{ is_state('switch.door', 'on') }}"
150160
```
161+
151162
{% endraw %}
152163

153164
### Combining Multiple Sensors
@@ -157,6 +168,7 @@ status. When using templates with binary sensors, you need to return
157168
`true` or `false` explicitly.
158169

159170
{% raw %}
171+
160172
```yaml
161173
binary_sensor:
162174
- platform: template
@@ -169,6 +181,7 @@ binary_sensor:
169181
and is_state('sensor.kitchen_co_status', 'Ok')
170182
and is_state('sensor.wardrobe_co_status', 'Ok') }}
171183
```
184+
172185
{% endraw %}
173186

174187
### Washing Machine Running
@@ -180,6 +193,7 @@ finished. By utilizing `delay_off`, we can have this sensor only turn off if
180193
there has been no washer activity for 5 minutes.
181194

182195
{% raw %}
196+
183197
```yaml
184198
# Determine when the washing machine has a load running.
185199
binary_sensor:
@@ -192,9 +206,10 @@ binary_sensor:
192206
value_template: >-
193207
{{ states('sensor.washing_machine_power')|float > 0 }}
194208
```
209+
195210
{% endraw %}
196211

197-
### Is Anyone Home?
212+
### Is Anyone Home
198213

199214
This example is determining if anyone is home based on the combination of device
200215
tracking and motion sensors. It's extremely useful if you have kids/baby sitter/
@@ -203,6 +218,7 @@ trackable device in Home Assistant. This is providing a composite of WiFi based
203218
device tracking and Z-Wave multisensor presence sensors.
204219

205220
{% raw %}
221+
206222
```yaml
207223
binary_sensor:
208224
- platform: template
@@ -217,6 +233,7 @@ binary_sensor:
217233
or is_state('binary_sensor.porch_ms6_1_129', 'on')
218234
or is_state('binary_sensor.family_room_144', 'on') }}
219235
```
236+
220237
{% endraw %}
221238

222239
### Device Tracker sensor with Latitude and Longitude Attributes
@@ -251,11 +268,11 @@ binary_sensor:
251268
### Change the icon when state changes
252269

253270
This example demonstrates how to use `icon_template` to change the entity's
254-
icon as its state changes, it evaluates the state of its own sensor and uses a
255-
conditional statement to output the appropriate icon.
256-
271+
icon as its state changes, it evaluates the state of its own sensor and uses a
272+
conditional statement to output the appropriate icon.
257273

258274
{% raw %}
275+
259276
```yaml
260277
sun:
261278
binary_sensor:
@@ -273,4 +290,5 @@ binary_sensor:
273290
mdi:weather-sunset-down
274291
{% endif %}
275292
```
293+
276294
{% endraw %}

0 commit comments

Comments
 (0)