DIY Projects

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

sudo nano /home/homeassistant/.homeassistant/configuration.yaml

Otherwise, it is in your user folder

sudo nano /home/UTILISATEUR/.homeassistant/configuration.yaml

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

    - device: '/dev/ttyUSB0'
      persistence_file: 'path/mysensors.json'
      baud_rate: 38400
    - device: '/dev/ttyACM0'
      persistence_file: 'path/mysensors2.json'
      baud_rate: 115200
    - device: ''
      persistence_file: 'path/mysensors3.json'
      tcp_port: 5003
    - device: mqtt
      persistence_file: 'path/mysensors4.json'
      topic_in_prefix: 'mygateway1-out'
      topic_out_prefix: 'mygateway1-in'
  optimistic: false
  persistence: true
  retain: true
  version: 2.0

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:

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.

    device: ''
    persistence_file: '/home/homeassistant/.homeassistant/mysensors.json'
    tcp_port: 5003
  optimistic: false
  persistence: true
  retain: true
  version: 2.0
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.

  default: error
    mysensors: debug
    homeassistant.components.mysensors: debug

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

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.

sudo systemctl restart home-assistant@homeassistant

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

sudo journalctl -fu home-assistant@homeassistant

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

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

  name: Sondes d'humidité
    - sensor.humidity_158d000156cbfa
    - sensor.box_little_3_1
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.

  friendly_name: Temperature Extérieure
  friendly_name: Humidité Extérieure

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.

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version