Home | Difficulty level | Advanced | How to include MySensors v2 IoT objects in Home Assistant (HASS)

How to include MySensors v2 IoT objects in Home Assistant (HASS)

Connected objects developed using the MySensors library are very well supported by Home Assistant. In this tutorial, we will see how to integrate MySensors projects developed using version 2.x of the library. You can connect directly to a MySensors Gateway or an MQTT gateway. We will see how to do with the first solution. This tutorial works whatever platform is used to run the home automation server (Windows, MacOS, Linux and Raspberry).

Necessary material

If you’re new to Arduino-based or ESP8266-based object development using the MySensors library, here are some articles to get you started:

For this article, I used the temperature and humidity probe presented in this tutorial. It is about 50m from the gateway. It’s not very far, but there is a lot of vegetation. The gateway presented here is based on an ESP8266 (Wemos d1 mini). To increase reception range, I opted for a 6dBi antenna. The cable is long enough to fix it to the outside. To optimize transmission range, read this tutorial.

Add MySensors objects to the Home configurations

Since the MySensors library is natively supported, there is nothing to install. Integration will only consist of declaring the gateway and integrating the objects into the groups.

Open the configuration.yaml file. If you installed Home-Assistant in a virtual environment (recommended), run this command

Otherwise, it is in your user folder

The documentation presents all possible configuration types (all details here)

You can connect directly to a MySensors connected to the USB port (first 2 devices), a standard Gateway and finally an MQTT gateway.

The MySensors component offers several additional options regardless of which gateway you choose:

  • Optimistic (optional, false by default). Use this option for devices that do not return the output status. For example a switch. It is considered that it has changed state when pressed.
  • Persistence (optional): Enables or disables the recording of data in a local JSON file. It is not advisable to disable this option. If the persistence is disabled, the sensors must present themselves (see this tutorial for more information on the presentation) whenever sending data. That is not very practical.
  • Retain (optional): option for the MQTT gateway. Enables or disables the option to retain messages by the MQTT broker.
  • Version (optional): version of the library used. The MySensors API has evolved significantly since version 2.0 (technical documentation here). It is better to indicate the version used and if possible to standardize your code.

Here we will configure a TCP / IP gateway. It has the (fixed) IP address on the LAN. By default, the communication port is port 5003.

I recommend that you put the persistence file in the same directory as the configuration.

Enable Logger

During the debugging, it is preferable to activate the recording of messages by the integrated logger. Create a new logger section. It is possible to retrieve the messages from the components as well as the messages exchanged with the gateway.

The logger accepts several levels of severity. The debug mode is suitable in most cases:

  • critical
  • fatal
  • error
  • warning
  • warn
  • info
  • debug
  • notset
Warning. The Gateway constantly sends messages over the network. On a Raspberry Pi with limited power, performance will collapse. Activate the logger for focusing only.

Restart HASS

Restart Home Assistant. I recommend you restart the service from the interface by going to the Configuration panel for example or by executing this command.

Follow the launch to verify that HASS is properly connected to the gateway with this command

Configure the group

Now that HASS can connect to the gateway, all you have to do is add the devices to an existing group (or a new group). You should have passed the device IDs by following the service execution log. Fortunately, it is very easy to find the device name directly from the web interface.

Open the menu and click the <> icon to open the states panel. The devices start with the prefix sensor

home assistant mysensors device discover list

To add the sensors to an existing group, simply add it to the list of entities. Here is an example for moisture sensors.

It is possible to display only one sensor on a

Change view (customize.yaml file)

As for the previous tutorial, I advise you to separate the configuration in separate files for easier maintenance.

Open the customize.yaml file. For each sensor, create a label and add the friendly_name option to define the label that will be displayed on the screen.

Save and restart HASS

So, all MySensors objects have been properly integrated into the interface. You can also enjoy the measurement history.

In the next tutorial we will see how to include radio devices using the Open Source RFLink Gateway.