mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-09 18:36:51 +00:00
Alternative for updating discovery examples (#28026)
* Alternative for updating discovery examples * tiny tweak --------- Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
parent
6ab52792cb
commit
d4f90d89f8
@ -565,16 +565,18 @@ A motion detection device which can be represented by a [binary sensor](/integra
|
||||
|
||||
- Configuration topic: `homeassistant/binary_sensor/garden/config`
|
||||
- State topic: `homeassistant/binary_sensor/garden/state`
|
||||
- Payload: `{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}`
|
||||
- Configuration payload: `{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state", "unique_id": "motion01ad", "device": {"identifiers": ["01ad"], "name": "Garden" }}`
|
||||
- Retain: The -r switch is added to retain the configuration topic in the broker. Without this, the sensor will not be available after Home Assistant restarts.
|
||||
|
||||
To create a new sensor manually.
|
||||
It is also a good idea to add a `unique_id` to allow changes to the entity and a `device` mapping so we can group all sensors of a device together.
|
||||
|
||||
To create a new sensor manually:
|
||||
|
||||
```bash
|
||||
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}'
|
||||
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state", "unique_id": "motion01ad", "device": {"identifiers": ["01ad"], "name": "Garden" }}'
|
||||
```
|
||||
|
||||
Update the state.
|
||||
Update the state:
|
||||
|
||||
```bash
|
||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/state" -m ON
|
||||
@ -593,9 +595,9 @@ For more details please refer to the [MQTT testing section](/integrations/mqtt/#
|
||||
Setting up a sensor with multiple measurement values requires multiple consecutive configuration topic submissions.
|
||||
|
||||
- Configuration topic no1: `homeassistant/sensor/sensorBedroomT/config`
|
||||
- Configuration payload no1: `{"device_class": "temperature", "name": "Temperature", "state_topic": "homeassistant/sensor/sensorBedroom/state", "unit_of_measurement": "°C", "value_template": "{% raw %}{{ value_json.temperature}}{% endraw %}" }`
|
||||
- Configuration payload no1: `{"device_class": "temperature", "name": "Temperature", "state_topic": "homeassistant/sensor/sensorBedroom/state", "unit_of_measurement": "°C", "value_template": "{% raw %}{{ value_json.temperature}}{% endraw %}","unique_id": "temp01ae", "device": {"identifiers": ["bedroom01ae"], "name": "Bedroom" }}`
|
||||
- Configuration topic no2: `homeassistant/sensor/sensorBedroomH/config`
|
||||
- Configuration payload no2: `{"device_class": "humidity", "name": "Humidity", "state_topic": "homeassistant/sensor/sensorBedroom/state", "unit_of_measurement": "%", "value_template": "{% raw %}{{ value_json.humidity}}{% endraw %}" }`
|
||||
- Configuration payload no2: `{"device_class": "humidity", "name": "Humidity", "state_topic": "homeassistant/sensor/sensorBedroom/state", "unit_of_measurement": "%", "value_template": "{% raw %}{{ value_json.humidity}}{% endraw %}","unique_id": "hum01ae", "device": {"identifiers": ["bedroom01ae"], "name": "Bedroom" } }`
|
||||
- Common state payload: `{ "temperature": 23.20, "humidity": 43.70 }`
|
||||
|
||||
#### Entities with command topics
|
||||
@ -605,15 +607,15 @@ Setting up a light, switch etc. is similar but requires a `command_topic` as men
|
||||
- Configuration topic: `homeassistant/switch/irrigation/config`
|
||||
- State topic: `homeassistant/switch/irrigation/state`
|
||||
- Command topic: `homeassistant/switch/irrigation/set`
|
||||
- Payload: `{"name": "garden", "command_topic": "homeassistant/switch/irrigation/set", "state_topic": "homeassistant/switch/irrigation/state"}`
|
||||
- Payload: `{"name": "Irrigation", "command_topic": "homeassistant/switch/irrigation/set", "state_topic": "homeassistant/switch/irrigation/state", "unique_id": "irr01ad", "device": {"identifiers": ["garden01ad"], "name": "Garden" }}`
|
||||
- Retain: The -r switch is added to retain the configuration topic in the broker. Without this, the sensor will not be available after Home Assistant restarts.
|
||||
|
||||
```bash
|
||||
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/switch/irrigation/config" \
|
||||
-m '{"name": "garden", "command_topic": "homeassistant/switch/irrigation/set", "state_topic": "homeassistant/switch/irrigation/state"}'
|
||||
-m '{"name": "garden", "command_topic": "homeassistant/switch/irrigation/set", "state_topic": "homeassistant/switch/irrigation/state", "unique_id": "irr01ad", "device": {"identifiers": ["garden01ad"], "name": "Garden" }}}'
|
||||
```
|
||||
|
||||
Set the state.
|
||||
Set the state:
|
||||
|
||||
```bash
|
||||
mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/switch/irrigation/set" -m ON
|
||||
@ -652,7 +654,6 @@ Setting up a [light that takes JSON payloads](/integrations/light.mqtt/#json-sch
|
||||
|
||||
#### Use object_id to influence the entity id
|
||||
|
||||
|
||||
The entity id is automatically generated from the entity's name. All MQTT integrations optionally support providing an `object_id` which will be used instead if provided.
|
||||
|
||||
- Configuration topic: `homeassistant/sensor/device1/config`
|
||||
|
Loading…
x
Reference in New Issue
Block a user