mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 09:17:06 +00:00
Update service.markdown (#10790)
* Update service.markdown notation changed to yaml * Update source/_docs/mqtt/service.markdown Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Update source/_docs/mqtt/service.markdown Co-Authored-By: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
e2896d30d0
commit
b86529d8a2
@ -20,38 +20,30 @@ The MQTT integration will register the service `mqtt.publish` which allows publi
|
||||
You need to include either payload or payload_template, but not both.
|
||||
</div>
|
||||
|
||||
```json
|
||||
{
|
||||
"topic": "home-assistant/light/1/command",
|
||||
"payload": "on"
|
||||
}
|
||||
```yaml
|
||||
topic: home-assistant/light/1/command
|
||||
payload: on
|
||||
```
|
||||
|
||||
{% raw %}
|
||||
```json
|
||||
{
|
||||
"topic": "home-assistant/light/1/state",
|
||||
"payload_template": "{{ states('device_tracker.paulus') }}"
|
||||
}
|
||||
```yaml
|
||||
topic: home-assistant/light/1/state
|
||||
payload_template: {{ states('device_tracker.paulus') }}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
`payload` must be a string. If you want to send JSON then you need to format/escape it properly. Like:
|
||||
|
||||
```json
|
||||
{
|
||||
"topic": "home-assistant/light/1/state",
|
||||
"payload":"{\"Status\":\"off\", \"Data\":\"something\"}"
|
||||
}
|
||||
```yaml
|
||||
topic: home-assistant/light/1/state
|
||||
payload: "{\"Status\":\"off\", \"Data\":\"something\"}"
|
||||
```
|
||||
|
||||
Example of how to use `qos` and `retain`:
|
||||
|
||||
```json
|
||||
{
|
||||
"topic": "home-assistant/light/1/command",
|
||||
"payload": "on",
|
||||
"qos": 2,
|
||||
"retain": true
|
||||
}
|
||||
```yaml
|
||||
topic: home-assistant/light/1/command
|
||||
payload: on
|
||||
qos: 2
|
||||
retain: true
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user