I was surprised to see that GitHub - hivemq/hivemq-mqtt-web-client: A websockets based MQTT Client for your browser. doesn’t appear to have a current HA addon. While it was in an old unmaintained community addon, it wasn’t included in the official Mosquitto addon.
I also haven’t found a great MQTT client. The best so far is MQTT Explorer, though it has performance issues and isn’t available on iOS devices. But, I discovered that the docker container for the MQTT addon does include
mosquitto_sub. Let’s use that, and then we can access MQTT messages directly from any client with an SSH connection.
- Install GitHub - hassio-addons/addon-ssh: Advanced SSH & Web Terminal - Home Assistant Community Add-ons, disabling or uninstalling the built-in addon if you already have it enabled.
- Disable protection mode in the addon config. This allows the addon to access Docker containers… and well, everything. I find the convenience of being able to access docker easily without having to turn on HAOS debugging is completely worth it.
- Configure the SSH options, start it up and confirm you can ssh in.
- Save the following to
./mqtt_client.sh. I like to do
cat > mqtt-client.shand press
#!/bin/bash docker exec addon_core_mosquitto \ /bin/bash -c "mosquitto_sub -u addons -P \$(jq -r '.addons.password' < /data/system_user.json ) -F %j $*" \ | jq
chmod +x ./mqtt_client.shto make it executable.
If you’re curious, I named it
mqtt_client and not
mqtt_sub as a reminder that this is not the normal mqtt_sub binary.
- Automatically read the password saved into the addon for the mqtt server.
- Format results as JSON.
- Pass any additional mqtt_sub CLI parameters to the command.
- Pass the results through
jqfor pretty printing.
Then, pass other flags as needed to subscribe to messages. For example:
./mqtt_client.sh --topic 'rtl_433/+/events' --topic 'homeassistant/#'
One edge case; you may find you need to do additional escaping as compared to normal commands. For example,
--topic # needs to be
--topic \# because
# is interpreted as a comment.
I’m sure there’s better ways to escape these types of characters in the script, but for a short debugging tool that seems like overkill.
Hopefully this is useful to someone else!