Platform Home Assistant "Binary Template Sensor”

1 minutes of reading
Proconductor: Home Assistant Community
Availability: included in thepersonale HUB Home Assistant
Category: software
Type: platform Home Assistant
Family: component "Binary Sensor” Home Assistant
Implementation difficulties: medium / low

The "Template Binary" platform Sensor”, daughter of the component "Binary Sensor"Of Home Assistant, it is useful to implement of binary sensors on a template basis.

These binary sensors change state from "off"Or"on”Based on the features set in the template that feeds them. This is a particularly useful platform when customizing the profirst configuration, to define states arising from others or groups from other states.

Considerations

START OF HOME ASSISTANT

If starting up Home Assistant one or more of the entities involved in the calculation of the status of a specific sensor “Binary Template Sensor"Should not be available yet, the sensor would take an" unknown "value and the frontend would return an error.

To avoid this, use the "is_state ()". For example, replacing

{{ states.switch.source.state == ‘on’ }}

with the counterpart

is_state ('switch.source', 'on')}}

since the latter always returns "true"Or"false", The" Binary Template Sensor"Can never be in state"unknown"

IDENTITY

We always recommend using an explicit list of IDs rather than grouping entities.

Examples

THRESHOLD SENSOR

Let's say we have an absorption sensor ("sensor.forno") And we assume that over a certain value (say 2,5 Watt) the appliance connected to it is considered operationalor. We can define a Binary Template Sensor that it becomes "on" when the absorption sensor exceeds the threshold:

binary_sensor:
  - platform: template
    sensors:
      forno_acceso:
        friendly_name: "Forno acceso"
        device_class: heat
        value_template: "{{ states('sensor.forno')|float > 2.5 }}"

TRANSFORMED SWITCH IN SENSOR

Some presence detection sensors are integrated on Home Assistant as switches (switches) instead of presence sensors. We define a sensor ("binary_sensor.apertura_porta") Which" converts "the state of the circuit-breaker into a binary sensor:

binary_sensor:
  - platform: template
    sensors:
      apertura_porta:
        device_class: motion
        value_template: "{{ is_state('switch.porta', 'on') }}"

IS THE WASHING MACHINE WASHING?

Well, more than an example, it is better to refer to prowhich illustrates how “deduce the status of a non-home automation appliance"


Home Assistant Official LogoATTENZIONE: remember that there is on our FORUM community an ad hoc section dedicated to Home Assistant, for any doubt, question, information on the specific merit of these components.


Please comment below