I’ve got a local MQTT server configured in HA for some random crap I’m doing. Tonight the need arose to get sensor data from a remote MQTT broker for power monitoring. Seems I cannot add a second MQTT broker easily. All I can find is some complicated solution where I must bridge MQTT or what not, isn’t there a simple way to just get sensor data from a remote MQTT broker? I feel all I find is waaaay too complicated for a single sensor solution?
You haven’t said what type of system you’re running, or which MQTT software you use, but it might be possible for you to make your own simple MQTT bridge by piping the output of an MQTT subscriber client into a publisher client. e.g. using the basic clients that come with Mosquitto, mosquitto_pub and mosquitto_sub, you can receive one topic and forward it on to another:
You’ll probably need to set extra parameters to set username, password, port, etc. for the two brokers, but running something like the above in the background should forward the subscribed topic from the remote broker onto your chosen topic on your local broker.
The main drawback of this approach is that although you use wildcards (# and +) to subscribe to remote multiple topics, they all get forwarded onto the same local topic. If you need to be able to tell multiple topics apart, you probably need to configure your local MQTT broker as a proper bridge.
Hi James… interested too in multiple brokers. I do bridge currently which although confusing at first works very well.
Are you saying that HA definitely can’t support dual/mutual brokers though as this was of interest to me too especially if trying to bring in a public brokers info ? I do agree bridging is probably the best option.
If I try to add extra broker lines in my configuration.yaml, HA logs a warning and only connects to the last broker I’ve listed. I can’t see any hint in the documentation or code that the MQTT integration is supposed to support more than one broker. Although I can’t think of a theoretical reason why one system ought not to be able to directly connect to more than one broker, I’m not familiar enough with the code to know how much effort it would take to make multiple brokers work.
Thanks for the idea. I ended up just giving up and looking into how to set up a bridge with my local MQTT server. It turned out only requiring an hour or two of work. Note irony. But it’s all working fine now and I guess with it all in place, that it’s a logical solution.
Still, I’d very much prefer having an ability to simply add a sensor in HA via a remote MQTT with simple means.