Skip to content

Commit f45ea82

Browse files
authored
Add switch example and list of supported devices (home-assistant#2312)
1 parent 3e06754 commit f45ea82

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

source/_docs/mqtt/discovery.markdown

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ logo: mqtt.png
1111
redirect_from: /components/mqtt/#discovery
1212
---
1313

14-
The discovery of MQTT devices will enable one to use MQTT devices with only minimal configuration effort on the side of Home Assistant. The configuration is done on the device itself and the topic used by the device. Similar to the [HTTP binary sensor](/components/binary_sensor.http/) and the [HTTP sensor](/components/sensor.http/). Currently, binary sensors, lights and sensors are supported. A discovery binary sensor or sensor will load the `mqtt` platform. For discovered light components the JSON payload can contain a `platform` attribute with one of `mqtt`, `mqtt_json` or `mqtt_template` defined. If no `platform` attribute is defined then `mqtt` is used.
14+
The discovery of MQTT devices will enable one to use MQTT devices with only minimal configuration effort on the side of Home Assistant. The configuration is done on the device itself and the topic used by the device. Similar to the [HTTP binary sensor](/components/binary_sensor.http/) and the [HTTP sensor](/components/sensor.http/).
15+
16+
Supported by MQTT discovery:
17+
18+
- [Binary sensors](/components/binary_sensor.mqtt/)
19+
- [Lights](/components/light.mqtt/)
20+
- [Sensors](/components/sensor.mqtt/)
21+
- [Switches](/components/switch.mqtt/)
22+
1523

1624
To enable MQTT discovery, add the following to your `configuration.yaml` file:
1725

@@ -34,13 +42,13 @@ The discovery topic need to follow a specific format:
3442

3543
- `<component>`: One of the supported components, eg. `binary_sensor`.
3644
- `<object_id>`: The ID of the device. This will become the `entity_id` in Home Assistant.
37-
- `<config>`: The topic `config` or `state` which defines the current action.
45+
- `<>`: The topic `config` or `state` which defines the current action.
3846

39-
The payload will be checked like an entry in your `configuration.yaml` file if a new device is added. This means that missing variables will be filled with the platform's default values.
47+
The payload will be checked like an entry in your `configuration.yaml` file if a new device is added. This means that missing variables will be filled with the platform's default values. All configuration variables which are *required* must be present in the initial payload send to `/config`.
4048

41-
### {% linkable_title Example %}
49+
### {% linkable_title Examples %}
4250

43-
A motion detection device which can be represented by a [binary sensor](/components/binary_sensor.mqtt/) for your garden would sent its configuration as JSON payload to the Configuration topic. After the first message to `config`, then the MQTT messages sent to the State topic will update the state in Home Assistant.
51+
A motion detection device which can be represented by a [binary sensor](/components/binary_sensor.mqtt/) for your garden would sent its configuration as JSON payload to the Configuration topic. After the first message to `config`, then the MQTT messages sent to the state topic will update the state in Home Assistant.
4452

4553
- Configuration topic: `homeassistant/binary_sensor/garden/config`
4654
- State topic: `homeassistant/binary_sensor/garden/state`
@@ -57,3 +65,18 @@ Update the state.
5765
$ mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/state" -m ON
5866
```
5967

68+
Setting up a switch is similar but requires a `command_topic` as mentionend in the [MQTT switch documentation](/components/switch.mqtt/).
69+
70+
- Configuration topic: `homeassistant/switch/irrigation/config`
71+
- State topic: `homeassistant/switch/irrigation/state`
72+
- Payload: `{"name": "garden", "command_topic": "homeassistant/switch/irrigation/set"}`
73+
74+
```bash
75+
$ mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/switch/irrigation/config" \
76+
-m '{"name": "garden", "command_topic": "homeassistant/switch/irrigation/set"}'
77+
```
78+
Set the state.
79+
80+
```bash
81+
$ mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/switch/irrigation/set" -m ON
82+
```

0 commit comments

Comments
 (0)