• Home
  • >
  • How To
  • >
  • ESP Easy: build your own home automation system

ESP Easy: build your own home automation system

  • by JaniDushman
  • 1 year ago
  • How To

Making your own home automation sensor is not that difficult or expensive. You need a sensor and a microcontroller board that transmits the sensor data wirelessly to your home automation controller. In this article we connect temperature, humidity and air pressure sensors and an LCD screen to an ESP8266 WiFi module. We install the ESP Easy firmware and integrate our sensor with the Domoticz open source automation system, so you can read the measurement data in the dashboard of your home automation controller. Your own home automation system in 17 steps!

01 ESP8266

The heart of a dome sensor consists of a controller board that reads sensor data and sends it to your home automation controller. A popular choice among DIY enthusiasts are signs based on the ESP8266 WiFi Module, produced by the Chinese company Espressif Systems. The controller operates at a clock frequency of 80 or 160 MHz, has 64 kilobytes of instructional memory and 96 kilobyte data memory, 512 kilobytes to 4 megabytes of ram, 802.11 b/g/n wifi and 16 gpio-pins for communication with the outside world. The AI-Thinker control boards are particularly popular, especially the minimalist ESP-01 with 6 usable pins and the ESP-12E with 20 usable pins.

02 ESP Easy

With only the hardware, you are nowhere: the firmware running on the ESP module determines the function of the controller board. Originally, the NodeMCU firmware was a popular choice for the ESP8266, but the Arduino firmware has also been supported in the meantime. The interesting thing about the latter is that you can then develop ESP module programs with the Arduino IDE. And ESP Easy firmware developers make it even easier for us: ESP Easy turns your ESP module into a multi-sensor device that you can easily configure via a web interface.

03 Download firmware

At the time of writing, ESP Easy’s developers are taking their firmware up and running. We therefore do not opt for the stable release, but for a development version of the fully rewritten version 2.0. Download the zip file (for us this ESPEasy_v2.0.0-dev11. zip, which in practice proved to be very stable) and unpack it. Besides the source code you can also see all kinds of bin files. That is the binary version of the firmware. The names make it clear what you need: normally only contains the stable plug-ins, tests the test plug-ins and also the plug-ins that are still being developed. 1024 is for ESP modules with 1 MB flash and 4096 is for ESP modules such as the ESP-12E with 4 MB flash.

04 Firmware Flashes

This article is illustrated with the ESP-12E, which has a micro-usb connector with built-in USB-to-serial converter for serial communication with your PC. First download the CP2102 drivers from the Silicon Labs website. Then connect the ESP module to your PC via usb. If you are using a different model ESP module, you need another USB totl converter that connects you to the gpio pins of your module. See ESP Easy’s wiki for more information. The flashing of the firmware is done with the FlashESP8266. exe tool in the zip file with the firmware. Select the serial port (e. g. COM0) and bin file with the desired firmware.

05 Wifi configuration

When the freshly flashed ESP module starts up (press the RST button on the board after flashing is complete), it functions as a wireless access point with ssid ESP_Easy_0. Connect to it via your smartphone or another Wi-Fi device and enter configesp as password. Then open your web browser, which will take you to the ESP module’s captive portal. Choose which ssid to use to connect the ESP module and enter the corresponding password. Press Connect to set up the connection.

06 Password

If the ESP module has succeeded in connecting to your wifi, you will see the IP address. Now connect your smartphone to your normal wifi again and then visit your web browser (this can now be done on your PC, a larger screen is now more convenient) the ip-address of the ESP module for the rest of the configuration. In the Config tab it is especially important that you give a unique name to your module and choose an administrator password, so that not everyone in your local network is able to change the configuration. Press Submit at the bottom.

07 Add Domoticz controller added

In the Controllers tab there is already a controller with the Domoticz protocol added by default. Click on Edit to the right. As a protocol you leave Domoticz HTTP as a protocol. Enter the IP address and port (default 8080) of your Domoticz controller. If you have protected Domoticz’s web interface with a username and password, please enter it here. Finally, check Enabled and click Submit. If you then press Close, your Domoticz controller appears in the list of controllers.

08 Status LED

In the Hardware tab, define what you are using the gpio pins for. A handy feature that is new in version 2.0 of the firmware can be found under Wifi Status LED. If you enter the pin number to which a LED is connected, ESP Easy displays the status of wifi on that LED. And this is also possible with the integrated LED of the ESP module. Select GPIO-2 (D4) and tick Inversed LED because it works. Click on Submit at the bottom. If ESP Easy is not connected to wifi, the LED flashes quickly between bright and soft.

09 Sensors and screen

Now take a breadboard and insert the ESP module (not connected to the power supply!) and a BMP180 sensor board. The latter is a circuit board with temperature and air pressure sensor. Now connect VIN on the BMP180 to 3V3 on the ESP module, GND to GND, SCL to D1 and SDA to D2. Now take the AM2302 (DHT22) temperature and humidity sensor, connect the red wire to VIN, black to GND and yellow to D5. Finally, connect the OLED screen with SDD1306 controller: VCC to VIN, GND to GND, SCL to D1 and SDA to D2. Then reconnect the ESP module power supply.

10 Virtual sensors in Domoticz

Create a dummy sensor in the Domoticz web interface. To do so, open the Settings / Hardware menu, select new hardware from the Dummy type list, name the device and make sure that Active is checked. Click on the Add button. Then click on Create Virtual Sensors on the virtual device. Name the sensor and choose Temp+Hum type. Click OK to create the sensor. Then locate the sensor in Settings / Devices and note the number in the Idx column. This is the id of the sensor. Then add a Temp+Baro sensor in the same way.

11 Configure DHT sensor configuration

Now open the ESP Easy web interface. On the Devices tab in the first row, click Edit. For Devices, choose Environment – DHT11/12/22. Enter the name of the sensor and check Enabled. Choose as GPIO pin GPIO-14 (D5) and as sensor type DHT 22. At IDX, enter the ID of the sensor in Domoticz and make sure that Send to Controller is checked. Then click Submit. Then click Close, then you will see the sensor in the list of devices, including the current temperature and humidity. In Domoticz you will also see the details.

12 Configure BMP sensor configuration

The BMP180 sensor communicates with the ESP module via the I2C interface. So first check the ESP Easy Hardware tab to see if the I2C interface is configured correctly: GPIO-4 (D2) for SDA and GPIO-5 (D1) for SCL. These are also the connections you made on the breadboard. Then go to the Devices tab and click on Edit in the second row. Select as the unit for Environment – BMP085/180. Name the sensor, tick Enabled and fill in the altitude of your location in meters (to compensate for the air pressure). Enter the correct id of the virtual sensor in Domoticz and click Submit.

13 Create own rules

During the editorial closure there was another ESP Easy error which caused the firmware to send the air pressure of the BMP sensor to Domoticz incorrectly. ESP Easy is fortunately flexible enough to solve this problem. To do so, first uncheck your BMP sensor Send to Controller and click Submit. Then open the Tools tab, click Advanced, check Rules and click Submit. A new Rules tab will now appear. Open this. In the text field you can now simply add your own rules.

14 Timer

Add the script below in the text field. Replace the IP address, port number and id with the values for your situation. This script sends the sensor data to Domoticz every minute. Reboot the ESP module in Tools / Reboot afterwards.

15 Configure OLED screen configuration

All that remains is to configure the oled screen so that we can see the sensor data as well. From the Tools tab, first click on I2C Scan and see what I2C address the OLED screen uses, default 0x3c. Next, create a third device on the Devices tab and select the Type Display – OLED SSD1306. Select a name, check Enabled and verify that the correct I2C address is entered. Also, choose the correct rotation (normal or inverted) and screen size.

16 Display sensor data

In the rest of the configuration of the OLED Screen, choose what will appear on the screen. You have 8 lines of 16 characters that you can fill in. Fill in on line 1 T:[BMP#Temperature]?C, on line 2 H:[AM2302#Humidity]% and on line 3 P:[BMP#Pressure] hPa. We use the BMP180 temperature because it is more accurate than the DHT22. Click Submit. After one minute (the default delay) you will see the sensor data on the screen.

17 Other sensors and actuators

The sensors and the screen we connected in this workshop are of course not the only supported devices. Here you will find a list of all plug-ins. Here you can also see which plug-ins are in the normal firmware and for which you need the testing or development firmware. The wiki page of a plug-in shows how to connect the device and configure the plug-in in ESP Easy.

IoT sensor on batteries

ESP Easy Easy is useful to transform an ESP module into an IoT device. But you don’t want to hang it on the wall all the time with a USB power adapter. Fortunately, the ESP module can also be powered with batteries. You have to do a number of tricks to reduce power consumption. Read this page on the wiki of ESP Easy. Broadly speaking, it boils down to keeping your ESP module in sleep mode for as long as possible. For example, you only measure the sensor value once an hour and then only switch on wifi for a moment. Also choose the right ESP module. For example, the Wemos D1 mini is an economical model that continues to work on three AA batteries for a year with some effort.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.