Home Control The Next Step

NETIO screenAs regular readers will know I’ve pretty much gotten to grips with the whole home control thing having after much research settled on a largely MQTT-based setup using the excellent new Raspberry Pi2 as a hub with Node-Red.

Though it could just as easily have been any proper Linux or Windows based setup, I could not justify in my own mind using an expensive piece of kit to do this as I’d previously been using an ATMEGA1284-based controller of my own design which cost just about nothing – but was constantly worrying about running out of resources on this – and then along came the Raspberry Pi 2.

Funny how things like that make a step change in how you do things and so it is again with the controller side of things – read on.

I’ve messed around with a number of solutions for the remote hand-held part of home control, ranging from simple infra-red controls, through radio, but always coming back to the not-too-well supported NETIO. I say that as it takes AGES to get changes made. The product costs very little, sits on Android or IOS phones and makes for a very pretty button-and-icon interface for home control – a LOT prettier than most of the other solutions out there and a lot easier to use – basically you move items around on a browser-based IDE, change properties and Bob’s your uncle.

The problem with this up to now has been the way NETIO handles the interface with your home control. It can use HTTP and UDP but I prefer to use a simple TCP interface. Up until now, each button or icon on NETIO would send a message and expect a response. So a button would send a message when pressed and simply need an acknowledgement.  An icon to say show the state of a light would regularly request updates and expect the status to come back. The problem with that was – if you expected a quick response when pressing a button you would be disappointed – imagine the icon requesting a response every half second in order to stay updated – and you had a dozen of them on screen at once-  that’s a lot of updating and on a poor connection this was disappointing.

Until now there was no way for a button to talk to it’s own separate icon. That has now all changed. NETIO now features event-driven operations, that is the home control system once the TCP connection is made, can arbitrarily send a message to the phone and to one or more icons at the same time. Each icon is now responsible for checking to see if a message is for it.. and that is done with a simple regular expression.

Trust me – this is a major step forward for this program – as it enables almost instant feedback – rather handy if you’re not in line of sight of the item.

Ok this all sounds really painful but it isn’t.

If you take a look at my picture above – one of my test pages, there are a bunch of on-off buttons and indicators.. The indicators need to do two things… at power up they need to poll the state of whatever it is you are controlling – that is so as to set their initial state. From there on they need to be watching out for messages which could come at any time. Each one must have something unique so so to identify it.

NET Control

On the NETIO control page here on the left you will see there is a READ instruction – that is to read in this case the state of the GPIO control on the Raspberry Pi2.  I’ve adopted the vertical line as a separator. So gpio?|0 sends off a string to the Pi which is picked up by Node-Red and sent to a function, which then returns (let’s say the light state is 1) status1=1

The parseResponse field will only do anything if the incoming string contains “status1=” and then pulls out the value to determine which of two images to use for on or off. The point here being that not only can this icon request the status – but any other event can return status1=1 and affect the icon, so you get a one-off refresh on power up and then whenever you change the state of a button, a message is sent from the Pi to the phone to change the state of the icon, in most cases instantly – no more polling.

And there you have it – the ability now to have WAY more icons than before on a page without ridiculous amounts of polling – If ONLY the NETIO author would do this via MQTT it would be SO good but for now this is just about the easiest interface out there without the limits of some predefined program. There are plenty of icons in NETIO and you can add your own images at any time.

At the Node-Red end…


There is an incoming TCP connection from the mobile phone, that data is processed in a simple function (and in the case of the simple local IO pins I store the outputs in a database but that’s not relevant here, nor is the MQTT output) the outputs are controlled as requested and also a TCP reply is sent back out to the phone. In the case of queries, no outputs are modified, the state of the outputs is picked up from global variables and send off to the TCP output…. a simple string.

House-building is commencing in the new cottage – the electrician is putting in my networking cable and ensuring I have a wire coming from most lights etc. to offer an over-ride function to normal manual control – once our boards turn up they will be pressed into service using a vastly expanded version of what you see above. It is all coming together.

If you want to keep up, subscribe to this page – or subscribe to my Facebook page  https://www.facebook.com/esp8266wifi and if you have ideas for improvement – fire away – there are some great conversations in here.


4 thoughts on “Home Control The Next Step

  1. Your video ‘My current work with Node-Red on the Raspberry Pi 2’ and this article have been a great help to me getting NetIO,mySQL, MQTT and node-red working on the Pi2.

    However, I’ve been unable to update a label icon in order to toggle lamp_on / lamp_off. Using an NetIO on the iPhone and the NetIO Raspberry Pi Demo config and the netio_server.py from the NetIO website the lamp_on / lamp_off works a treat. I then tried a simplified node-red flow using tcp in, a simple function node looking for get_status, then tcp out with payload: “on\n” and a simple NetIO config with a button and a label with icon = lamp_off, parseResponse=.*$. formatReponse=icon_lamp_{0}.png This failed to change the icon to lamp_on.

    Changed node-red flow and NetIo to UDP still didn’t work. I also captured some of the network traffic and looked at it in Wireshark. This showed that when using TCP there was no response from node-red to ‘on\n’ I thought I sent via the tcp out node but when I used UDP the response data packet was hex 6f6e0a (on\n). This was the same data that the net_server.py returned but netio_server response changed the icon!

    Would it be possible to get a copy of your NetIO config and the Node-Red flow you describe in this article to help me figure this out?

  2. Well after trying both Openhab and Openremote, I finally decided to five Netio a try. Took me ages to realise that it’s not something you can actually install and run on the Raspberry pi!

    This now gives me much more resources for running node red on the pi. Netio does seem easier to use than the other two and I was starting to get quite annoyed with Openhab, so Netio and Node Red seem like a good match (now I figured out for to actually send data via tcp…).

    So I’m now trying to develop a similar system to yourself using Netio, node-red, raspberry pi, and a number of esp modules.

    1. Let me know how you manage. I am having a little difficulty. With 4 indicators on NETIO, using event-driven mode, they all send a request back when the page opens – then at regular intervals after that. I had to add the 2 seconds repeat as they do not always send the right information out initially – I don’t know if Node-red is not picking up the data quickly enough – or whether they are failing to send out the right information – it is hard to tell. it seems that sometimes 2 or more commands get merged together. When I put a 2 second timer on them I got a similar problem so I staggered the timer slightly and the problem completely went away.

      1. So far I only have two temperatures being read (Raspberry Pi CPU temp a mqtt temperature reading from an ESP board), and only one button, so I’ve not had a chance to test several calls close together.

        However, so far it seems to be working ok. Though soon I’ll be adding more to the system so might come across those issues. Will let you know if the outcome.

Comments are closed.