Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 3912824

Browse files
marthocfabaff
authored andcommitted
Add documentation for availability topic and payloads (home-assistant#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
1 parent d5a6b1b commit 3912824

File tree

2 files changed

+57
-37
lines changed

2 files changed

+57
-37
lines changed

source/_components/binary_sensor.mqtt.markdown

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ ha_iot_class: "depends"
1414
---
1515

1616

17-
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.
17+
The `mqtt` binary sensor platform uses an MQTT message payload to set the binary sensor to one of two states: `on` or `off`.
1818

19-
To use your MQTT binary sensor in your installation, add the following to your `configuration.yaml` file:
19+
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`.
20+
21+
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.
22+
23+
To use an MQTT binary sensor in your installation, add the following to your `configuration.yaml` file:
2024

2125
```yaml
2226
# Example configuration.yaml entry
@@ -27,32 +31,37 @@ binary_sensor:
2731
2832
Configuration variables:
2933
34+
- **name** (*Optional*): The name of the binary sensor. Default is `MQTT Binary Sensor`.
3035
- **state_topic** (*Required*): The MQTT topic subscribed to receive sensor values.
31-
- **name** (*Optional*): The name of the sensor. Default is 'MQTT Sensor'.
32-
- **qos** (*Optional*): The maximum QoS level of the state topic. Default is 0.
33-
- **payload_on** (*Optional*): The payload that represents on state. Default is "ON".
34-
- **payload_off** (*Optional*): The payload that represents state. Default is "OFF".
36+
- **payload_on** (*Optional*): The payload that represents the on state. Default is `ON`.
37+
- **payload_off** (*Optional*): The payload that represents the off state. Default is `OFF`.
38+
- **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.
39+
- **payload_available** (*Optional*): The payload that represents the online state. Default is `online`.
40+
- **payload_not_available** (*Optional*): The payload that represents the offline state. Default is `offline`.
41+
- **qos** (*Optional*): The maximum QoS level to be used when receiving messages. Default is `0`.
3542
- **device_class** (*Optional*): The [type/class](/components/binary_sensor/) of the sensor to set the icon in the frontend.
3643
- **value_template** (*Optional*): Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
3744

38-
For a quick check you can use the commandline tools shipped with `mosquitto` to send MQTT messages. Set the state of a sensor manually:
45+
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:
3946

4047
```bash
4148
$ mosquitto_pub -h 127.0.0.1 -t home-assistant/window/contact -m "OFF"
4249
```
4350

44-
An extended configuration for the same sensor could look like this if you want/need to be more specific.
51+
The example below shows a full configuration for a binary sensor:
4552

4653
```yaml
4754
# Example configuration.yaml entry
4855
binary_sensor:
4956
- platform: mqtt
57+
name: "Window Contact Sensor"
5058
state_topic: "home-assistant/window/contact"
51-
name: "Windows contact"
59+
payload_on: "ON"
60+
payload_off: "OFF"
61+
availability_topic: "home-assistant/window/availability"
62+
payload_available: "online"
63+
payload_not_available: "offline"
5264
qos: 0
53-
payload_on: "1"
54-
payload_off: "0"
5565
device_class: opening
5666
value_template: '{% raw %}{{ value.x }}{% endraw %}'
5767
```
58-

source/_components/cover.mqtt.markdown

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,44 @@ ha_iot_class: "depends"
1313
ha_release: 0.18
1414
---
1515

16-
The `mqtt` cover platform enables the possibility to control an MQTT cover. The device state will be updated only after receiving the a new
17-
state from `state_topic`. If these messages are published with `RETAIN` flag, the MQTT device will receive an instant state update after subscription and will start with correct state. Otherwise, the initial state will be `unknown`.
16+
The `mqtt` cover platform allows you to control an MQTT cover (such as blinds, a rollershutter, or a garage door).
1817

19-
There is a state attribute that stores the relative position of the device, where 0 means the device is `closed` and all other intermediate positions means the device is `open`.
18+
The device state (`open` or `closed`) will be updated only after a new message is published on `state_topic` matching `state_open` or `state_closed`. If these messages are published with the `retain` flag set, the cover 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`.
2019

21-
When a state topic is not available, the cover will work in optimistic mode. In this mode, the cover will immediately change state after every command. Otherwise, the cover will wait for state confirmation from device (message from `state_topic`).
20+
There is an attribute that stores the relative position of the device, where 0 means the device is `closed` and all other intermediate positions means the device is `open`.
2221

23-
Optimistic mode can be forced, even if `state_topic` is available. Try to enable it, if experiencing incorrect cover operation.
22+
If a state topic is not defined, the cover will work in optimistic mode. In this mode, the cover will immediately change state (`open` or `closed`) after every command sent by Home Assistant. If a state topic is defined, the cover will wait for a message on `state_topic` matching `state_open` or `state_closed` before changing state in Home Assistant.
23+
24+
Optimistic mode can be forced, even if a `state_topic` is defined. Try to enable it if experiencing incorrect cover operation.
25+
26+
The `mqtt` cover platform optionally supports an `availability_topic` to receive online and offline messages (birth and LWT messages) from the MQTT cover 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 cover as "unavailable". If these messages are published with the `retain` flag set, the cover will receive an instant update after subscription and Home Assistant will display correct availability state of the cover when Home Assistant starts up. If the `retain` flag is not set, Home Assistant will display the cover as "unavailable" when Home Assistant starts up.
2427

2528
To use your MQTT cover in your installation, add the following to your `configuration.yaml` file:
2629

2730
```yaml
28-
# Example configuration.yml entry
31+
# Example configuration.yaml entry
2932
cover:
3033
- platform: mqtt
3134
name: "MQTT Cover"
32-
state_topic: "home-assistant/cover"
3335
command_topic: "home-assistant/cover/set"
3436
```
3537
3638
Configuration variables:
3739
3840
- **name** (*Optional*): The name of the sensor. Default is `MQTT Cover`.
39-
- **state_topic** (*Optional*): The MQTT topic subscribed to receive sensor values.
40-
- **command_topic** (*Optional*): The MQTT topic to publish commands to control the rollershutter.
41+
- **command_topic** (*Optional*): The MQTT topic to publish commands to control the cover.
4142
- **payload_open** (*Optional*): The payload that opens the cover. Default is `OPEN`.
4243
- **payload_close** (*Optional*): The payload that closes the cover. Default is `CLOSE`.
43-
- **payload_stop** (*Optional*): The payload that stops the rollershutter. default is `STOP`.
44-
- **state_open** (*Optional*): The payload that represents open state. Default is `open`.
45-
- **state_closed** (*Optional*): The payload that represents closed state. Default is `closed`.
44+
- **payload_stop** (*Optional*): The payload that stops the cover. default is `STOP`.
45+
- **state_topic** (*Optional*): The MQTT topic subscribed to receive cover state messages.
46+
- **state_open** (*Optional*): The payload that represents the open state. Default is `open`.
47+
- **state_closed** (*Optional*): The payload that represents the closed state. Default is `closed`.
48+
- **availability_topic** (*Optional*): The MQTT topic subscribed to to receive birth and LWT messages from the MQTT cover device. If `availability_topic` is not defined, the cover availability state will always be "available". If `availability_topic` is defined, the cover availability state will be "unavailable" by default.
49+
- **payload_available** (*Optional*): The payload that represents the online state. Default is `online`.
50+
- **payload_not_available** (*Optional*): The payload that represents the offline state. Default is `offline`.
4651
- **optimistic** (*Optional*): Flag that defines if switch works in optimistic mode. Default is `true` if no state topic defined, else `false`.
47-
- **qos** (*Optional*): The maximum QoS level of the state topic. Default is `0`. Will also be used when publishing messages.
48-
- **retain** (*Optional*): If the published message should have the retain flag on or not. Default is `false`.
52+
- **qos** (*Optional*): The maximum QoS level to be used when receiving and publishing messages. Default is `0`.
53+
- **retain** (*Optional*): Defines if published messages should have the retain flag set. Default is `false`.
4954
- **value_template** (*Optional*): Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
5055
- **set_position_topic** (*Optional*): The MQTT topic to publish position commands to.
5156
- **set_position_template** (*Optional*): Defines a [template](/topics/templating/) to define the position to be sent to the `set_position_topic` topic. Incoming position value is available for use in the template `{{position}}`. If no template is defined, the numeric position (0-100) will be written directly to the topic.
@@ -60,7 +65,7 @@ Configuration variables:
6065

6166
## {% linkable_title Examples %}
6267

63-
In this section you find some real life examples of how to use this sensor.
68+
In this section you find some real life examples of how to use this platform.
6469

6570
### {% linkable_title Full configuration without tilt %}
6671

@@ -70,16 +75,19 @@ The example below shows a full configuration for a cover without tilt.
7075
# Example configuration.yml entry
7176
cover:
7277
- platform: mqtt
73-
state_topic: "home-assistant/cover"
74-
command_topic: "home-assistant/cover/set"
7578
name: "MQTT Cover"
79+
command_topic: "home-assistant/cover/set"
80+
state_topic: "home-assistant/cover/state"
81+
availability_topic: "home-assistant/cover/availability"
7682
qos: 0
7783
retain: true
7884
payload_open: "OPEN"
7985
payload_close: "CLOSE"
8086
payload_stop: "STOP"
81-
state_open: "OPEN"
82-
state_closed: "STATE"
87+
state_open: "open"
88+
state_closed: "closed"
89+
payload_available: "online"
90+
payload_not_available: "offline"
8391
optimistic: false
8492
value_template: '{% raw %}{{ value.x }}{% endraw %}'
8593
```
@@ -92,27 +100,30 @@ The example below shows a full configuration for a cover.
92100
# Example configuration.yml entry
93101
cover:
94102
- platform: mqtt
95-
state_topic: "home-assistant/cover"
96-
command_topic: "home-assistant/cover/set"
97103
name: "MQTT Cover"
104+
command_topic: "home-assistant/cover/set"
105+
state_topic: "home-assistant/cover/state"
106+
availability_topic: "home-assistant/cover/availability"
98107
qos: 0
99108
retain: true
100109
payload_open: "OPEN"
101110
payload_close: "CLOSE"
102111
payload_stop: "STOP"
103-
state_open: "OPEN"
104-
state_closed: "STATE"
112+
state_open: "open"
113+
state_closed: "closed"
114+
payload_available: "online"
115+
payload_not_available: "offline"
105116
optimistic: false
106117
value_template: '{% raw %}{{ value.x }}{% endraw %}'
107118
tilt_command_topic: 'home-assistant/cover/tilt'
108-
tilt_status_topic: 'home-assistant/cover/tilt-status'
119+
tilt_status_topic: 'home-assistant/cover/tilt-state'
109120
tilt_min: 0
110121
tilt_max: 180
111122
tilt_closed_value: 70
112123
tilt_opened_value: 180
113124
```
114125

115-
For a check you can use the command line tools `mosquitto_pub` shipped with `mosquitto` to send MQTT messages. This allows you to operate your cover manually:
126+
To test, you can use the command line tool `mosquitto_pub` shipped with `mosquitto` or the `mosquitto-clients` package to send MQTT messages. This allows you to operate your cover manually:
116127

117128
```bash
118129
$ mosquitto_pub -h 127.0.0.1 -t home-assistant/cover/set -m "CLOSE"

0 commit comments

Comments
 (0)