Adding a Plugwise Smile to the Fibaro HC2

Yep, I’m still alive 😉 The ‘silence’ since April this year was simply because I really needed some sort of ‘sabbatical’ after almost 10 years of spending a great deal of my spare time to Home Automation – and some other (more important) things happened in the past months as well. But last week something happened that brought back the inspiration to write a new post.

I think it must have been about 2 weeks ago when Marco from Mood LedLight contacted me to help him to get some information the Plugwise Smile can provide into his Fibaro HC2. He was probably inspired by my post about getting Smart meter data into a HC2. And Marco is the one that advised me on my Gazebo LED project some years ago and he’s my LED strip supplier. I don’t own a Plugwise Smile but thought I’d give it a try – if it can be done I should be able to do it, right? 😉

Marco sent me some info about the progress he had already made – he used a PHP script to query the Smile and write the result to a file on a Windows 2008 IIS server and read that file from a lua script in a Fibaro virtual device and actually wanted to get rid of the PHP part.

The only part I did was getting the authentication working so that it was possible to get the Smile XML data without the use of the Win2k8 Web server. For the last part, XML parsing in Lua, I didn’t have enough time so I asked Marco to seek for help on that from the real Fibaro Lua script cracks – cause I only know the basics. 3 days later Marco had found the solution; here it is… have fun!

%% properties
%% globals
-- Virtual device id
vDevId = 102
-- url van PI met meterconnectie
PI1 = Net.FHttp("192.168.xx.xx");
PI1:setBasicAuthentication("smile", "fake");
-- ophalen JSON info
response, status, errorCode = PI1:GET("/core/modules");
-- Meter info ophalen 
--local a = string.match(response, "^.+<vendor_name>(.+)</vendor_name>.+$");
--local b = string.match(response, "^.+<modified_date>(.+)</modified_date>.+$");
--local c = string.match(response, "^.+<created_date>(.+)</created_date>.+$");
--local d = string.match(response, "^.+<vendor_model>(.+)</vendor_model>.+$");
-- Uitlezen meters
local e = string.match(response, "unit='W' directionality='consumed'>(.+)</measurement>.+$");
local e1, e2, e3, e4, e5, e6, e7, e8, e9 = string.match(e, "(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)%s(%x.+)");
-- omzetten naar decimalen
local e1 = string.match(e1, '%d+')
local e2 = string.match(e2, '%d+')
local e3 = string.match(e3, '%d+')
local e4 = string.match(e4, '%d+')
local e5 = string.match(e5, '%d+')
local e6 = string.match(e6, '%d+')
local e7 = string.match(e7, '%d+')
local e8 = string.match(e8, '%d+')
local e9 = string.match(e9, '%d+')
-- Totaal tellers (dag+nacht-teruglevering)
local e10 = e8 + e9 - e6
-- delen door 1000 voor KwH
local e6 = e6/1000
local e8 = e8/1000
local e9 = e9/1000
local e10 = e10/1000
-- afronden op 2 decimalen
local e6 = string.format("%.2f", e6)
local e8 = string.format("%.2f", e8)
local e9 = string.format("%.2f", e9)
local e10 = string.format("%.2f", e10)
-- waardes weergeven
--fibaro:debug("vendor name :" .. a);
--fibaro:debug("vendor_model :" .. d);
--fibaro:debug("modified date :" .. b);
--fibaro:debug("created date :" .. c);
fibaro:debug(" Huidig gebruik : " .. e1 .." Watt" );
--fibaro:debug(" waarde 2 : " .. e2 );
--fibaro:debug(" waarde 3 : " .. e3 );
--fibaro:debug(" waarde 4 : " .. e4 );
--fibaro:debug(" Nachtteller totaal : " .. e5 .." KiloWatt uur");
--fibaro:debug(" Dagteller totaal : " .. e6 .." KiloWatt uur");
--fibaro:debug(" Totaal tellers : " .. e7 .." kiloWatt uur");
--fibaro:debug(" waarde 5 : " .. e5 );
fibaro:debug(" Terug Levering totaal : " .. e6 .." KwH");
--fibaro:debug(" waarde 7 : " .. e7 );
fibaro:debug(" Nachtteller totaal : " .. e8 .." KwH" );
fibaro:debug(" Dagteller totaal : " .. e9 .." KwH" );
fibaro:debug(" Totaal tellers : ".. e10 .." KwH" );
-- Update virtual device
fibaro:call(vDevId, "setProperty", "ui.lbldagverbruik.value", e9.." KWh");
fibaro:call(vDevId, "setProperty", "ui.lblnachtverbruik.value", e8.." KWh");
fibaro:call(vDevId, "setProperty", "ui.lblactueelverbruik.value", e1.." Watt");
fibaro:call(vDevId, "setProperty", "ui.lbltotaalverbruik.value", e10.." KWh");
-- Temp dag start ophalen en aftrekken van totaal om dag totaal te berekenen
local myVar1 = fibaro:getGlobalValue('Watt_today_start');
fibaro:debug ("waarde van de variable dag start is ".. myVar1);
local myVar2 = fibaro:getGlobalValue('Watt_Temp');
fibaro:debug ("waarde van de variable dag totaal is ".. myVar2);
local myVar3 = (myVar2 - myVar1);
local myVar3 = string.format("%.2f", myVar3)
fibaro:debug ("waarde van de variable dag gebruik is ".. myVar3);
fibaro:call(vDevId, "setProperty", "ui.lbltodayverbruik.value", myVar3.." KWh");
-- Gisteren
local myVar4 = fibaro:getGlobalValue('Watt_yesterday');
fibaro:call(vDevId, "setProperty", "ui.lblyesterdayverbruik.value", myVar4.." KWh");
fibaro:debug ("waarde van de variable gisteren gebruik is ".. myVar4);
-- update global variable
fibaro:setGlobal("Watt_current", e1);
fibaro:setGlobal("Watt_Temp", e10);
fibaro:setGlobal("Watt_today", myVar3);
-- ff 20 seconden slapen



The Fibaro FGMS-001 on RaZberry and Z-Wave, The Interoperable Standard ?

Well, maybe the fact that the Z-Wave logo can only be found at the bottom of the package of the FGMS-001 was an omen for another story about bad luck. Here it goes.

Fibaro FGMS-001After successfully binding to events in the Z-Way API and getting the required information into my home-brew Home Automation system, I focused on the FGMS-001.

It’s a real beauty; small, flexible, you could almost say that Fibaro reinvented the motion sensor and even managed to fit some additional sensors into the ‘ball’ which are useful @ lots of places in the house.

So I was very excited to see this sensor working. Inclusion went fine, but then the trouble started. My binding worked fine, but no sign of Temp & Lux values? I also saw an error in the z-way-server.log:

Packet CC::MULTI_CHANNEL_CMD_ENCAP_V2 is too short: required at least 5 bytes, got 3
Error returned from _zway_cc_call_handler(zway, command, controller->id, 0, data[4], &data[5]): Wrong packet from Z-Wave network or Discovery got bad data (stick communication failed) (-9)

That doesn’t look good, so I searched for the error message; according to this seems I need a better/newer XML file, so I did. Motion was working, but Temp & Lux weren’t being updated. After a while I found out that this doesn’t happen by design – you have to change some parameters in the configuration. OK, did that. Wrong – you can’t use the RaZberry Expert UI to change those values, cause it messes up the entered values – enter “10” but this is changed to “32769” once you tab your way to the next textbox. Imagine what happens after applying such a value – temperature measurement every 9 hours.

So to finally get things going, I had to do it myself from a command prompt (setting Temperature interval to 600 seconds):


Yep, by the time I got this far the device counter had already reached 7, with just 2 sensors. And the battery is at 88% now, after almost 3 days – what was it, 2 years battery life? I’ll believe it when I see it. The FGMS-001 has lost a lot of its ‘glamour’ in just 2 days.

So what is this, a sensor from a bad batch? Still in beta stage? forum blames Fibaro for not following the standards of the holy grail of Home Automation called Z-Wave. Is this true and if so, why do this? Can’t they read?  Or is there some other purpose for this kind of deviation? I don’t know and frankly it doesn’t even really matter – what it results in does matter.

Cause all these little deviations make Z-Wave unreliable, immature – you never know whether it’ll work out of the box or not. Lots of techies will be able to solve this sort of issues, but the majority won’t. Killing. And imagine the IoT, with a predicted >25 billion devices around 2020, being driven by Z-Wave … it gives me the shivers!

Adding a smart meter to the Fibaro HC2

This is (sort of) a follow-up on my previous post about the cheap Serial to Ethernet converter. It has kept me busy for a couple of evenings, for several reasons:

  • I wanted to use the Arduino Nano as a web server;
  • Make the Nano return a JSON object containing the smart meter data;
  • Learn more about the Fibaro HC2 on the job;
  • The new sketch was unstable.

It was mostly that last item that kept me busy for some time – well, waiting describes it better actually, cause the sketch I initially wrote was doing what it should, but wasn’t stable – it stopped working after 2 hours, the next time after 20 hours.. totally unpredictable. I also saw the Nano was sometimes missing incoming serial P1 data. And of course, these sort of things never happen while you’re there to witness it: I was always either at work or asleep (or both 😉 ).

So for a few days I tried to improve things and had to wait until the next day to see if the changes fixed the issue. It wasn’t lack of free RAM, it wasn’t the USB hub misbehaving, it wasn’t RF interference, nor was it a grounding issue. After I found a solution, the cause was very obvious actually: the Nano doesn’t do multitasking. Somehow taking care of receiving and processing serial data and handling an Ethernet shield interfered with each other – I still don’t know why, but after I denied the web server part of the sketch of servicing HTTP requests while the smart meter data was being received, this problem was solved. Detecting the beginning and end of a P1 packet is easy: it starts with ‘/’ and ends with ‘!’. So now the loop() looks like this:

void loop() {
  c =;
  switch (c) {
    case '/':
      receiving = true;
    case '!':
      receiving = false;
  if(!receiving) {
    if (ether.packetLoop(ether.packetReceive())) {

With a P1 packet being about 500 bytes in size and 9600 baud this would ‘stall’ the response for about half a second (max.), which should not be a problem.

After I finally had a sketch that kept working for >48 hours it was time to have a look a the Fibaro HC2 and try to get the smart meter information (visibly) available in there.

Because I’ve spent very little time with the Fibaro HC2, please don’t put too much weight in what I have to say about the HC2, but: there’s one word that’s now associated with the HC2 in my head: impressive. The HC2 case feels solid, looks good, gets warm, the UI looks good, the power consumption is about 13.5 W doing nothing (I had no Z-Wave hardware to add), and the HC2 has something called Virtual Devices. For me, that’s the thing I’m interested in the most – using the HC2 is not my thing, but exploring what I can do to add my own things to it is..

So after I hooked up the HC2 to my LAN, performed some upgrades and changed some settings, I immediately focused on those Virtual Devices. P1 Smart meter in Fibaro HC2I know I’ve just scratched the surface so far, but being able to create a Virtual Device within minutes and being able to get the smart meter data from the Nano web-server into Virtual Device properties and being displayed nicely as well with just a lua script of ~20 lines of code – that’s impressive! Not bad for a beginner 😉 And for a price <20 Euro! Add a database solution, charting and I think the HC2 has a great future ahead.


Although I liked what I’ve seen so far, I do have some things that might be not so handy.

The lua script I wrote, was only 20 lines or so. Editing the code from within the browser, in a small window is not really as comfortable as editing code can/should be. And more important, everything you need in a script has to be in there (AFAIK) – so suppose you have to calculate a CRC, the CRC code has to be inside the script that needs it – no way of including source code files which will probably be used in more ‘main loops’ than just 1. I’d really like to see some sort of ‘Plugin’-ish way to add support for exotic hardware; a bunch of files with code, UI pages that can be embedded in the HC2 UI (e.g. for configuration stuff), creating Plugin specific triggers etcetera. In other words: really embed your own creations into HC2.

If Fibaro can accomplish that, then the HC2 can become the killer solution for Home Automation for a lot of people; with Z-Wave as the base technology, yet still expandable with support for other popular hardware.

Oh my, almost forgot the lua script, here it is:

%% properties
%% globals
if (nano == nil) then
  nano = Net.FHttp("", 80)
response, status, errorcode = nano:GET("/")
local data
data = json.decode(response)
-- not 0 based!
jso = data[1]
v181  = jso.v181
v182  = jso.v182
v170  = jso.v170 * 1000
v2421 = jso.v2421
-- deviceid 7
fibaro:call(7, "setProperty", "ui.lbl181.value", v181.." kWh")
fibaro:call(7, "setProperty", "ui.lbl182.value", v182.." kWh")
fibaro:call(7, "setProperty", "ui.lbl170.value", v170.." W")
fibaro:call(7, "setProperty", "ui.lbl2421.value", v2421.." m3")

Have fun!

Meet the Fibaro Wall Plug FWGPF-101

Fibaro Wall Plug

Today I received a Fibaro Wall Plug FGWPF-101.

I shut down my RPi running RasPlex, exchanged the SD card for the one with the RaZberry software on it, booted the RPi and from the RaZberry UI I included the Fibaro Wall Plug (Plug from now on). Within 2 minutes the Plug was ready to play with 😉

Lets have a closer look at what this Plug can do:

– handle 2.5 kW continuous load (resistive load, so watch the cos φ)
– Radio: Z-Wave, 1 mW @ 868.4 MHz
– Range: 30 m indoors
– Dimensions: D x H 43 x 65 mm
– Crystal RGB LED ring which can be used for a number of things
– Measuring momentary and historic power usage
– Local control by a small push button

The first thing I noticed was the very tiny manual: A4, printed on both sides with a very small font. I downloaded the Operating manual as PDF, maximized Adobe Reader on one of my 22″ HD resolution screens and still had to zoom to 121% before i could start reading. MS Word counts > 3100 words on a single-sided A4 – I’ve seen better.

The Plug itself looks great though! The white surface is glossy and the LED ring looks nice too. But the biggest advantage is the size – it’s really small!

3 different Plugs

I took a picture of 3 plugin modules I have and as you can see 4 Fibaro Plugs will easily fit into that box with 4 sockets; Insteon will manage 2 (and 4 with some extra force) but PLCBUS is the big loser here: only 2 will fit.

The first I did was trying to get a feeling about how fast the Plug responded to On/Off switching from the RaZberry UI. Well, what can I say.. comparing it to X-10 or PLCBUS is useless in terms of responsiveness, those 2 will never win. But I also have a Insteon Hub and an Insteon On/Off Module on my desk and I can control this On/Off module from my homebrew Home Automation system. So i tried both Fibaro and Insteon and I’m not sure, but I think Insteon is a little bit faster: the clicking sound of the Insteon module relay seems to have a smaller ‘silence gap’ with the clicking sound of the mouse than the Fibaro Plug. But maybe I’m biased, so I’ll redo this ‘measurement’ in another way 😉

I’ll test this more thoroughly in the next few days, but before I can do that I need to be able to control this new Plug from my system – that’s the only way I can really compare the two. And I’ll add PLCBUS to the competition as well, just for fun.

After that I’ll do some range testing and see how really well (reliable) this Fibaro Plug performs in a real house, compared to those other 2.

Stay tuned!


PS, a message for Mr. Essent – my wife’s hairdryer did turn the LED ring of the Fibaro Plug dark orange, while my hobby equipment all stayed in the green zone! 😉