lundi 17 avril 2017

ESP Easy + Domoticz

Now that we have our NodeMCU flashed with ESP Easy, and wired with the DHT11 sensor, let 's make the configuration to handle the data with Domoticz.

Open the Domoticz web interface, click on Setup and then Hardware.
Name: choose a name for the hardware we want to add, "Sensors module" in my case.
Type: choose "Dummy, does nothing, uses for virtual switches only"
Then click Add.




The hardware should then appear on the top. Click on "Create virtual sensor".
Provide a name to the virtual sensor, and select the sensor type: "Temp+Hum" and press OK.

Now, if you click on Setup and then Devices, you should see something like this:



From there, you see which IDX number we have to provide into ESP Easy. If it is the first object that you add in Domoticz, this IDX should be 1.

Now, go back into the ESP Easy web interface, and change the IDX number of your sensor device, to match with Domoticz.
Within about a minute, you should see the first value appearing on Domoticz. You need to click on Temperature.



It works! We now have a link between NoceMCU and Domoticz. It is as simple as that!

ESP EASY firmware test

Because it is compatible with many sensors and with many home automation systems, I have decided to use ESP Easy firmware.

More info can be found at: https://www.letscontrolit.com/wiki/index.php/ESPEasy

First, I will use a NodeMCU clone as a try, so we can test a sensor with it, and configure the ESP to send the sensor value to Domoticz. Then, later on, I will replace the NodeMCU by a raw ESP12E.

ESP Easy firmware can be downloaded at: https://sourceforge.net/projects/espeasy/
I will use the release R120.

Unzip the espeasy_r120 file. You will see the source folder, with the source code and library, and firmware already compiled in another folder, with its tool to flash it.

As we dont need to customize the code yet, I will use the flash tool to flash the NodeMCU.
First, locate your COM port number into the device manager.

Then, open the flash.cmd script:
- Type your port number
- Type the memory size of your module (mine is 1024)
- Type the release version: 120
Flashing the module should take about 1 minute.

Then, grab your mobile phone, and scan for wifi networks. If everything is OK, you should see a ESP_0 wifi network in the list. Connect to it. The password is "configesp".
Once connected, open your web browser and type: http://192.168.4.1/setup
You should arrive on a page that asks you to select your wifi network, and to type the password. Then, hit Connect.

Wait about 30 seconds to let the NodeMCU connect to your wifi network. The new IP address of the NodeMCU should be displayed on your web browser. If not, you can still use your router config page to find the NodeMCU IP address.

From a device on your network, open your web browser and type the NodeMCU IP.
The main ESP EASY config page should appear:


Then, click on the Config tab. From there, you will be able to change the name of the module and to put an admin password if needed.
As we want to use it with Domoticz, put your Raspberry Pi Domotivz server IP into Controller IP.
Port should be 8080 if you have not changed it.
By default, connection can be made anonymously to Domoticz. However, for security reason, it is possible to secure it with user and password.
For the beginning, we will use HTTP protocol. Later on, we will move to MQTT.
Dont forget to click on Submit at the bottom of the page.



Adding a sensor:

As a test, I am going to add a basic DHT11 temperature and humidity sensor. This sensor will be replaced by the BME280 once I will receive it.

To add a sensor, click on the Devices tab. Click on device, and choose "Temperature and Humidity DHT".
Provide a name to the sensor and choose the Pin that you want to use, GPIO-13 in my case.
You can also provide an IDX number. This one will have to match with the IDX number on Domoticz. We will cover that point later on.


Then, disconnect the NodeMCU to wire the DHT11 sensor.

NodeMCU pinout:


So it should look like this (my DHT11 has only 3 Pins):



Now, power the NodeMCU, and browse to it, and click on Devices:
After the 60 seconds default delay, you should see:


It works!!

Domoticz setup

Domoticz is an open source home automation system. It can be used to monitor and control various devices such as lights, switches, alarm system, camera, etc...
Domoticz proposes to create scenarios that will trigger an event, depending on conditions.
It is compatible with many devices, from different vendors.


More information can be found on https://domoticz.com/ 

As I already have a Raspberry Pi running Raspbian, I will use it to run Domoticz.

Domoticz installation:

I presume that you already have a Raspberry Pi, running Raspian Jessie Lite, and with SSH enable.

To install Domoticz, simply type:  
sudo curl -L install.domoticz.com | sudo bash

More info can be found at: https://www.domoticz.com/wiki/Installing_and_running_Domoticz_on_a_Raspberry_PI

During the installation, it will ask you which port you want to use for HTTP and HTTPS access. Ports by default are 8080 and 443.  It can be changed, as well as the installation folder.

Once Domoticz is installed, to see the web interface, just type http://Raspberry_IP:8080 from  a web browser. If everything is fine, you should see this:





dimanche 16 avril 2017

Sensor module

This module will only report sensors value to Domoticz over wifi on a regular time interval.
The sensor module will be based on an ESP12E microcontroller.

The sensors that I have chosen (low price, I2C interface, reliability) are:

- Luminosity: BH1750
- Temperature, Humidity, Atmospheric pressure: BME280
- Soil moisture: Analog soil sensor

Powering the module:
This module has to run on battery.
ESP12 operating voltage is between 3V and 3.6V according to datasheet. (https://mintbox.in/media/esp-12e.pdf)
I2C sensors BH1750 and BME280 can run between 3V and 5V.
ESP12E has only one analog pin that can operate at maximum voltage 1V.

For this reasons, it should be easier to use a 3V battery, that could power the ESP and sensors without rectifying the voltage.
I have found that Lifepo4 battery could provide a stable voltage, so no regulator is needed.
I will use 2 x AA 3V 700 mAh Lifepo4.

ESP12E Firmware:
Easy and stable, the choice will be ESP EASY (https://sourceforge.net/projects/espeasy/)

ESP EASY is compatible with the sensors that I use, according to the specs (https://www.letscontrolit.com/wiki/index.php/ESPEasy).
It is compatible with Domoticz HTTP/MQTT, and with many other home automation solutions.

Drafting the specification..



Here are the specifications, that may change or be adapted in the future.

- Monitoring: Temperature, Air humidity, Luminosity, plant soil humidity, Atmospheric pressure
- Watering system that can be triggered by scenarios (soil moisture level) or manually
- Open source

Sensors data have to be accessible from PC and mobile (web browser) and from outside (internet).
Plants are outdoor so sensors data have to be reported wirelessy.
No main power where the plants are. Project has to run on battery.

The microcontroller needs to have the followings:
- I2C capable (sensors reading)
- Analog capable (soil sensor reading)
- Wifi capable
- Cheap
- Evolutive
- Low power consumption

For those reasons I choose the microcontroller ESP8266 / ESP12E.

I have decided, for pratical reason, to make 2 ESP "modules":
- One that will regulary check the sensors and report the value over wifi.
- A second one that  will control the water.
This will probably evolve and I may reconsider to have 2 modules instead of one.

Data collecting: DOMOTICZ
As I already have at home a Raspberry Pi that is running Raspian, I thought that I could use an open source domotic tool.
I have tried couple of them and made by choice with Domoticz. This can be also reconsidered and should not be that hard as many domotic softwares use standart protocol such as MQTT.