Yoctopuce and Home Assistant

Yoctopuce and Home Assistant

Even if Yoctopuce devices are more often used for professional automation than for private home automation, we already had the opportunity to present you some home automation applications: a ventilation system to fight humidity, a system to optimize watering according to the weather, etc. So we decided to study the possibility of integrating the monitoring of these systems on a standard home automation console: Home Assistant.

Home Assistant


Home Assistant is a free and open software intended to be a central control system for all connected objects in a house. It allows to integrate quite easily a lot of sensors and home automation actuators, supporting thousands of different products. A host of developers have contributed to its expansion, adding support for new products as their personal needs arise, creating an extremely flexible ecosystem.

Rather than courting hardware manufacturers to adopt Home Assistant as the sole standard, as commercial proprietary systems tend to do, Home Assistant has chosen to implement as many interconnections as possible with existing open protocols. In particular, thanks to an excellent integration of MQTT, Home Assistant allows to finely integrate all systems based on this protocol.

MQTT


To make it simple, MQTT is a rather basic message exchange system using a central point of contact, the broker. But its use in home automation made the protocol evolve towards more and more descriptive structured messages, allowing a good coverage of all types of useful data. In particular, the appearance of gateways such as Zigbee2MQTT, capable of converting proprietary Zigbee messages into understandable MQTT messages, have made it an essential solution in home automation.

To make MQTT even easier to use, Home Assistant offers MQTT message senders the option of occasionally sending a special announcement message, which serves to describe the purpose and format of all messages they use. Thanks to this mechanism, called MQTT discovery, Home Assistant allows the user to see at a glance the detected connected objects, and to create appropriate user interfaces for these objects in a few clicks, without having to implement a specific extension for each hardware.

Home Assistant makes it easy to set up MQTT objects that implement the discovery protocol
Home Assistant makes it easy to set up MQTT objects that implement the discovery protocol


Other home automation systems such as openHAB have followed suit and recognize MQTT discovery messages coded according to the Home Assistant syntax.

Yoctopuce and Home Assistant


VirtualHub and Yoctopuce network interfaces (YoctoHub-Ethernet, YoctoHub-Wireless-n, etc.) have long had the ability to publish the status of all connected sensors and actuators to an MQTT broker. This is configured at the HTTP callback level, as documented in a previous article.

Configuration of the connection to an MQTT broker
Configuration of the connection to an MQTT broker


Today's news is that if you upgrade them to version 54000 or higher, they will now publish MQTT discovery messages allowing you to use them very easily with Home Assistant.

Yoctopuce devices now appear in the list of discovered MQTT objects
Yoctopuce devices now appear in the list of discovered MQTT objects


Clicking on a device provides its details and a link to add it to the dashboard
Clicking on a device provides its details and a link to add it to the dashboard



Installation and sample usage


If you did not yet install Home Assistant, you will find in the documentation several methods to choose from. We chose to install a brand new control machine, but since we intend to continue running our own automation scripts on that same machine, we opted for a standard Linux Mint image, and installed Home Assistant Container via Docker. The other essential components of the system (mosquitto, the MQTT broker, as well as zigbee2MQTT and Yoctopuce tools) were installed natively, because for these kind of simple little tools, Docker brings more trouble than benefits.

To test Home Assistant, we decided to see if it would indeed provide a good way to monitor our humidity control system that was set up almost ten years ago, and still works with the same Python script as originally. So we simply set up a callback on our VirtualHub to the MQTT broker, without changing anything else.

The result is quite nice. In a few clicks, we got the interface we wanted, without any effort:

It only took a few clicks to setup this monitoring dashboard
It only took a few clicks to setup this monitoring dashboard


The elements of the web interface reposition perfectly when accessed via WiFi from a cell phone. Clicking on any sensor even provides a graph of the measurement history:

Sensor history is readily available
Sensor history is readily available


Conclusion


The addition of MQTT discovery to Yoctopuce hubs will definitely simplify the use of Yoctopuce devices with Home Assistant. You can now add any kind of sensor (CO2, temperature, power, etc.) to your home automation system without any effort. We were impressed by the quality of the Home Assistant solution, which offered no difficulty to be configured and used even though we had never studied it before starting to work on this blog post.

An important detail to keep in mind: as it stands, the Yoctopuce MQTT integration only allows publishing values, but not changing the state of Yoctopuce devices. It is therefore perfect for measurement and monitoring, but not yet adequate for automation via MQTT. However, given the potential of this integration with Home Assistant, we might not stop there...




1 - fra Monday,april 17,2023 11H10

With my Yocto-VOC (last firmware and virtualhub on RPI), it's not working properly. Home Assistant receives MQTT messages every 1-2 seconds regardless of the interval set for callbacks. For now, I have implemented the sensor on Home Assistant with:
sensor:
- platform: rest
name: voc
resource: http://192.168.1.109:4444/bySerial/YVOCMK01-123/api/voc/currentValue
unit_of_measurement: "ppm"
scan_interval: 120

2 - mvuilleu (Yocto-Team)Monday,april 17,2023 15H35

@fra: the frequency set in the callback is not the reporting frequency, it is the reconnection delay. Once the MQTT connection is established, advertised values are published as soon as they change, and timed reports are published at the frequency individually set for each. The value offered in Home Assistant integration is the timed report, so you should set its frequency in the timed report configuration panel

3 - fra Friday,may 19,2023 19H37

I apologize for jumping to conclusions prematurely. I appreciate the clarification, and indeed, it is now functioning well.

4 - manu3b Thursday,december 28,2023 11H31

Looks promizing!
My Yocto sensor is connected directly to the Home Assistant Box.
My current basic solution is to install Yocto lib in Home Assistant OS, call it in a bash script, and declare in HA a
command_line sensor.
Now, the best would be to create an HA Add-on for the VirtualHUB:
https://developers.home-assistant.io/docs/add-ons/tutorial

5 - mvuilleu (Yocto-Team)Monday,january 08,2024 6H40

@manu3b That may be a good idea indeed, we will look at it

6 - chrisdu Friday,november 15,2024 18H48

I also have a big problem evaluating the temperatures of my 6 thermal modules in Home Assistant. I can see all the values ​​in the MQTT Explorer from the Home Assistant, but the value from "homeassistant/sensor/THRMCPL1-0B91C/temperature1" is a config"{
"uniq_id": "THRMCPL1-0B91C_temperature1_avg",
"name": "Schamott_oben",
"unit_of_meas": "'C",
"dev_cla": "temperature",
"~": "/THRMCPL1-0B91C/Schamott_oben",
"stat_t": "~/avg",
"object_id": "Schamott_oben",
"avty_mode": "all",
"avty": [
{
"t": "/THRMCPL1-0B91C/module/rdy",
"pl_avail": 1,
"pl_not_avail": 0
},
{
"t": "/ThermoGrill/module/rdy",
"pl_avail": 1,
"pl_not_avail": 0
}
],
"dev": {
"ids": "THRMCPL1-0B91C",
"name": "THRMCPL1-0B91C",
"mf": "Yoctopuce",
"mdl": "Yocto-Thermocouple",
"hw": "Rev. #1",
"sw": "54851",
"via_device": "VIRTHUB0-46b4647452",
"cu": "http://10.0.0.18:4444"
}
}"
what should I do with it?

the entities are not available in the MQTT plugin?!
I have already reinstalled the plugin and checked the connection to the MQTT broker. The entities are still not available.

thank you very much for your help
PS: is your plugin for the Home Assistant already available?
lg Christian

7 - mvuilleu (Yocto-Team)Friday,november 15,2024 20H40

@chrisdu: What you are looking at is not the sensor messages, but only Home Assistant discovery messages.

As you have not configured a "root topic" in the MQTT callback, Yoctopuce devices will appear at the root of MQTT tree (you can actually find the exact pat in the discovery messages listed).

If your device is not publishing live values, it is most probably because you did not activate timed reports in the device configuration. Look for the section named "Datalogger and timed reports" in the device configuration panel.

If the Yoctopuce devices do not appear in the list of MQTT devices, check your Home Assistant logs to see if there is anything abnormal.

Don't hesitate to contact Yoctopuce support directly by mail to get more help (support@yoctopuce.com)

8 - chrisdu Sunday,november 17,2024 14H59

Thank you very much for the quick reply. Your tip with the root topic was the clue. When I entered "homeassistant" under root topic (optional) in Virtualhub, I was able to receive the temperatures straight away.
lg

Yoctopuce, get your stuff connected.