home-assistant.io/source/_docs/mqtt/testing.markdown
Marley Jaffe ce4789b95f
Updated MQTT testing documentation (#14537)
Co-authored-by: Fabian Affolter <mail@fabian-affolter.ch>
2020-09-18 11:36:08 +02:00

1.6 KiB

title description logo
MQTT Testing Instructions on how to test your MQTT setup. mqtt.png

The mosquitto broker package ships commandline tools (often as *-clients package) to send and receive MQTT messages. As an alternative have a look at hbmqtt_pub and hbmqtt_sub which are provided by HBMQTT. For sending test messages to a broker running on localhost check the example below:

mosquitto_pub -h 127.0.0.1 -t home-assistant/switch/1/on -m "Switch is ON"

Another way to send MQTT messages manually is to use the "MQTT" Integration in the frontend. Choose the "Configuration" tab, click "Integrations" and click the "Configure" option under the "MQTT" integration. Enter something similar to the example below into the "topic" field under "Publish a packet*.

   home-assistant/switch/1/power

and in the Payload field

   ON

In the "Listen to a topic" field, type # to see everything, or "home-assistant/switch/#" to just follow the published topic. Press "Start Listening" and then press "Publish". The result should appear similar to the text below

Message 23 received on home-assistant/switch/1/power/stat/POWER at 12:16 PM:
ON
QoS: 0 - Retain: false
Message 22 received on home-assistant/switch/1/power/stat/RESULT at 12:16 PM:
{
    "POWER": "ON"
}
QoS: 0 - Retain: false

For reading all messages sent on the topic home-assistant to a broker running on localhost:

mosquitto_sub -h 127.0.0.1 -v -t "home-assistant/#"