Add documentation for availability topic and payloads (#3378)

* Add documentation for availability topic and payloads

Added documentation for availabiltiy topic and payloads added in a pull request. Also cleaned up documentation for the MQTT cover generally to make clear the differences between state topic and messages and availability topic and messages.

* Add default qos level

* Add documentation for availability topic and payloads

Added documentation for availability topic and payloads added to the MQTT binary sensor in a pull request. Also cleaned up documentation for the MQTT binary sensor generally.

* Remove sending
This commit is contained in:
marthoc 2017-09-25 13:41:57 -04:00 committed by Fabian Affolter
parent d5a6b1bd14
commit 39128242c9
2 changed files with 57 additions and 37 deletions

View file

@ -14,9 +14,13 @@ ha_iot_class: "depends"
---
The `mqtt` binary sensor platform uses the MQTT message payload as the sensor value. If messages in this `state_topic` are published with *RETAIN* flag, the sensor will receive an instant update with the last known value. Otherwise, the initial state will be off.
The `mqtt` binary sensor platform uses an MQTT message payload to set the binary sensor to one of two states: `on` or `off`.
To use your MQTT binary sensor in your installation, add the following to your `configuration.yaml` file:
The binary sensor state will be updated only after a new message is published on `state_topic` matching `payload_on` or `payload_off`. If these messages are published with the `retain` flag set, the binary sensor will receive an instant state update after subscription and Home Assistant will display the correct state on startup. Otherwise, the initial state displayed in Home Assistant will be `unknown`.
The `mqtt` binary sensor platform optionally supports an `availability_topic` to receive online and offline messages (birth and LWT messages) from the MQTT device. During normal operation, if the MQTT cover device goes offline (i.e. publishes `payload_not_available` to `availability_topic`), Home Assistant will display the binary sensor as `unavailable`. If these messages are published with the `retain` flag set, the binary sensor will receive an instant update after subscription and Home Assistant will display the correct availability state of the binary sensor when Home Assistant starts up. If the `retain` flag is not set, Home Assistant will display the binary sensor as `unavailable` when Home Assistant starts up. If no `availability_topic` is defined, Home Assistant will consider the MQTT device to be available.
To use an MQTT binary sensor in your installation, add the following to your `configuration.yaml` file:
```yaml
# Example configuration.yaml entry
@ -27,32 +31,37 @@ binary_sensor:
Configuration variables:
- **name** (*Optional*): The name of the binary sensor. Default is `MQTT Binary Sensor`.
- **state_topic** (*Required*): The MQTT topic subscribed to receive sensor values.
- **name** (*Optional*): The name of the sensor. Default is 'MQTT Sensor'.
- **qos** (*Optional*): The maximum QoS level of the state topic. Default is 0.
- **payload_on** (*Optional*): The payload that represents on state. Default is "ON".
- **payload_off** (*Optional*): The payload that represents state. Default is "OFF".
- **payload_on** (*Optional*): The payload that represents the on state. Default is `ON`.
- **payload_off** (*Optional*): The payload that represents the off state. Default is `OFF`.
- **availability_topic** (*Optional*): The MQTT topic subscribed to receive birth and LWT messages from the MQTT device. If `availability_topic` is not defined, the binary sensor availability state will always be `available`. If `availability_topic` is defined, the binary sensor availability state will be `unavailable` by default.
- **payload_available** (*Optional*): The payload that represents the online state. Default is `online`.
- **payload_not_available** (*Optional*): The payload that represents the offline state. Default is `offline`.
- **qos** (*Optional*): The maximum QoS level to be used when receiving messages. Default is `0`.
- **device_class** (*Optional*): The [type/class](/components/binary_sensor/) of the sensor to set the icon in the frontend.
- **value_template** (*Optional*): Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
For a quick check you can use the commandline tools shipped with `mosquitto` to send MQTT messages. Set the state of a sensor manually:
To test, you can use the command line tool `mosquitto_pub` shipped with `mosquitto` or the `mosquitto-clients` package to send MQTT messages. To set the state of the binary sensor manually:
```bash
$ mosquitto_pub -h 127.0.0.1 -t home-assistant/window/contact -m "OFF"
```
An extended configuration for the same sensor could look like this if you want/need to be more specific.
The example below shows a full configuration for a binary sensor:
```yaml
# Example configuration.yaml entry
binary_sensor:
- platform: mqtt
name: "Window Contact Sensor"
state_topic: "home-assistant/window/contact"
name: "Windows contact"
payload_on: "ON"
payload_off: "OFF"
availability_topic: "home-assistant/window/availability"
payload_available: "online"
payload_not_available: "offline"
qos: 0
payload_on: "1"
payload_off: "0"
device_class: opening
value_template: '{% raw %}{{ value.x }}{% endraw %}'
```