MySensors v2 - ESP8266 WiFi Gateway with Domoticz [Full Guide]

We continue the series of items on the library MySensors v2.In this article we will learn how to make a WiFi Gateway based on ESP8266 a unit and connect it to Domoticz. The ESP8266 modules are supported since version 1.5 through the work of Yveaux . You can follow discussions on the subject here .

In this article, we will build the WiFi gateway with a nRF24L01 radio module. It will serve us for a later tutorial.

List of materials

No special specifications exists. Probably you can use one ESP-01 module goal i have not tried. I advice you to take one ESP-12 with a usb connector. It is Easier to program and not much more expensive. For this article i have used Wemos D1 Mini .

ThenRF24L01 are not consistent with our breadboard. So, you can use a socket adapter plate to wire the nRF24L01 module. This socket integrate a power regulator to Reduce from 5V to 3.3V.


The system is easy. If you do not-have a 3.3V (or the power if bad), you can use a step down power supply module (from 5V).

Gateway Wifi ESP8266 + reed switch jeedom domoticz mqtt

Programming: what gateway choose

There are two kinds of ESP8266 Gateway:

  • The Network Gateway. The Gateway will be available from ict IP address. The default Port is 5003. The home servers compliant with MySensors library will be ble to communiquer Then with objects connected to the network MySensors.

  • Customer MQTT. The Gateway Enables communication via a MQTT server (broker). The exchanges are bidirectional. Choose this solution if you home automation software (for example) is not consistent with MySensors.

In the examples, you will find an OTA Gateway aussi That allows the update “in the air” program. I have not tried yet.

The choice is easy quite, if you Plan to integrate connected objects MySensors was home automation server That Provides a dedicated plugin (it works and take into account the functions of MySensors you need) , build a Network Gateway, Otherwise opt for the customer MQTT

Prepare the gateway program

mysensors arduino gateway mqtt client

Open the gateway program. Examples -> MySensors -> GatewayESP8266 gold ESP8266MQTTClient


  • Modify your SSID and wireless password ( MY_ESP8266_SSID, MY_ESP8266_PASSWORD)

  • Set.. a static ip, MY_IP_ADDRESS (if you want). In this case, you need to set the DHCP address (MY_IP_GATEWAY_ADDRESS, MY_IP_SUBNET_ADDRESS).

That’s all

mysensors v2 arduino gateway ip static

If you build a MQTT Client Gateway

  • Uncomment and modify the address of your MQTT broker

  • If you want, you can modify the prefix of the in / out topics

Copy this code inside the gateway.

 #include #include #define CHILD_ID_CONTACTEUR 0#define CONTACTEUR_PIN D3 // Reed switch PinetatPrecedent boolean = false; // Previous stateMyMessage msgContacteur (CHILD_ID_CONTACTEUR, V_TRIPPED);void setup ()   pinMode (CONTACTEUR_PIN, INPUT);  digitalWrite (CONTACTEUR_PIN, HIGH);void presentation ()   sendSketchInfo ( "Reed Switch Test", "1.0");  present (CHILD_ID_CONTACTEUR, S_DOOR);void loop ()   uint8_t state;  // Read the state of the reed switch  state = digitalRead (CONTACTEUR_PIN);  if (state! = etatPrecedent)     etatPrecedent = state;      Serial.print ( "Switch state");    Serial.println (state "Open", "Close"?);    send (msgContacteur.set (state "1": "0")?);    delay (50); 

Some Explanations.

We define a child for the node (the gateway node has est.)


Reed switch is connected to the pin and D3 to ground (G)


a boolean variable will test the previous state and send a MQTT messages in case of change of the switch state.

 etatPrecedent boolean = false; 

We create a MyMessage object with V_TRIPPED kind

 MyMessage msgContacteur (CHILD_ID_CONTACTEUR, V_TRIPPED) 

Now, we present the sensor

 void presentation ()   sendSketchInfo ( "Reed Switch Test", "1.0");  present (CHILD_ID_CONTACTEUR, S_DOOR); 

The loop runs every 50ms. Send the value only if the reed switch changes state

 send (msgContacteur.set (state "1": "0")?) 

Domoticz Version used for this article. v3.4834

To add the Gateway, go into the settings and equipment. In the list, select Gateway MySensors with Lan interface.

domoticz mysensor ajout choix gateway

Fill in the IP address (static IP is better) and the port (5003 by default). Save.

2. domoticz mysensor ajout gateway esp8266

Click Settings and wait at least one minute. Domoticz need this time to collect data and childs.

3. domoticz mysensor ajout dispositifs noeuds et fils

Add a device

4. domoticz mysensor ajout appareil

When Domoticz can make mistakes When It create devices (probably because i use the version 2). It is not significant, we will exchange That after.

Click the blue arrow and write a name for this device.

5. Domoticz ajout dispositif

Go to switches

6. Domoticz dispositif mysensors

Click Edit . In the switch choose the type Door Lock and save.
7. Domoticz changement type interrupteur
Click the star if you want to add this device on the dashboard.

8. Domoticz dispositif mysensors configuré

No comments:

Powered by Blogger.