Fix platform

This commit is contained in:
Fabian Affolter 2018-12-30 22:06:54 +01:00
parent 011e423d2e
commit 572ff69932
No known key found for this signature in database
GPG Key ID: E23CD2DD36A4397F

View File

@ -13,28 +13,15 @@ ha_release: 0.9
ha_iot_class: "depends" ha_iot_class: "depends"
--- ---
The `mqtt` binary sensor platform uses an MQTT message payload The `mqtt` binary sensor platform uses an MQTT message payload to set the binary sensor to one of two states: `on` or `off`.
to set the binary sensor to one of two states: `on` or `off`.
The binary sensor state will be updated only after a new message is published on 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,
`state_topic` matching `payload_on` or `payload_off`. the binary sensor will receive an instant state update after subscription and Home Assistant will display the correct state on startup.
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`. Otherwise, the initial state displayed in Home Assistant will be `unknown`.
## {% linkable_title Configuration %} ## {% linkable_title Configuration %}
The `mqtt` binary sensor platform optionally supports an `availability_topic` to 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 sensor 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`
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. is defined, Home Assistant will consider the MQTT device to be available.
To use an MQTT binary sensor in your installation, To use an MQTT binary sensor in your installation,
@ -48,15 +35,15 @@ binary_sensor:
``` ```
{% configuration %} {% configuration %}
state_topic:
description: The MQTT topic subscribed to receive sensor values.
required: true
type: string
name: name:
description: The name of the binary sensor. description: The name of the binary sensor.
required: false required: false
type: string type: string
default: MQTT Binary Sensor default: MQTT Binary Sensor
state_topic:
description: The MQTT topic subscribed to receive sensor values.
required: true
type: string
payload_on: payload_on:
description: The payload that represents the on state. description: The payload that represents the on state.
required: false required: false
@ -68,11 +55,7 @@ payload_off:
type: string type: string
default: "OFF" default: "OFF"
availability_topic: availability_topic:
description: > description: "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."
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.
required: false required: false
type: string type: string
payload_available: payload_available:
@ -91,21 +74,15 @@ qos:
type: integer type: integer
default: 0 default: 0
unique_id: unique_id:
description: > description: An ID that uniquely identifies this sensor. If two sensors have the same unique ID, Home Assistant will raise an exception.
An ID that uniquely identifies this sensor. If two sensors have
the same unique ID, Home Assistant will raise an exception.
required: false required: false
type: string type: string
device_class: device_class:
description: > description: The [type/class](/components/binary_sensor/) of the sensor to set the icon in the frontend.
The [type/class](/components/binary_sensor/) of
the sensor to set the icon in the frontend.
required: false required: false
type: string type: string
value_template: value_template:
description: > description: Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
Defines a [template](/docs/configuration/templating/#processing-incoming-data)
to extract a value from the payload.
required: false required: false
type: string type: string
force_update: force_update:
@ -114,36 +91,36 @@ force_update:
type: boolean type: boolean
default: False default: False
off_delay: off_delay:
description: For sensors that only sends On state updates, this variable sets a delay in seconds after which the sensor state will be updated back to Off. description: "For sensors that only sends `On` state updates, this variable sets a delay in seconds after which the sensor state will be updated back to `Off`."
required: false required: false
type: integer type: integer
device: device:
description: 'Information about the device this binary sensor is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). Only works through [MQTT discovery](/docs/mqtt/discovery/) and when [`unique_id`](#unique_id) is set.' description: "Information about the device this binary sensor is a part of to tie it into the [device registry](https://developers.home-assistant.io/docs/en/device_registry_index.html). Only works through [MQTT discovery](/docs/mqtt/discovery/) and when [`unique_id`](#unique_id) is set."
required: false required: false
type: map type: map
keys: keys:
identifiers: identifiers:
description: 'A list of IDs that uniquely identify the device. For example a serial number.' description: A list of IDs that uniquely identify the device. For example a serial number.
required: false required: false
type: list, string type: list, string
connections: connections:
description: 'A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. For example the MAC address of a network interface: `"connections": [["mac", "02:5b:26:a8:dc:12"]]`.' description: "A list of connections of the device to the outside world as a list of tuples `[connection_type, connection_identifier]`. For example the MAC address of a network interface: `'connections': ['mac', '02:5b:26:a8:dc:12']`."
required: false required: false
type: list, tuple type: list, tuple
manufacturer: manufacturer:
description: 'The manufacturer of the device.' description: The manufacturer of the device.
required: false required: false
type: string type: string
model: model:
description: 'The model of the device.' description: The model of the device.
required: false required: false
type: string type: string
name: name:
description: 'The name of the device.' description: The name of the device.
required: false required: false
type: string type: string
sw_version: sw_version:
description: 'The firmware version of the device.' description: The firmware version of the device.
required: false required: false
type: string type: string
{% endconfiguration %} {% endconfiguration %}
@ -154,8 +131,8 @@ In this section, you will find some real-life examples of how to use this sensor
### {% linkable_title Full configuration %} ### {% linkable_title Full configuration %}
To test, you can use the command line tool `mosquitto_pub` shipped with To test, you can use the command line tool `mosquitto_pub` shipped with `mosquitto` or the `mosquitto-clients` package to send MQTT messages.
`mosquitto` or the `mosquitto-clients` package to send MQTT messages.
To set the state of the binary sensor manually: To set the state of the binary sensor manually:
```bash ```bash
@ -184,14 +161,7 @@ binary_sensor:
### {% linkable_title Get the state of a device with ESPEasy %} ### {% linkable_title Get the state of a device with ESPEasy %}
Assuming that you have flashed your ESP8266 unit with Assuming that you have flashed your ESP8266 unit with [ESPEasy](https://github.com/letscontrolit/ESPEasy). Under "Config" is a name ("Unit Name:") set for your device (here it's "bathroom"). A configuration for a "Controller" for MQTT with the protocol "OpenHAB MQTT" is present and the entries ("Controller Subscribe:" and "Controller Publish:") are adjusted to match your needs. In this example, the topics are prefixed with "home". Also, add a "Switch Input" in the "Devices" tap with the name "switch" and "button" as value.
[ESPEasy](https://github.com/letscontrolit/ESPEasy).
Under "Config" is a name ("Unit Name:") set for your device
(here it's "bathroom"). A configuration for a "Controller" for MQTT with the
protocol "OpenHAB MQTT" is present and the entries ("Controller Subscribe:" and
"Controller Publish:") are adjusted to match your needs.
In this example, the topics are prefixed with "home". Also, add a "Switch Input"
in the "Devices" tap with the name "switch" and "button" as value.
As soon as the unit is online, you will get the state of the attached button. As soon as the unit is online, you will get the state of the attached button.
@ -203,7 +173,6 @@ home/bathroom/switch/button 1
The configuration will look like the example below: The configuration will look like the example below:
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
binary_sensor: binary_sensor:
@ -213,4 +182,4 @@ binary_sensor:
payload_on: "1" payload_on: "1"
payload_off: "0" payload_off: "0"
``` ```
{% endraw %}