mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-17 06:16:50 +00:00
Cleanup mqtt publish action template option documentation (#34257)
* Cleanup mqtt publish action template option documentation * Missed instance
This commit is contained in:
parent
ec46c4c74f
commit
eb55afff7b
@ -1085,11 +1085,7 @@ The MQTT integration will register the `mqtt.publish` action, which allows publi
|
|||||||
| `qos` | yes | Quality of Service to use. (default: 0) |
|
| `qos` | yes | Quality of Service to use. (default: 0) |
|
||||||
| `retain` | yes | If message should have the retain flag set. (default: false) |
|
| `retain` | yes | If message should have the retain flag set. (default: false) |
|
||||||
|
|
||||||
|
### Publish action data examples
|
||||||
{% important %}
|
|
||||||
You must include either `topic` or `topic_template`, but not both. If providing a payload, you need to include either `payload` or `payload_template`, but not both.
|
|
||||||
{% endimportant %}
|
|
||||||
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
topic: homeassistant/light/1/command
|
topic: homeassistant/light/1/command
|
||||||
@ -1100,7 +1096,7 @@ payload: on
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
topic: homeassistant/light/1/state
|
topic: homeassistant/light/1/state
|
||||||
payload_template: "{{ states('device_tracker.paulus') }}"
|
payload: "{{ states('device_tracker.paulus') }}"
|
||||||
```
|
```
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
@ -1108,27 +1104,24 @@ payload_template: "{{ states('device_tracker.paulus') }}"
|
|||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
topic_template: "homeassistant/light/{{ states('sensor.light_active') }}/state"
|
topic: "homeassistant/light/{{ states('sensor.light_active') }}/state"
|
||||||
payload_template: "{{ states('device_tracker.paulus') }}"
|
payload: "{{ states('device_tracker.paulus') }}"
|
||||||
```
|
```
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
|
|
||||||
`payload` must be a string.
|
Be aware that `payload` must be a string.
|
||||||
If you want to send JSON using the YAML editor then you need to format/escape
|
If you want to send JSON using the YAML editor then you need to format/escape
|
||||||
it properly. Like:
|
it properly. Like:
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
topic: homeassistant/light/1/state
|
topic: homeassistant/light/1/state
|
||||||
payload: "{\"Status\":\"off\", \"Data\":\"something\"}"`
|
payload: "{\"Status\":\"off\", \"Data\":\"something\"}"`
|
||||||
```
|
```
|
||||||
|
|
||||||
When using Home Assistant's YAML editor for formatting JSON
|
{% endraw %}
|
||||||
you should take special care if `payload` contains template content.
|
|
||||||
Home Assistant will force you in to the YAML editor and will treat your
|
|
||||||
definition as a template. Make sure you escape the template blocks as like
|
|
||||||
in the example below. Home Assistant will convert the result to a string
|
|
||||||
and will pass it to the MQTT publish action.
|
|
||||||
|
|
||||||
The example below shows how to publish a temperature sensor 'Bathroom Temperature'.
|
The example below shows how to publish a temperature sensor 'Bathroom Temperature'.
|
||||||
The `device_class` is set, so it is not needed to set the "name" option. The entity
|
The `device_class` is set, so it is not needed to set the "name" option. The entity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user