MySensors

From Domoticz
Jump to: navigation, search

Introduction

MySensors.org [1] is an open source hardware and software community focusing on do-it-yourself home automation and Internet of Things. With their library you can create original and affordable sensors and actuators based on components like, Arduino, ESP8266, Raspberry Pi, NRF24L01+ and RFM69.

You'll need

  • Domoticz up and running (Domoticz supports MySensors on all operating system)
  • A MySensors gateway (more on this below)
  • A MySensors node (more on this below)
  • A MQTT broker (if you plan on using the MQTT-gateway)

Installing software

To install Domoticz, follow one the relevent guide for your operating system on Domoticz_Wiki_Manual.

MySensors hardware

A MySensors network consists of at least 2 parts, a Gateway and a sensor Node.

MySensors gateway

The MySensors Gateway acts as the glue between Domoticz and the MySensors radio network. It translates radio messages to a protocol which can be understood by Domoticz. You can build the gateway yourself using the same components as for the sensors. Currently MySensors has 3 different gateways, all are supported by Domoticz:

Only the MQTT-gateway requires extra software besides Domoticz: a MQTT broker. A serial-gateway is probably the easiest gateway to get started with.

MySensors node

MySensors supports a lot of different sensors and actuators. A list of examples can be found on their website [5]. For this tutorial we'll use the Air Humidity Sensors [6]. Don't power-up the node before the Gateway is powered up and Domoticz is configured, because the node needs to retrieve a Node-ID from Domoticz.

Connecting Domoticz to the Gateway

If you go to the Setup - Hardware in Domoticz and add new hardware you'll have 3 harware types with "MySensors" in the name, each corresponding to the 3 different MySensors gateways:

  • MySensors Gateway with USB (serial)
  • MySensors Gateway with LAN interface (Ethernet)
  • MySensors Gateway with MQTT interface (MQTT)

MySensors Gateway with USB (serial)

Connecting the serial gateway to Domoticz is the easiest. Since this gateway has an USB port, the only thing you need to do is plug the gateway into the machine you are running Domoticz on. Then in the Setup - Hardware fill in the COM-port that the gateway is using (on Windows it will usually be COM1). The baudrate will usually be 115200, unless you are using a Arduino Pro Mini running at 3.3V as a gateway, then it will be 38400 (these are the default values in the MySensors-library, you can change them yourself by setting MY_BAUD_RATE).

MySensors Gateway with LAN interface (Ethernet)

Connecting the ethernet gateway to Domoticz is almost as easy as connecting the serial gateway. The only difference between the two gateways is that the ethernet-gateway uses an IP-address instead of a COM-port. The IP-address the gateway uses can be assigned by your router (DHCP) or a static IP set in the sketch (using the MY_IP_ADDRESS define). The default port for the ethernet gateway is 5003 (but can also be changed in the sketch by setting the IP_PORT define).

MySensors Gateway with MQTT interface (MQTT)

The MQTT-gateway needs the most configuration to get up and running, but is also the most flexible once up and running.

Installing a MQTT-broker

First you need to install a piece of software, called a MQTT-broker. On Windows and the RaspberryPi the most popular choice is Mosquitto [7]. On their Wiki-page is an easy to follow installation guide [8]. If you are a bit more technical and already have Docker running, there is also a Docker image available [9].

Configuring the MQTT-gateway sketch

In the MQTT-gateway sketch, there are at lease 2 defines you need to change [10] before uploading the sketch to an Arduino or ESP8266. Those define the IP-address and port on which the MQTT-broker you just installed can be reached (MY_CONTROLLER_IP_ADDRESS and MY_PORT). If you changed the default broker configuration to require a username and password, you will also have to define those in the gateway-sketch (MY_MQTT_USER and MY_MQTT_PASSWORD). The final thing you can configure are the MQTT-topics that the gateway will publish messages on. By default these will be "mygateway1-out" and "mygateway1-in", but they can be changed using the defines MY_MQTT_PUBLISH_TOPIC_PREFIX and MY_MQTT_SUBSCRIBE_TOPIC_PREFIX. For Domoticz to work without additional software (like NodeRED), you will have to set MY_MQTT_PUBLISH_TOPIC_PREFIX to "domoticz/in/MyMQTT" and MY_MQTT_SUBSCRIBE_TOPIC_PREFIX to "domoticz/out/MyMQTT".

Configuring Domoticz to use the MQTT-gateway

Once the MQTT-gateway and broker are up and running, you will need to add the hardware to Domoticz. When you go to Setup - Hardware, you can add "MySensors Gateway with MQTT interface". In the "remote address" field you need to specify the IP-address of the MQTT-broker. In the port you will need to specify the MQTT-broker-port (usually 1883). If you have specified an username and password in the MQTT-broker, you can also specify them in Domoticz. The CA-filename is an advanced setting if you also require a certificate to communicate with your broker.

Adding a node to Domoticz

If you configured Domoticz correctly and it can talk to one of the MySensors gateways (check the Domoticz log), you are now ready to power-up your MySensors-node. Once the node starts up, it will connect to the gateway and ask for an Node-ID. The gateway will pass this request on to Domoticz and it will give the sensor a unique Node-ID.
To view all MySensors nodes, go to Setup - Hardware and click on the "setup" button in the grid
MySensors-Setup.png
This will show all MySensor-nodes and their connected sensors (childs)
MySensors-Nodes-View.png

The sensors will also automatically appear in the Device view (Setup - Devices). From the Devices view, you'll need to add the sensor to Domoticz by clicking the green "Add Device" arrow.
MySensors-TempHum-Devices.png

After this the temperature and humidity should be visible in the Temperature tab in Domoticz.
MySensors-TempHum-Node.png

Need more help

If you have any questions after this introduction to MySensors, take a look at the Domoticz forum. It has a sub-forum dedicated to MySensors [11]. The MySensors website also has forum with a specific topic about Domoticz [12] as a controller.