Monthly Archives: March 2016

Putting it all together in Imperihome

This blog entry is about using the Imperihome APP with Node-Red to control IOT. This is looking like the best APP out there.. Read on..

Please note: 14/03/2016 Update thanks to vastly improved understanding of Imperihome – part of this is  thanks to Peter Oakes and his homework (check him out on YouTube). See here for a new video on the setup… more up to date than this blog entry.

I’m writing this for three reasons:

1. To clarify how Node-Red and Imperihome can work together to allow remote access to IOT

2. To form a base from which to expand

3. To get the conversation away from the original Imperihome article (previous blog) which is now WAY overcrowded.

So here is a basic setup for an RGB LED with colour, saturation and intensity control. Output is to debug but you could of course send that off to any RGB light or to MQTT (which is what I will do). Here is the API information for various devices..

Here is the APP itself in the Google Play Store.

The basic setup for using the Imperihome API (documented here – suggest printing this out it you are interested) is as follows:

You need to define:

  1. The system
  2. The rooms
  3. The devices

Rooms are merely a mechanism for separating stuff up into pages – use them as you will.

You set this up on Node-Red – then merely create a new SYSTEM using IMPERIHOME STANDARD SYSTEM in the App. If you don’t have password setting on your Node-Red pages then you don’t need a username and password. That simple. The local URL  in the APP will be http://192.168.0.x:1880/test1 – if you want to use this outside of the home at the very minimal you want username and pass and preferably setup https (the two security items being outside of the scope of this article).


Let’s go through this step by step – the cream things are standard http input and output nodes. The latter need no setup at all, the input nodes need and address – I’ve called my base address “test1” – don’t worry you don’t have to create any test pages – you need do nothing more than set up this tab in Node-Red and setup the APP as I’ve described above.

The URLS for the first 3 http nodes are self explanatory – the last on (rest actions) is as follows:


So the first 3 are incoming requests from the APP (by default every 5 seconds and at startup) – I change my default (in settings for the APP SYSTEM) to 2 seconds.

The system request and room requests are just setup – in this case I have one “room”  - I can have as many as I like and these are essentially tabs in the APP.

The orange units are functions you write yourself. The first function is merely setup.

msg.payload = { "id": "ISS:Test:01", "apiversion": 1};
return msg;

The third one – the rooms is also simple:

msg.payload = {"rooms": [{ "id": "roomID1", "name": "Test Room" }]};
return msg;

If you want more rooms you simply add them as such:

msg.payload = {"rooms": [{ "id": "roomID1", "name": "Test Room" },[{ "id": "roomID2", "name": "Other Room" }]};
return msg;

Ok, this takes us to the devices function. This simultaneously tells the APP what devices you have (you don’t need to set anything up on the APP at all other than your node-red page address the name of which (test1) is arbitrary.

var rgbState = global.get('rgbState') || 0;
var rgbLevel = global.get('rgbLevel') || 0;
var rgbColour = global.get('rgbColour') || "AAAAAAAA";

msg.payload = {"devices": [
{ "id": "dev01", "name": "RGB Light", "type": "DevRGBLight", "room": "roomID1", "params": [{"key": "dimmable", "value": "1"}, {"key": "whitechannel", "value": "0"}, {"key": "Status", "value": rgbState}, {"key": "Level", "value": rgbLevel}, {"key": "color", "value": rgbColour}]}
return msg;

If you look at the Imperihome API instructions you’ll see all about parameters and types.

So – I pull in three global variables (which used to be of the form but which are now accessed with .get and .put commands – looks odd if you’re not used to them but it’s simple enough.. the “!! 0” simply means return 0 or “AAAAAAAA”  if the variable has yet to be initialised.

Incidentally AAAAAAAA for a colour – yes that caught me out – it is HEX and the first 2 digits are irrelevant unless you are using WRGB LEDS.  I’m using RGB (the W is for WHITE).

So this sets up the RGB light device in the APP and prefills values – but also it is called regularly to update the APP display – such as the sliders and RGB control. rgbSTATE incidentally is for the APP RGB on-off button – and will be 1 or 0. Level will be 0-100 and the rgbColour will be any WRGB value (first 2 digits ignore).

What we are saying in that mess above is that this is an RGB light control in the main room, it is dimmable, we’re not using WHITE and here are the settings.

All that remains to do now is take action when the actual APP controls are changed… and that means storing updates to the global variables.

That is this bit extracted from above.


So we have the http input and I described that URL above – and a simple switch – ie. which device are we talking about? I only have one device here…

Imperihome switch

See “dev01” – that is the name of the one and only device – really one should give the devices more meaningful names but that’ll do here.

There is one output from this switch node – there would be more if you added more (the +rule).

The output goes to a simple standard function (top)

msg.payload = { "success": true, "errormsg": "ok" };
return msg;

That then goes back to the APP via the http node. This is common to all devices…

So here it gets more interesting. You are taking in commands from the APP and doing something – firstly storing the results in global variables – but then taking RGB and brightness data and creating an output to go off to your RGB light – in this case just a debug output.

This is a bodge – does not take into account proper colour adjustment at various brightnesses – and right now people (just got your email Chris) are firing ideas at me so this version will go in the bin – but it will do for the purpose of experimenting.


function colorLuminance(hex, lum) {
    // Validate hex string
    hex = String(hex).replace(/[^0-9a-f]/gi, "");
    if (hex.length < 6) {
        hex = hex.replace(/(.)/g, '$1$1');
    lum = lum || 0;
    // Convert to decimal and change luminosity
    var rgb = "#",
    for (var i = 0; i < 3; ++i) {
        c = parseInt(hex.substr(i * 2, 2), 16);
        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
        rgb += ("00" + c).substr(c.length);
    return rgb;

switch (msg.req.params.actionName){
case "setStatus": global.set('rgbState', msg.req.params.actionParameter);  break; 
case "setColor":  global.set('rgbColour', msg.req.params.actionParameter);  break;
case "setLevel":  global.set('rgbLevel', msg.req.params.actionParameter);  break;
default: break;
if (global.get('rgbState') == '0' || global.get('rgbLevel') == '0') {
    msg.payload = 'RGB = 0,0,0';
} else {

    hexColor = colorLuminance(global.get('rgbColour').slice(2), -1+(parseInt(global.get('rgbLevel'))*0.01));

    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16);
return msg;


The function above merely takes RGB and brightness and produces an RGB value adjusted by brightness.

The main code has a switch to check which command came in – to adjust status (1,0), level (brightness 0-100) and RGB value. These are merely stored in the global variables.

All that remains to do is output something suitable to the debug – it is crude but it works.



So whenever you make a change to the on-off state of the control in the APP, or change colour, brilliance or saturation – you will see a new RGB value come out of the debug.

When first setup this works. I then go into the APP and adjust the refresh time to every 2 seconds and something strange happens… the level control “flickers”. It did this in my more complex set up and now does it in this simplified and “clean” version.

Here are APP screenshots – ignore my username and pass.






All very simple – and can be expanded on with multiple rooms, IP cameras and all SORTS of widgets – a BARGAIN at £4 for the APP.

Update 09/03/2016

It turns out that the brilliance slider thing was a bug – fixed. Meanwhile here’s a picture of my current setup with a few controls – note that the http responses are all tied together where the response is identical – makes for a much simpler layout.





ImpirihomeImperihome is a well-developed App (Android and IOS) for controlling gadgets (there are some IOS limits). It supports a wide range of systems and has a good range of controls and graphs.

Problem is… I don’t want to control any of these – Node-Red is doing a fine job of that right now.  I’m using Blynk and node-red-contrib-UI for visuals along, of course with Nextion displays (more on the latter soon).

The Blynk is fine but it has some really dumb restrictions (one page per project – and as some of the widgets are very large that makes it useless for some applications) – also it remains to be seen how quickly we’ll get new widgets when they go commercial this month and I’m not really that happy about an on-going payment. Blynk could do well or flop due to lack of support when they ask for money – and how quickly new controls emerge – who knows.

The node-red-contrib-UI program development for now at least APPEARS to have stopped – hoping that will change. Both of these incidentally work very reliably in their latest incarnation but Blynk has an inexplicable “ON” or “OFF” message on buttons which just seems rather limiting to me – what if you want to use the buttons for “up” and “down”. I’m told this will be fixed… but no timescale for when.  I’ve also been pressing for multiple pages per projects for some time – that also has still not arrived.

ImperihomeAnd so we have this lovely looking Imperihome App which reader Gregg brought to my attention. Now I have to say that I am able to write this now only because of some sterling weekend work by others who’s comments you should read. AT FIRST GLANCE this would appear to blow the pants off either of the previously mentioned UI systems.

A quick browse through the web showed NOTHING on the subject of Imperihome and Node-Red – but we’re fixing that right here – this APP is meant to work with commercial off the shelf units and I’m sure it will do that well – look at the comments on their site – mostly positive or even glowing – but I’m not interested in any of that – I have a working setup to control lots of devices via Node-Red and I’m happy with that  - what I want is a pretty and well-functional display for my phone – and it might just be that this is it. Now that Node-Red is standard on one of the world’s most popular SBCs (the Raspberry Pi – just recently given a major upgrade to RPi3) – I see Node-Red really going places hence sticking with it as my main control hub.

So – Imperihome - multiple pages – SURE – now, not later.  Decent RGB controls – YES – and they don’t take up half the screen.  Loads of devices including heating systems, RGB lights etc, yes. Multiple screen layouts – yes – again – now not later.

And now – Node-RED. Adding new devices is a matter of adding a couple of lines to the code that Steven Daglish has provided in the comments below (note his example mentions a lightswitch – just not implemented so don’t panic when you can’t see the light.

Note the pictgures here – this is just a TINY glimpse at what you can do with this app - you really need to go look at the site – the App is £4 but there’s a free demo – I lasted 20 seconds before I had to go buy the full App – it is WELL worth it.

You can see a bunch of controls – or have widgets with options for each widget – you can have variable numbers of widgets on a page so you might have large widgets on a phone or loads of little ones on a tablet – this is just WAY more advanced than anything else out there.

Oh, oh!! And it has speech recognition “turn off boiler” works no problem – sadly you seem to have to press a button to start it off – “ok google” takes you to the normal search.

This just keeps getting better – I just added one of my EASY-N cameras in Spain – and it works.

Note this blog entry is a re-write of the original article from earlier this week in the light of new knowledge. Expect to see LOTS more about this in here soon as I get my head around this and thanks to the guys who’ve contributed – keep it coming  - we’re onto a winner here I think. See the comments.


Visual Interfaces for IOT

Hollyberry BlynkSo much happening right now – the new Raspberry Pi 3 once again sets the bar with improved performance, Bluetooth and WIFI as standard. With up to 10x the speed of the original Pi we can do even more serious work with these devices.

Please note before proceeding – apparently the Blynk team plan to charge for the use of this app – it is not clear if this means using their server, using a local server or both? And they claim that new widgets will be included in a monthly deal – but WHAT new widgets and in what timescales? – as the Blynk app moves from free to paid I think they will find people want more definition of what is included and when. A one-off fee is one thing – an on-going payment is altogether something else.

The ESP8266s are looking (depending on which software you use) to be very reliable to – so that is both the central control and peripheral activity side of things more or less in place.

Where we are still falling down IMHO is the visual interface side – that is – remote control by phone. I’m interested only in Android but I’m sure the same applies to IOS.

At the turn of the year it was looking like a neck and neck race between a small number of systems, node-red-contrib-ui for those inclined to doing a spot of programming and Blynk for those who are more concerned with the visuals.  I’ve looked at several other packages but to be honest either the visuals were just pretty poor or the technology not too well thought out etc.

We’re not there yet.  To my mind the one with the most hope was, until recently node-red-contrib-ui but since January there has been little or no sign of the author and no further developments that I am aware of (though I did hear a rumour that it might become a permanent part of Node-Red – let’s hope this spurs major new development) – this is a great shame as there was a heavy conversation going on with big improvements almost there – and then it all stopped. This is not new – I was convinced at one point that NETIO would be the brave future but development on that seemed to stop some time ago despite being commercial.

That leaves us with Blynk and a few others. Blynk is almost there. It works with the concept of a central server which knows the states of various devices, accepts updates and relays that to the APP. I pushed hard on this to make sure that regardless of whether the App was on or off, the state would be stored and the App would reflect changes when brought back to life. This was considered an edge request by the designers but they implemented it anyway and between that, improvements to the local version of the (small Java) server (which can run on a Raspberry Pi) and some sterling volunteer third party work to bring websocket-based communication back to Node-Red, the App is looking like a clear leader – but not perfect yet.

Blynk[4]I recently contacted Blynk and was assured that at some point they will fix the current issue – that being – they expected people to use buttons for ON and OFF scenarios.  I’d not twigged to this issue until recently when I finally started putting together a set of Blynk controls for my various gadgets.

One of the items I use a lot in my Node-Red applications is my own BIGTIMER (node-red-contrib-bigtimer) and that can set, say a light, to come on and off at set times during the day – for example coming on at lighting up time and off at midnight.  But like all timers – one must have an override facility – and so it is with bigtimer – I can inject text “on”, “off” and “auto” into the input to manually override the timer or send it back to auto.

Well as you can imagine – that is simple to implement with 3 buttons – but having them say “ON” or “OFF” just does not apply – similarly for heating control you might have “up” and “down” buttons.

Blynk say they will not only implement variable text in the buttons but also icon graphics… well, can I put a request in now – if these are to be fixed icons – we need a full set of remote control icons – ie stop, pause, start, ff, rw etc.   For text the best option would be freeform…. or NOTHING – text in momentary buttons just doesn’t make sense to me. A change of colour when being pressed is good and they’ve implemented that.

It would be nice if they had a smaller button as well – and the RGB control is just WAY too big – but looking at the alternatives – Blynk are to my mind still ahead of most.

I’ve looked at several alternatives – but right now most just not cutting the mustard. Either too complicated to setup, too limiting, unreliable or just not finished – and that happens a lot. There is just one out there that might just blow Blynk out of the water and you’ll see my videos and this blog commenting in the future – the app is called Imperihome and thanks to a small number of us working together, there is now good support via Node-Red for this App which is available for both IOS and Android – on the surface it blows even Blynk out of the water. Time will tell.


Raspberry Pi 3 Grand Opening

Raspberry Pi 3  packagingAfter a couple of tense hours, the doorbell rang this morning – the RS delivery guy with my brand-spanking new Raspberry Pi 3.

So was it worth getting? Is this going to kill the competition? Should I have stopped in bed?

The Pi arrived in the usual oversize box – and I quickly opened it up only to find a load of packing and inside, a much smaller box.

Some day the various suppliers will “go green” and stop doing this – however – I opened up the smaller box to find – my Raspberry Pi 3 – which just happens to look almost identical to the previous model except for a few minor layout changes and a new chip + chip antenna.  So the first answer is – YES your existing boxes and connectors will fit.

Raspberry Pi 3[8]If you read my blog from yesterday you’ll know that the big differences here are greater clock speed, Bluetooth 4.1 and WI-FI – all welcome additions to the new Pi.

The new board is powered by a 1.2GHz, 64-bit quad-core ARM Cortex-A53 CPU, a step up over the 900MHz, 32-bit quad-core ARM Cortex-A7 processor used in the previous models. The new processor and other improvements should make it up to 50% faster than the Pi 2 in 32-bit mode and up to 10 times faster than the original Pi. I say “should” as I’ve not tested this.

Raspberry Pi 3[6]I’d already downloaded the latest Raspbian (dated 26/02/2016) and popped that onto a handy 16GB microSD card – all that remained was to plug everything in and switch on.

I turned on the power and…. the usual on-board red light came on and the normal boot up text appeared no problem!  After perhaps 10 seconds the screen blanked momentarily and up came the familiar Raspberry Pi graphical environment.

This time however, in the top right hand corner of the screen, twin monitor icons flashed to say that three access points could be seen!

I noted that Node-Red, complete with GPIO control is up and running – but what I could not see immediately was anything to do with Bluetooth – which seems a little odd. Try as I might I could not find any reference to Bluetooth – so just for the sake of if I popped open a terminal and did the usual “sudo apt-get update” and “sudo apt-get upgrade” but about the only thing that came to my attention was the upgrade of Node-Red from 0.12.5 to 0.13.3 -  which seems odd given that the version of Debian I downloaded was only released a few days ago.

When you do this incidentally – note that the Node-Red upgrade takes a LONG time – I was convinced at one point that the whole thing had died on me.


Raspberry Pi 3

The bad news? No USB3, no SATA, no PCIe  - but then this was to be expected – 2GB of RAM would have been nice too – but then they did manage to keep the price the same.

I went into the graphical setup for Raspberry Pi configuration, told it to expand the file system (why don’t they do that automatically), to disable serial (so that it can be used in Node-Red) and to enable SPI, I2C, SSH and the camera (i have a little camera module). I also changed the hostname from “raspberrypi” to “raspberrypi3” – sensible while I only have one of them.

I went Googling for Bluetooth on the Raspberry Pi 3 and of course, by and large the reviews out there are the usual – people re-gurgitated press release material and not actually testing anything so every review I found just blindly said “and now with WIFI and Bluetooth”


I noted that the NOOBS installation was 2 days younger than the Raspbian file so I went and installed that – and grabbed Raspbian – same result even after update and upgrade.

Here is a solution for the missing Bluetooth…

sudo apt-get install blueman bluez pulseaudio-module-bluetooth --install-suggests

My thanks to Brian Moses on Google+ for that one -  LO AND BEHOLD a Bluetooth symbol on the top of the screen – I put my H800 Logitech headset (which works with everything) into discover mode – and pressed search on the PI – again – everything worked – head headset was recognised and is now trusted… I pulled up a typical Python game after CONNECTING at which point the Bluetooth symbol turned green and… works a treat.


The Onion Omega

The Onion Omega is described as “an invention platform for the Internet or things”.

Mine arrived with a bunch of modules including Ethernet, OLED, relay and other modules but the basic setup is the Omega board itself and in order to  do anything with it, the base board which features usb, micro-usb and a couple of switches.

The package is interesting – OpenWRT Linux, a 400Mhz chip, 64MB RAM and 16MB Flash – not the kind of thing I’m used to – where the SBCs I normally review have a GIG of RAM and usually 8GB of EMMC or the ability to handle large microSD boards – this system has none of that.

OmegaSo the basic Omega board is small – but no-where near as small as, for example an ESP12 board. But then, an ESP-12 board won’t run ANY kind of Linux.

Having plugged the Omega into the baseboard the first thing I did was head on over to the getting started guide here.

I plugged the unit into the USB (for power) on my laptop and a pretty RGB LED on the baseboard lit up along with a dim light on the actual Omega.

A good start (as anyone who’s tested the Orange Pi PC will no doubt know, it really IS good to have visual indicators).  The instructions suggested that I should log into the access point created by the unit – of course that’s a great idea but I was using the laptop to read the instructions…

So I used my phone instead… the access point sure enough was there and connected immediately.

I logged into the page as “root” with passsword “onioneer” and sure enough a reasonably phone-friendly page came up to ask me for my WIFI details.

The device then said “configuring” for what seemed like far too long.  It could also only see two of my three access points – something that has never happened before. As I sat there I wondered if the phone had gone back to my WIFI access point – sure enough it had – so I pointed it back to the Onion and all was well – the device went off somewhere and updated itself. “You have successfully set up your Omega”.

At this point the instructions wanted me to hook up serially to the unit to get to the command prompt – I hate that so I had a quick look using the IP scanner and sure enough the Omega was on my network. I set up an SCP session (WinSCP) using the same credentials and I was straight into file manager of WinSCP and then via Putty to the command line. All looked very familiar but I noted that there is already a webserver in there and BOWER.

That was the setup tutorial here done – magic.

The next obvious move to my mind would have been to go to the documentation page here -

Sadly at the time of writing – it says “All pages in master” – followed by “there are no pages in master”.

Not really sure what to think about that.

Thankfully there was somewhat more info under “tutorials”.

In the tutorials was info for setting up a LAMP environment (Linux, Apache, MYSQL etc) but.. but  didn’t I already see a www directory. I opened a browser on my PC and just typed in

A lovely web page came up – with some interesting buttons…

onion Omega

The GPIO tool lets you graphically play with up to 12 GPIO lines – setting them up as inputs or outputs and sending values.

OLED on Onion OmegaI noted the OLED button and quickly plugged in the OLED display (without turning the power off – probably not a sensible move) – I pressed the OLD button and a picture of an OLED came up in the browser. The window was editable – so I typed in “Hi” into the window and pressed the button – lo and behold “Hi” came up on the TINY OLED display.

This was certainly getting off to a fine start – ideal for someone new – so many of these gadgets assume you LOVE arcane commands and hence put beginners off immediately. Up to now my grandkids would have no problem with this at all.

Trying to send an image to the OLED – I loaded up an image in the browser, I could see a black and white representation of it  (upside down compared to the text but never mind) – and within a second that same image was on the OLED. Very good.

The Servo expansion board allows it would seem up to 16 PWM outputs – and again all controllable via the web interface – a lot of work has gone into this.

Relay expansion – 2 relays – again controllable from the web interface – the only thing is  the relays are tiny and as I understand it NOT suitable for 240v mains  - so of limited use I guess.

You don’t actually need my chosen SCP connection as you can do everything via the web interface – there is an editor – a setup button, status and more – all VERY well put together.

And so for someone starting off – this is nice – within minutes you are up and running.  The price of all of this of course is another matter. All of these modules total up to quite a bit – see pricing here

If you want to control some lights – this is NOT the way to do it – but if you want to learn and are perhaps just starting out – the quality of the web pages and of the interface is FAR better than some of the stuff I’ve reviewed in recent months. Everything I checked just worked.

I did notice that they even do t-shirts in the store – and a quad-coptor.  I’m still busy puzzling over what on earth the latter has to do with anything.

Following an example – I pulled up the terminal, logged in and typed:

expled 0xf21133

Well, the nice blue LED on the expansion board turned pink! Success!

So… having concluded that the serial port is not needed as you can do everything via the web, my next job will be to find out if you can access said serial port – I could see a Nextion display being attached to this.

There are vague references to using multiple languages including node.js – could this mean that it will run Node-Red?  Sadly it might be me but apart from the examples I could not actually find “documentation” so for now that will have to remain on my wish list unless someone can tell me I missed a huge pile of documentation somewhere.

Here’s an article describing installing node.js but it’s a little old….

Definitely a good start and an interesting idea. Something for the holidays perhaps.