Add examples for ESPEasy (#4527)

* Add sensor example

* Small changes

* Add ESPEasy example

* Add ESPEasy example

* Fixes

* ✏️ Minor improvements
This commit is contained in:
Fabian Affolter 2018-01-27 20:26:47 +01:00 committed by Franck Nijhof
parent 50e4cec1ff
commit a964ae5ac8
3 changed files with 98 additions and 8 deletions

View File

@ -13,12 +13,11 @@ ha_release: 0.9
ha_iot_class: "depends"
---
The `mqtt` binary sensor platform uses an MQTT message payload 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 `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.
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:
@ -78,6 +77,13 @@ value_template:
type: string
{% endconfiguration %}
## {% linkable_title Examples %}
In this section, you will find some real-life examples of how to use this sensor.
### {% linkable_title Full configuration %}
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
@ -86,6 +92,7 @@ $ mosquitto_pub -h 127.0.0.1 -t home-assistant/window/contact -m "OFF"
The example below shows a full configuration for a binary sensor:
{% raw %}
```yaml
# Example configuration.yaml entry
binary_sensor:
@ -99,5 +106,32 @@ binary_sensor:
payload_not_available: "offline"
qos: 0
device_class: opening
value_template: '{% raw %}{{ value.x }}{% endraw %}'
value_template: '{{ value.x }}'
```
{% endraw %}
### {% linkable_title Get the state of a device with ESPEasy %}
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.
As soon as the unit is online, you will get the state of the attached button.
```bash
home/bathroom/status Connected
...
home/bathroom/switch/button 1
```
The configuration will look like the example below:
{% raw %}
```yaml
# Example configuration.yml entry
binary_sensor:
- platform: mqtt
name: Bathroom
state_topic: "home/bathroom/switch/button"
payload_on: "1"
payload_off: "0"
```
{% endraw %}

View File

@ -90,8 +90,9 @@ If you are using the [Owntracks](/components/device_tracker.owntracks/) and enab
owntracks/tablet/tablet {"_type":"location","lon":7.21,"t":"u","batt":92,"tst":144995643,"tid":"ta","acc":27,"lat":46.12}
```
Thus the trick is extract the battery level from the payload.
Thus the trick is extracting the battery level from the payload.
{% raw %}
```yaml
# Example configuration.yml entry
sensor:
@ -99,8 +100,9 @@ sensor:
state_topic: "owntracks/tablet/tablet"
name: "Battery Tablet"
unit_of_measurement: "%"
value_template: {% raw %}'{{ value_json.batt }}'{% endraw %}
value_template: '{{ value_json.batt }}'
```
{% endraw %}
### {% linkable_title Get temperature and humidity %}
@ -116,6 +118,7 @@ office/sensor1
Then use this configuration example to extract the data from the payload:
{% raw %}
```yaml
# Example configuration.yml entry
sensor:
@ -123,10 +126,37 @@ sensor:
state_topic: 'office/sensor1'
name: 'Temperature'
unit_of_measurement: '°C'
value_template: {% raw %}'{{ value_json.temperature }}'{% endraw %}
value_template: '{{ value_json.temperature }}'
- platform: mqtt
state_topic: 'office/sensor1'
name: 'Humidity'
unit_of_measurement: '%'
value_template: {% raw %}'{{ value_json.humidity }}'{% endraw %}
value_template: '{{ value_json.humidity }}'
```
{% endraw %}
### {% linkable_title Get sensor value from a device with ESPEasy %}
Assuming that you have flashed your ESP8266 unit with [ESPEasy](https://github.com/letscontrolit/ESPEasy). Under "Config" set a name ("Unit Name:") for your device (here it's "bathroom"). 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 sensor in the "Devices" tap with the name "analog" and "brightness" as value.
As soon as the unit is online, you will get the state of the sensor.
```bash
home/bathroom/status Connected
...
home/bathroom/analog/brightness 290.00
```
The configuration will look like the example below:
{% raw %}
```yaml
# Example configuration.yml entry
sensor:
- platform: mqtt
state_topic: 'home/bathroom/analog/brightness'
name: Brightness
```
{% endraw %}

View File

@ -119,5 +119,31 @@ switch:
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 switch manually:
```bash
$ mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1 -m "ON"
$ mosquitto_pub -h 127.0.0.1 -t home/bedroom/switch1 -m "ON"
```
### {% linkable_title Set the state of a device with ESPEasy %}
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". There is no further configuration needed as the [GPIOs](https://www.letscontrolit.com/wiki/index.php/GPIO) can be controlled with MQTT directly.
Manually you can set pin 13 to high with `mosquitto_pub` or another MQTT tool:
```bash
$ mosquitto_pub -h 127.0.0.1 -t home/bathroom/gpio/13 -m "1"
```
The configuration will look like the example below:
{% raw %}
```yaml
# Example configuration.yml entry
switch:
- platform: mqtt
name: bathroom
state_topic: "home/bathroom/gpio/13"
command_topic: "home/bathroom/gpio/13"
payload_on: "1"
payload_off: "0"
```
{% endraw %}