Added 'availability_template' to Template Binary Sensor platform (#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
This commit is contained in:
Gil Peeters 2019-09-28 21:57:25 +10:00 committed by Charles Garwood
parent 822a45b6d4
commit c752427e1b

View File

@ -18,6 +18,7 @@ other entities. The state of a Template Binary Sensor can only be `on` or
Here is an example of adding a Template Binary Sensor to the `configuration.yaml` file: Here is an example of adding a Template Binary Sensor to the `configuration.yaml` file:
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
binary_sensor: binary_sensor:
@ -28,6 +29,7 @@ binary_sensor:
value_template: >- value_template: >-
{{ state_attr('sun.sun', 'elevation')|float > 0 }} {{ state_attr('sun.sun', 'elevation')|float > 0 }}
``` ```
{% endraw %} {% endraw %}
{% configuration %} {% configuration %}
@ -58,6 +60,11 @@ sensors:
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 sensors device_class value 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 sensors device_class value
required: true required: true
type: template type: template
availability_template:
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`.
required: false
type: template
default: true
icon_template: icon_template:
description: Defines a template for the icon of the sensor. description: Defines a template for the icon of the sensor.
required: false required: false
@ -118,6 +125,7 @@ sensor of `furnace` that provides a current reading for the fan motor, we can
determine if the furnace is running by checking that it is over some threshold: determine if the furnace is running by checking that it is over some threshold:
{% raw %} {% raw %}
```yaml ```yaml
binary_sensor: binary_sensor:
- platform: template - platform: template
@ -127,6 +135,7 @@ binary_sensor:
device_class: heat device_class: heat
value_template: "{{ states('sensor.furnace')|float > 2.5 }}" value_template: "{{ states('sensor.furnace')|float > 2.5 }}"
``` ```
{% endraw %} {% endraw %}
### Switch as Sensor ### Switch as Sensor
@ -137,6 +146,7 @@ original switch can then be hidden by
[customizing](/getting-started/customizing-devices/). [customizing](/getting-started/customizing-devices/).
{% raw %} {% raw %}
```yaml ```yaml
binary_sensor: binary_sensor:
- platform: template - platform: template
@ -148,6 +158,7 @@ binary_sensor:
device_class: opening device_class: opening
value_template: "{{ is_state('switch.door', 'on') }}" value_template: "{{ is_state('switch.door', 'on') }}"
``` ```
{% endraw %} {% endraw %}
### Combining Multiple Sensors ### Combining Multiple Sensors
@ -157,6 +168,7 @@ status. When using templates with binary sensors, you need to return
`true` or `false` explicitly. `true` or `false` explicitly.
{% raw %} {% raw %}
```yaml ```yaml
binary_sensor: binary_sensor:
- platform: template - platform: template
@ -169,6 +181,7 @@ binary_sensor:
and is_state('sensor.kitchen_co_status', 'Ok') and is_state('sensor.kitchen_co_status', 'Ok')
and is_state('sensor.wardrobe_co_status', 'Ok') }} and is_state('sensor.wardrobe_co_status', 'Ok') }}
``` ```
{% endraw %} {% endraw %}
### Washing Machine Running ### Washing Machine Running
@ -180,6 +193,7 @@ finished. By utilizing `delay_off`, we can have this sensor only turn off if
there has been no washer activity for 5 minutes. there has been no washer activity for 5 minutes.
{% raw %} {% raw %}
```yaml ```yaml
# Determine when the washing machine has a load running. # Determine when the washing machine has a load running.
binary_sensor: binary_sensor:
@ -192,9 +206,10 @@ binary_sensor:
value_template: >- value_template: >-
{{ states('sensor.washing_machine_power')|float > 0 }} {{ states('sensor.washing_machine_power')|float > 0 }}
``` ```
{% endraw %} {% endraw %}
### Is Anyone Home? ### Is Anyone Home
This example is determining if anyone is home based on the combination of device This example is determining if anyone is home based on the combination of device
tracking and motion sensors. It's extremely useful if you have kids/baby sitter/ 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
device tracking and Z-Wave multisensor presence sensors. device tracking and Z-Wave multisensor presence sensors.
{% raw %} {% raw %}
```yaml ```yaml
binary_sensor: binary_sensor:
- platform: template - platform: template
@ -217,6 +233,7 @@ binary_sensor:
or is_state('binary_sensor.porch_ms6_1_129', 'on') or is_state('binary_sensor.porch_ms6_1_129', 'on')
or is_state('binary_sensor.family_room_144', 'on') }} or is_state('binary_sensor.family_room_144', 'on') }}
``` ```
{% endraw %} {% endraw %}
### Device Tracker sensor with Latitude and Longitude Attributes ### Device Tracker sensor with Latitude and Longitude Attributes
@ -251,11 +268,11 @@ binary_sensor:
### Change the icon when state changes ### Change the icon when state changes
This example demonstrates how to use `icon_template` to change the entity's This example demonstrates how to use `icon_template` to change the entity's
icon as its state changes, it evaluates the state of its own sensor and uses a icon as its state changes, it evaluates the state of its own sensor and uses a
conditional statement to output the appropriate icon. conditional statement to output the appropriate icon.
{% raw %} {% raw %}
```yaml ```yaml
sun: sun:
binary_sensor: binary_sensor:
@ -273,4 +290,5 @@ binary_sensor:
mdi:weather-sunset-down mdi:weather-sunset-down
{% endif %} {% endif %}
``` ```
{% endraw %} {% endraw %}