Platform Home Assistant "MQTT Binary Sensor”

3 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: low
Card revision: 1.2

The “MQTT Binary platform Sensor”, daughter of the "Binary Sensor” di Home Assistant, serves to define in configuration one or more binary sensors powered by MQTT telemetry procoming from one or more home automation devices.

In fact, they exist sensors binary (for binary means only two states, such as on / off, open / closed, etc.) that, if queried through MQTT, dispense the profirst state through i payload of the telemetric topics dedicated to this purpose. Furthermore, such telemetry is usually published automatically and / or cyclically via MQTT, allowing those who subscribe to these telemetric topics to obtain readings as they arrive.

An example of telemetric topic, in the case of a Sonoff RF Bridge updated to Tasmota is the following:


This topic returns via the proprio payload (or "payload") the readings of the sensor connected via radio to the unit:


Nb. To use this platform it is necessary that the "MQTT" component of Home Assistant has been previously configured (see first part of the card dedicated to the "MQTT" component). We also recommend to read carefully the guide dedicated to the theme of configuration of the MQTT components in the profirst home automation.


Basically a binary sensor configured via the MQTT Binary platform Sensor set the profirst state (on / off) by reading an MQTT message and two different payloads, all defined in configuration.

the configuration basis of any MQTT sensor in the file configuration.yaml it's pretty simple.
It is sufficient to insert an entry of this type:

  - platform: mqtt
    state_topic: "home-assistant/window/contact"

where the example of "home-assistant / window / contact”Will evidently be the telemetric topic of which to collect the payload for the extraction of the information of interest.

The variables available for configuration customization are the following:

state_topic(string, request) - The MQTT topic to which to register to receive telemetry
name(string, optional) - Name of the MQTT sensor. Default: "MQTT Binary Sensor”
qos(integer, optional) - The QoS level for the state_topic. Default: 0 (What is QoS?)
payload_on(string, optional) - The payload which, if received, sets the binary sensor to "on"
payload_off(string, optional) - The payload which, if received, sets the binary sensor to "off"
value_template(template, optional) - Defines the template for the extraction (parsing) of the data.
force_update(Boolean, optional) - Send to the automation engine of Home Assistant the Update Searchnameof value even if it did not actually happen. Useful to keep historians graphs constant. Default: false
availability_topic(string, optional) - Topic MQTT to which to register to get the device online / offline status. Usually the topic is indicated LWT.
payload_available(string, optional) - The payload that rappit returns the "available" status. Example: "online". It is used in abbinameto the variable "availability_topic". Usually a payload is indicated LWT.
payload_not_available(string, optional) - The payload that rappit returns the status "not available". Example: "offline". It is used in abbinameto the variable "availability_topic". Usually a payload is indicated LWT.
unique_id(string, optional) - An ID that uniquely identifies the sensor in terms of configuration. If two sensors have the same ID, Home Assistant raises an error exception.
device_class(device_class, optional) - The type / class of sensor useful for setting the correct, relative icon on the frontend of Home Assistant.



Let's consider using a Sonoff RF Bridge (updated Tastmota) coupled with an 433mhz radio magnetic sensor Sonoff DW1. This sensor sends, when opened, a radio signal containing a personal code; this signal and this personal code are intercepted by the RF Bridge which in turn reports it immediately afterwards in the payload of a MQTT telemetry.

Lo state_topic on which this information is published is the following:


A "typical" payload is similar to the following:


where the variable "Date"Contains, for theapptogether, the sensor code you are appena open ( "561691").

A binary sensor MQTT that provides home automation with contact opening information so it will be:

  - platform: mqtt
    name: "Contatto apertura finestra"
    payload_on: "561691"
    payload_off: ""
    device_class: opening
    state_topic: "tele/SonoffRFBridge/SENSOR"
    value_template: "{{ value_json.RfReceived.Data }}"}"

Nb. The example is carried out on a magnetic sensor that DOES NOT communicate the event of reclosing of the gap. Therefore, the field "payload_off”Is left intentionally empty and this case study will be managed with an automation Home Assistant ad hoc.


on inDomus there is a guide appdedicated to implementation of this platform.

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