MQTT Client using the Advanced SSH & Web Terminal

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.

  1. 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.
  2. 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.
  3. Configure the SSH options, start it up and confirm you can ssh in.
  4. cd config
  5. Save the following to ./ I like to do cat > and press ctrl-d after pasting.

docker exec addon_core_mosquitto \
  /bin/bash -c "mosquitto_sub -u addons -P \$(jq -r '.addons.password' < /data/system_user.json ) -F %j $*" \ |
  1. chmod +x ./ to 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.

This will:

  1. Automatically read the password saved into the addon for the mqtt server.
  2. Format results as JSON.
  3. Pass any additional mqtt_sub CLI parameters to the command.
  4. Pass the results through jq for pretty printing.

Then, pass other flags as needed to subscribe to messages. For example:

 ./  --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!