- Using the Automation Editor, create a new automation.
- Switch the Automation Editor from Visual to YAML mode.
- Copy the following YAML and paste it over whatever is currently displayed in the editing window (i.e. overwrite the existing YAML).
alias: example
trigger:
- platform: state
entity_id: sensor.sonoff_1001392a8a_temperature
not_to:
- 'unavailable'
- 'unknown'
action:
- service: mqtt.publish
data:
topic: 'your/topic/goes/here'
payload: '{{ trigger.to_state.state }}'
mode: single
- In the
topic
option, replaceyour/topic/goes/here
with the topic you intend to use. - In the
alias
option, replace the word “example” with whatever you want to name this automation. - Click the Save button.
- Optionally switch back to Visual mode (to view the automation in that mode) or exit the Automation Editor. The automation is complete and functional.
Reference
You don’t.
The documentation is providing an example of how to publish a payload to a topic using a command-line application called mosquitto_pub
. It’s a completely separate application from Home Assistant.
I believe you would be better served by a visual application like MQTT Explorer. It’s an MQTT client that allows you to publish/subscribe to topics. It’s useful for debugging purposes such as confirming that the broker has received a payload published by an MQTT client like Home Assistant (or any other MQTT client). One of its features is the ability to display all of the topics that the broker knows about in a tree-view (makes it easier to understand).