From b86529d8a2d1d27839fcf3469c2b53a6b405b715 Mon Sep 17 00:00:00 2001 From: Luca Angemi Date: Tue, 15 Oct 2019 12:25:13 +0200 Subject: [PATCH] Update service.markdown (#10790) * Update service.markdown notation changed to yaml * Update source/_docs/mqtt/service.markdown Co-Authored-By: Franck Nijhof * Update source/_docs/mqtt/service.markdown Co-Authored-By: Franck Nijhof --- source/_docs/mqtt/service.markdown | 36 ++++++++++++------------------ 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/source/_docs/mqtt/service.markdown b/source/_docs/mqtt/service.markdown index d714c1c12b3..5ad15fa9dbf 100644 --- a/source/_docs/mqtt/service.markdown +++ b/source/_docs/mqtt/service.markdown @@ -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. -```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 ```