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:
Luca Angemi 2019-10-15 12:25:13 +02:00 committed by Franck Nijhof
parent e2896d30d0
commit b86529d8a2

View File

@ -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. You need to include either payload or payload_template, but not both.
</div> </div>
```json ```yaml
{ topic: home-assistant/light/1/command
"topic": "home-assistant/light/1/command", payload: on
"payload": "on"
}
``` ```
{% raw %} {% raw %}
```json ```yaml
{ topic: home-assistant/light/1/state
"topic": "home-assistant/light/1/state", payload_template: {{ states('device_tracker.paulus') }}
"payload_template": "{{ states('device_tracker.paulus') }}"
}
``` ```
{% endraw %} {% endraw %}
`payload` must be a string. If you want to send JSON then you need to format/escape it properly. Like: `payload` must be a string. If you want to send JSON then you need to format/escape it properly. Like:
```json ```yaml
{ topic: home-assistant/light/1/state
"topic": "home-assistant/light/1/state", payload: "{\"Status\":\"off\", \"Data\":\"something\"}"
"payload":"{\"Status\":\"off\", \"Data\":\"something\"}"
}
``` ```
Example of how to use `qos` and `retain`: Example of how to use `qos` and `retain`:
```json ```yaml
{ topic: home-assistant/light/1/command
"topic": "home-assistant/light/1/command", payload: on
"payload": "on", qos: 2
"qos": 2, retain: true
"retain": true
}
``` ```