How do I use a read information from a secondary (same network) MQTT broker?

Hey guys. I have HASS OS running on a Raspberry Pi with a Sonoff Zigbee 3.0 dongle managing most of my devices

I also have another server on the local network that I want to track the outputs of various commands with, such as folder sizes/uptime/backup status etc.

This server is able to publish the required information via MQTT with mosquitto, and other devices on the network are able to subscribe to this information with mosquitto too. The output is:

{"backup_dir_size": "330M", "image_dir_size": "489G"}

However, I can’t find any information about how to connect HA to this other local machine to subscribe to its MQTT outputs

I’ve tried adding it to configuration.yaml, but I understand this is now depreciated and it should be done via UI, but the MQTT UI says I can’t configure more than one broker

I tried

mqtt:
  broker: 192.168.0.203
sensor:
  - platform: mqtt
    name: "Test sensor"
    state_topic: "shell_command_output" 

which doesn’t work… so I tried

mqtt:
  broker: 192.168.0.203
  sensor:
    - name: "MQTT_SHELL_SENSOR"
      state_topic: "shell_command_output"
      value_template: "{{ value_json.backup_dir_size }}"

which adds the sensor to HA, but it continually displays “Unknown” state, even after my broker on 192.168.0.203 publishes to the shell_command_output topic

Can anyone shed some light on my problem?

Thanks

You should probably look into bridging your two brokers.

Use the one connected to HA as the main and bridge the other one to the main one.

That way any topics should get transferred between the two brokers and all connected clients to either broker will see the same messages.

1 Like

@finity, thank you so much for pointing me in the right direction. It’s working now

I had to create another config file in /share/mosquitto/mynewconfig.conf containing:

connection [any_name_you_choose]
address 192.168.0.203 
topic shell_command_output in
topic shell_command_output out

then I restarted the MQTT integration in HA, and my custom MQTT sensor MQTT_SHELL_SENSOR was showing the correct value of 330M for backup_dir_size once the secondary broker had published it again

Thanks again for the pointer

1 Like