Please, proceed carefully following the tips published in this blog, specially when Main Power is involved. I'm not responsible for any damages caused by what is written in this blog.
Thank you

Saturday, 10 March 2018

Home Automation System - Energy consumption monitor...the first test

After a little stop, I'm going to tell you about my Home Automation System.

In particular, I would like to speak about some test I made to build a power monitoring system.

I'm trying to build something easily integrable in OpenHAB. I need a system able to acquire data and send them to OpenHAB, to be remotely accessible and use them to trigger alarms and notifications.

I need a little device which can be plugged in some junction box...

Looking for it on internet I found the Eastron sdm120c Modbus...

A nice product which can be query through its RS485 serial interface to fetch data about energy consumption (voltage, current, power, etc etc). It can be easily connected to an Arduino or Raspberry.

I was buying it when I found this one: PZEM-004T Energy Module, a little device with a current clamp able to get power consumption. It has a serial interface and so its data can be read by Arduino / Raspberry. It has little dimensions and it's very cheap. I bought it for 8€, shipped at home

Currently I bought only one...if my tests will be ok, I'll buy others. Mi target is to monitor home power consumption for each floor.

Now I have to choose a MCU. I would like to use a Esp8266 NodeMCU; it's a little device, has built in wifi capabilities and is very cheap! If it will not work as expected, I will use an Arduino board.

Ok, let's begin with some experiment just to see if PZEM-004T Energy Module will work. I will use an Arduino board because it's easier to plug than the ESP8266 NodeMcu

If it will work good, I'll try the ESP8266 NodeMcu.

The device needs 5V for the low-voltage side and 220v for the power line

Let's begin to plug:
  • GND and 5V from Arduino to the device;
  • serial output from the device to 2 Arduino GPIO

To test a load, I will use a simple lamp.

I downloaded a simple software for Arduino, which writes the data acquired on the serial output. Here is the output when the lamp is switched off: no current, no power:

Switch on the lamp...

and we get the power...

Perfect. It works as expected. Next step will be to use an Esp8266 NodeMCU instead of Arduino and then use MQTT tu send data to OpenHAB.

Thursday, 25 January 2018

Home Automation System - Alarm and OpenHAB...Let's build it

As I said before, here is the second and last part of my post about Home Alarm and OpenHAB, just to monitor input status using remote connection...a thing that actually I'm not able to do...

Here is my checklist:

  • take all the alarm inputs to the Raspberry PI3
  • build a litte board to interface input signal with the raspberry GPIO and let the voltage be compatible (raspberry GPIO are tolerant to a max of 3.3v)
  • plug the input signal of alarm into the input of this board...and output pin of this board to Raspberry GPIO
  • install and setup the GPIO Binding in OpenHAB (see https://github.com/openhab/openhab1-addons/wiki/GPIO-Binding)
  • finally, add new items in a OpenHAB sitemap

Let's begin

Cables and others...

My raspberry is near the main central unit of the alarm, where we can find 3 of the 11 input signals which we must manage...the other 8 are managed by an expansion board, far from the central unit and connected to it through a serial bus...

Luckily, I found a couple of empty pipes which connect central unit and expansion board...So, it's easy to put a ethernet cable into a pipe and use as connection.

I chose an ethernet cable (thanks to Piero for the suggestion) because it has 8 wires, it's shielded and it's easy to place

So, I placed this cable...and then I linked all its wires to the 8 signals of the expansion board...

This is the junction box where the expansion board is placed (the white box in the bottom) and where all the input signal arrived from the respective sensors / contacts.

The blue one is the ethernet cable...its wires are connected to the black clamps which, in turn, are connected to the expansion board.

Ok, I can close now.

Let's go upstairs, where we can find the junction box for the central unit.

Here is it...you can see the blue ethernet cable

I found also the 3 remaining input signal not managed by the expansion board but directly connected to the central unit...

I took the 8 wires of the ethernet cable plus the other 3 to the new self-built voltage divider board. Here is it: on the righe side we have the inputs, on the left side we have the outputs...in the middel we can find the voltage divider resistors

Last step: connection between outputs and the Raspberry GPIO 

We have 12 wires instead of 11 because there is also GND in common between sensors and raspberry.

Ok, all is connected. Raspberry boot up and home alarm is still working...nothing wrong for now.

Just some test: I open and close the windows and see that the voltage drop to 0v and then go back to 3v (3v is the max voltage divider output)

OpenHAB configuration

Now it's time to switch to the software side of the project.

On OpenHAB I installed GPIO Binding, to use the GPIO output with OpenHAB.

Open PAPERUI (the web interface to configure OpenHAB) and follow the path Add-ons -> Bindings

Here you can find the official documentation

Then, I created new items on OpenHAB, for the 11 inputs. So, I created a new file called gpio.items in the folder /etc/openhab2/items and wrote down the 11 items, one for each GPIO.

Here is my file (Visual Studio Code editor with Platformio extension)

As you can see, every row is linked to a pin number, which is the GPIO number of the raspberry; activelow parameter is used to tell to OpenHAB that the contact is OPEN when the voltage is 0 ... in my case its value is "no" because when my contact is OPEN we have positive voltage...

Finally I can add the newly created items to a sitemap...here is the result: (OpenHAB app on mobile)

Now I have to verify that all is working well...🍀🍀🍀


I'm not responsible for any damages caused by what is written in this post. Please proceed carefully and by your intentions

Friday, 19 January 2018

Home Automation System - Alarm and OpenHAB...my idea

I can't believe it!!! I reached a little goal...Home Alarm and OpenHAB together...

I know...It seems a simple thing...today home alarm systems can be remote controlled ... but the old ones (as mine is...) don't...

My target was to view the input status of all sensors / radars in my home alarm system...I don't like remote controller...just remote monitoring...

So, it's quite simple: I have to integrate all sensors / radars with a device, as Arduino or similar ones, and gets the input status (OPEN / CLOSE).

I have to know what kind of signal is transmitted by sensors / radars...I discovered the wires from the sensors / radar and with the tester I found the voltage is about 4.5v when the signal is HIGH and 0 when the signal is low.

I made some test with my main entrance door so I confirmed this behaviuor. Door OPEN, 4.5v on the terminal...DOOR closed, 0 voltage.

Now, I have to find a device with at least 11 GPIO 4.5v tolerant

I can choose between:

- a NodeMCU ESP8266 device, with integrated wifi; but it accepts only 4 volts

- an Arduino UNO with ethernet shield, with GPIO 5v tolerant;

The first choice would be the best, because we have integrated wifi and a very small layout...but I have to step down voltage from 4.5v to 3.3v (max)

Otherwise, using Arduino UNO, the voltage is already OK but I need a new shield (ethernet shield)


Raspberry PI3 where OpenHAB and MQTT broker are running, has a lot of GPIO on its board. I could use them. But these GPIO works with 3.3v max. No problem...I will build an interface device with voltage divider...

Then I could use an OpenHAB bindings (see https://github.com/openhab/openhab1-addons/wiki/GPIO-Binding) to manage GPIO, so no needs for an external software...


 - take all alarm input wires to the Raspberry PI3
 - build an interface to step down voltage from 4.5v to 3.3v
 - download and setup of GPIO binding of OpenHAB (see https://github.com/openhab/openhab1-addons/wiki/GPIO-Binding)
 - make a new sitemap to see the alarm device input

In the next post, I will descrive the operational phase of work