Home temperature monitoring using openHAB on RaspberryPi, ESP8266 and HDC1000.

It’s been awhile since I’ve wanted to start making my home “smart”.

I figured I could put some of my past projects together to build something nice, so I installed openHAB, a very known and powerful home automation software, on my raspberryPi.

Installing OpenHAB

There are plenty of guides on how to do it, so I’m just telling you the basic commands:

Installing an MQTT broker

Install the latest mosquitto binaries:

Setting up OpenHAB

(code adapted from here)

Let’s copy the default config file:

Open it in your favorite text editor, scroll down to the MQTT transport section and add this line:

Create a sitemap file:

Now the items file:


OpenHAB is now configured to read the two values from the MQTT broker and is subscribed to the “home/temperature” and “home/humidity” topics, which have been assigned to the two items.

The “<humidity>” icon does not exist but I googled one and uploaded it to “/opt/openhab/www/webapps/images/”. Neat!

Start openHAB by typing:

This will take a couple of minutes but this is how the interface looks like:

The openHAB interface.

The openHAB interface.

NodeMCU Code

The NodeMCU MQTT code is bugged in 0.9.5 so you most likely need to update your ESP8266 with a newer release (click!). I flashed nodemcu_float_0.9.6-dev_20150331.bin because the latest version also had problems connecting to the MQTT server. Just remember to get the float version.

Let me make this clear, coding for NodeMCU is a pain in the ass. You are going to get LOTS of “out of memory” errors and watchdog timeouts as soon as you implement a program which is bigger than an example.

However, after a lot of trial-and-error, I’ve been able to make a working program.

To do this, we need to split the program into different files and compile them separately, then call the compiled files from the main program, in order to reduce memory usage.

(I really hope I’ve been doing this wrong and there is a better way. If you know any, please tell me.)

  1. Upload my NodeMCU module (named “HDC1000.lua”). Instructions here.
  2. Create a file called “main.lua” with the following content:
  3.  Now a “connect.lua” file, which handles the WiFi connection:
  4.  And last but not least, the main loop of our program, “loop.lua”
    This sends MQTT messages to “home/humidity” and “home/temperature” every 60 seconds.
  5.  Now we need to compile all those files. Run these commands (press the “Send to ESP” button  instead of the “Save to ESP”):
    Ignore all the errors/reboots, they are “normal”.
  6.  You can then test your program by doing:

And that’s it. If you want your program to start at boot, you need to rename your “main.lua” file to “init.lua”.

You should do this so that the program starts again if it crashes, but be sure your code works as you might get stuck into infinite loops.

You can monitor MQTT messages by running

on your RaspberryPi.

Yay, it works!

Checking MQTT messages…

Now open your openHAB page: http://raspberrypi:8080/openhab.app

…Yay, it works!


Finally, everything works! I loved building this from the ground up: from the breakout board, to the NodeMCU library, to a fully working system!

Tomorrow I will place my ESP8266 and HDC1000 sensor outside and find a way power them (USB charger? Solar panel + LiPo?)

I hope to add more sensors and features (light and curtains control would be awesome) in the following weeks.

Note: I’m now learning how to program the ESP8266 in C. It may not be very straightforward or “Arduino-like” but will definitely save me some headaches and will allow me to take advantage of the full power of the chip.

Let me know what you think and if you have any questions or feedback!

NodeMCU library for the TI HDC1000 sensor!

It’s been a while since I received my NodeMCU development board but I have only been able to get my hands on it lately.

I soon downloaded the ESP uploader and after reading some Lua docs (and finding out some weird things such as that the “not equal” operator is actually “~=” ) I started writing my own code for the board.

Writing and uploading software to the board is easy and fast. The only concern is that after flashing the NoceMCU firmware you are not left with a lot of memory available.

So I wrote a NodeMCU library (they call them modules) for the TI HDC1000. The code has been merged to the dev branch of the nodemcu firmware and it should go to the master soon, but I’ve set up a repo too (click!).

Continue reading

Goodbye Arduino: ESP8266 development boards are coming – with Lua firmware!

The ESP8266 is a tiny, cheap MCU with integrated WiFi and impressive specs (datasheet here) and a lot of modules have been on the scene for quite a bit of time.

There are different versions of them, and this is the most common one:

An ESP8266 module

An ESP8266 module.


The fact is that, even if those modules have mostly been used for WiFi-to-serial communication with Arduinos, the chip can do a lot more than that. In fact, it’s a 32-bit MCU, which has a lot of horsepower compared to your average Atmega. Also, many of the modules don’t have all the pins broken out (10 GPIOs).

I actually thought about designing a proper breakout board for this chip, but many people from the community preceded me.

There is a toolchain you can use to write bare C to the chipset and access all of its functions (including all the GPIO pins). It’s been out for quite a few time and many firmwares have been developed, extending and improving AT commands.

One of the best news I came across this week is the release of a new firmware for the device, called nodemcu, which supports Lua commands: programming becomes Arduino-easy!

The guys over at nodemcu also developed a nice breakout board: I just bought one and I hope it comes here soon. It has a CH340G USB-to-serial converter on board together with a microUSB connector. All pins are also broken out on pin headers!


The nodemcu dev board

The Nodemcu dev board.

This is very exciting news and, in my opinion, the start of a new era for makers! This is what I’ll use for all my future projects.

You can find more info on the ESP8266 forums.