We've already shown you how to integrate Yoctopuce sensors in Home Assistant, by configuring a Yoctopuce hub to exchange data with an MQTT broker on the local network. But how do you go about integrating in Home Assistant sensors installed in another site without access to the local network, or even in the middle of nowhere with only a GSM connection?
Most IoT vendors solve this problem by offering a proprietary Cloud service to manage remote objects, and sometimes also a plug-in to integrate it into Home Assistant. The problem with this approach is that when the vendor shuts down or simply decides to abandon the product, the IoT device becomes completely unusable. This is what happened with Nest Revolv, SmartDry, and so on, and will happen again...
As you may have guessed, we don't like this solution. Instead, to manage your remote Yoctopuce modules, we've, for some time now, been providing a solution called VirtualHub (for Web), available free of charge with source code, which you can install on the web host of your choice. This allows you to maintain end-to-end control of your modules, with no time limit. The tool offers almost complete remote access to modules, with an interface very similar to that provided by live Yoctopuce modules.
However, as this solution is intended to be hosted on a public server on the Internet, it cannot connect directly to the MQTT server on your local network for integration in Home Assistant. That's where the new tool we're offering today comes in: Yoctopuce MqttBridge.
Our MqttBridge is a small tool you'll find on the tool page of our web site. It's designed to be installed on a machine on your local network, typically on the machine running the MQTT broker(mosquitto or similar). It's a command line tool and consumes very few resources. It is available for most platforms directly in binary form, but we also provide you with its source code (in pure C).
The principle of this tool is very simple: it connects via the Yoctopuce API to an instance of VirtualHub (for Web) and connects it to a local MQTT broker, exactly as a local YoctoHub or VirtualHub configured to make MQTT-type HTTP callbacks would have done:
Working principle of our MqttBridge tool
The topics used by MqttBridge are the same as those managed by Yoctopuce hubs, described in detail in this post. The informative MQTT discovery topics for direct integration in Home Assistant are of course included. As with the configuration on the hubs, you can choose which root topic to use to publish values, as well as deciding whether you want read-only access or whether you want to enable commands to be sent to the modules via MQTT (to switch relays, for example).
If you run the utility with the --help option, it provides you with all its options:
[--mqtt_port <port> | --mqtts_port <port>]
[--mqtt_user <username> --mqtt_pass <password>]
Special command-line options:
-c <conffile>: load config from JSON file to avoid long cmdline
(config file uses key names identical to the options listed above)
-g <logfile>: log debug infos into a <logfile>
-i : install as a service (with the arguments specified)
-u : uninstall as a service
-d : run as a daemon (when running as a service on Unix)
-v : show the version of the executable
To avoid a huge command line with passwords, we recommend using a separate configuration file. The configuration file uses the same keywords, but in JSON format:
The MqttBridge tool is based on our v2.0 programming library, and therefore supports TLS-secured connections, both for contacting VirtualHub (for Web) and for connecting to the MQTT server. However, in this case, you'll either need to provide the cacert option for certificates of authority to verify the identity of the servers, or set the ignore_cert option to disable certificate verification.
In addition to enabling the integration of remote Yoctopuce modules in Home Assistant, this new tool can naturally also be used with a local YoctoHub on which you have already configured another HTTP callback, for example to store data on an InfluxDB database. You now have the choice between an MQTT connection initiated entirely autonomously by the hub, or initiated by a machine on your local network.
Please note that as this is a brand-new tool, it's certainly not entirely free of bugs. Please feel free to report them to email@example.com, and we'll do our best to correct them as quickly as possible.