All posts for the month January, 2017

First Project with the ESP8266 WiFi/MCU Module

The ESP8266 is an inexpensive WiFi-Serial MCU module that allows you to create sensors, switches, or just about any WiFi enabled connectivity for projects.  In my project, I decided to embark on a learning exercise by creating a real time energy threshold monitor to monitor my electricity usage and know when we were experiencing a time of high utilization.  The hope is that by doing so, we become more conscious about how much energy we use and that this can hopefully lead to better habits that reduce our energy costs.

We have a Z-Wave home automation system based on a Raspberry Pi, USB Z-wave stick, and Linux running Domoticz – an open source home automation suite.  Domoticz is a very capable system that lets you tie in a wide variety of control endpoints, data sources, and load switching.  To add the ESP8266 to Domoticz, I had to write some code (firmware) for it using the Arduino IDE (1.8.x) and install the community ESP8266 libraries.  I needed two channels (LEDs) to represent two states; low and high usage.  I used 2 GPIO ports on the module to light an LED (red or green) depending on what Domoticz detected for energy usage.  The interfacing is done as a simple HTTP request to the LED (see code).  In order to do this I had to also create a dummy switch in Domoticz under Hardware and create two separate instances; one for each LED.  

Once I had both virtual devices created, I was then able to see them in the devices list: 

It is a good idea to create a static IP reservation in the DHCP settings of your network, this way, the ESP8266 always comes up with the same IP address on your network: 

Now that we know what the IP address of the module will be, it was easy to assign each virtual switch in Domoticz to each LED (click for larger view):

You can see here how I created the linkage to each LED.  Domoticz makes it easy!  They now show up on the Control Board in the Domoticz web UI:

I still had to have logic in Domoticz to decide when to switch back and forth between red and green LEDs.  Fortunately, it’s easy to do and set that in the Events utility which allows you to build blocky style logic code that makes Domoticz pure magic:  

Here is a LINK TO THE SOURCECODE for the ESP8266 module for this project.  It should help you setup something similar.  These ESP8266 modules are the perfect thing for creating great automation solutions, only limited by your imagination!  Let me know how you use them in your project!  I plan to transfer my module into a decorative frosted glass globe that will glow and change color when the energy demand changes.  Meanwhile, here’s a video demonstration of the module in action: