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.
</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
```