A Thermostat Weekend

tmp3C7AAs I make changes and I don’t want to bore readers – I’m adding sections at the top of this article and moving earlier versions of the stat down the page. If you are new to this you might want to start at the bottom at the point in this blog entry marked “The Old Ways”.

The Newer Ways: You will read below about last weekend’s work on the thermostat control – here is the link to the current code which now also handles a de-humidifier (not on a timed basis) and a heating using indicators built into the gauge (my thanks to the author for his help). The image on the left depicts the latest version.

Mobile Thermostat panel by Peter ScargillThe New Ways: This is about a DIY Thermostat in Node-Red – if you want to read about how I got to this point, start at “The Old Ways” then come back up here. If not, read on. Here’s a short video. So – you want a thermostat using Node-Red Dashboard (remember you can set all of that up on a variety of hardware alternatives using the script – which turns your little SBC into a potentially powerful central control system for IOT). Here it is.  You should be familiar with Node-Red, Node-Red dashboards and flows. If you need to know more about home control you could read all about it in what is now called the Home Control 2018 blog (quickly before I come up with a reason to change that to 2019). Lots of links in there to code for Esp8266s (ESP-GO) etc.

I’m assuming you have sensors and a relay board to control the heating and all you need is the pretty bit with glue in the middle, understand basic heating and are ready to go.

Here it is on the left – two days of solid graft. With this magic screen you can set up an entire week’s heating, controllable at hourly intervals – in a minute if that. Each hour can be poked with finger or mouse, adjusted and at the touch of a button replicated to the next hour. Similarly a whole day’s settings can be instantly replicated to the next day etc. You have control of the automatic temperature, with manual override as well as frost and stat settings and all on one colourful screen.

And if you don’t like it – it’s all there in source in Node-Red – what could be easier.  I must’ve made a dozen variations as you’ll see in “The Old Ways” before coming to this – what’s really exciting is that some of the control and display elements of Node-Red Dashboard are getting easier as I go along – at first I seemed to get no-where, now, the sky seems like the limit.

So – each of those coloured elements represents one of the 24 hours of the day – simply select by touch (the black bar will light up purple) an move left or right using the bottom arrows. The COPY button next to it will replicate an hour in the next one if you have selected an hour – or will copy a whole day if you’ve selected DAY. You can select frost and away settings and adjust temperatures there. On the top of the display is your actual temperature – and settings to adjust the SET temperature – and away from hours (>) to days (>>).  A is for automatic! When you have the settings the way you want them – use the disk icon to save or use the cancel icon to revert back to what you had before you started. That’s it – nothing else.  The data (a very small amount) is stored in your /home/pi directory but of course you can change that.

And here’s the flow you’ll be looking at – complete with lots of test buttons.

flow for the thermostat

This is slightly different to the code I’ve put up as I’m now monitoring actual temperature (the purple MQTT node top right – in the demo code I have kept the demo buttons).

The left side is entirely test material, storing values from your temperature and humidity sensors (the latter is not used as I ran out of room to display – maybe this week I’ll re-think the sizes slightly. I’m also pondering expanding the hour-day idea to hour-day-zone as I have two heating systems here but that will be later and I’ll leave this code intact).

Note: You’ll see some icons here – I’ve not distributed then as I’m not 100% sure of their copyright status – if you look around and look at an earlier blog talking about icons and .png files – there are no shortages of decent transparent .png icons for you to use – there are also a bunch of them built into Angular.

Temperature display from the new thermostatAll seems to work – in Chrome on the PC and on my HTC phone the displays are identical. Now – if anyone would care to ponder improvements – maybe find enough room in that right corner to get some more info…. do write in with ideas and code.

HOLD THE PHONE: I think I’m in love… check this beauty out on the right – found it HERE and modified the colours, text and size – a true work of art – quick modification in a browser and I changed parameters to make it do temperature (originally speed) change colour – etc…  I have it working in a simple local web page but sadly when I put it in a template right now – I get a white screen… I’m at a bit of a loss as to why.. if anyone wants to step in here….. it is so lovely it would be a shame to miss.

And finally: The original gauge here had a grey display with decimal points. I needed to get rid of those as I’m dealing in integers. I contacted the author Mykhailo Stadnyk

At the end of that – two new parameters – valueInt:2 and valueDec:0 gave me what I wanted – a simple integer degrees printout.

If you are using my flows – and creating directories etc, always remember that Linux and Javascript are case-sensitive – don’t go making directories/files  in upper-case and addressing them in lower-case.

Oh – LEDS –  I just found this – lovely CSS LEDs  – I need to figure out how to add one into the canvas.. I’ve also asked hr writer of that gauge if he’d consider adding in an optional LED indicator for me (boiler active).

The Old Ways: Here is where this all started.

As it happens, a few days ago, reader Antonio pointed me to a little ESP8266 Thermostat – well, some code for it anyway, using one of those little 120*180 displays.

ESP8266 stat gave me ideasI’m not that partial to Arduino development but I grabbed the code and stuck it on my hardware. Some great ideas there – but the implementation using a rotary encoder left something to be desired – and the code doesn’t support MQTT – and minus temperatures messed the display up. Oh and it seems to be partly in Italian and partly in English. Oh and a good but not especially long-lasting sensor is sitting right next to warm electronics and a warm display.

Don’t get me wrong, a STERLING effort and no doubt it will go on to be very good – but it wasn’t quite what I was looking for. It certainly fired me up.

As you all by now know I’m an MQTT/Node-Red/Mobile phone kind of guy and so armed with my new knowledge of Node-Red Desktop I sat down with coffee on Friday morning and started to put together some new thermostat code (as if I needed more). One of the things I really liked about the ESP code was the timing page you see above. I have 5 time zones per day which can be any temperature – different at the weekend – but not without it’s issues – what if the weekend is not your “special” time for example – and it needs lots of controls.

This on the other hand was simple. I got to thinking – but if it was on a touch screen you would not have all that selecting nonsense and what about replicating settings for every day and….

And so it was that I sat down with a gallon of coffee and did what I always do – plough in with the code long before I’ve put a plan together. Sometimes it works, sometimes it doesn’t. Hey, I’m a one-man team!

Templates on Node-Red: Well, this time it did and I’m chuffed, but before getting into this – a quick lesson on using TEMPLATES in Node-Red Desktop.

Templates are easy – pretty much you can make a web page in a template – you can even have includes and JQuery comes with the deal.  The problem I’ve always had in the past is getting stuff in and out of the template – the examples given really don’t help and I spent HOURS trying to get to grips with this.

Scargill's very first Node-Red thermostatWhen we were messing with buttons (see other blog entries) I got a lot of help from folk, most of it I understood, getting variables into the Template I most definitely did not – but it worked and now the light is coming on.  Remember the good old days of ASP programming and other server-side interpreted coding – you had this code on the server which was NOT in the same space as the code in the web page. Well, this is similar.

The likes of msg.payload sits in Node-red along with global variables, context variables  etc. They do NOT reside in run-time Javascript on the web page and that had me going in circles for ages. Well, there is a way around it, digging through the code we ended up with for the buttons I extracted this and modified it a little…

scope.$watch(‘msg’, function(msg) {
// do stuff in here with msg… which includes any part of msg, even arrays etc.

So here we are on the web page – in a script tag – and we drop this in. I know – what the HELL is scope (yes I know what variable scope is). I can’t tell you in detail but I can tell you it works perfectly!  As soon as you inject the normal Node-Red msg (entire) object into the template – where that // comment is above, you can use the lot inside that function, calling javascript functions etc. Note that in typical examples elsewhere – inside that function you’d see the word data – and I’d previously then used “data.payload” etc. – however, keeping the name the same (msg) makes it easier.

Along with the ability to fire out information back to Node-Red with this and similar for buttons..

ng-click=”send({payload: ‘hello world’})”

The first attempt: With that realisation I started on my new little thermostat. The most COMPLICATED page is that of settings – and the project above that I really liked – got me started as gives you 24 settings every day of the week. FANTASTIC – but I had to make it easy. Now, it is REALLY easy. You can set up programs for the entire week in a minute.

Over on the right – you see my FIRST interpretation of this – yes, it works – I just don’t have a relay fastened up yet to DO something.

Ok –  the colours were not that subtle – don’t be awkward – I only started on Friday morning after a fear-filled, anaesthetic-devoid double-crown fitting at the dentists via a 90+ mile round trip. – yes, I was brave though it nearly reduced me to tears – so bear that in mind before criticising my colour taste  – I’ve change it as you’ll see later. The buttons are simply Angular buttons with png images inserted.

So – you can touch/click on any of the timings – or temperature, or day and using the up and down buttons (they’ll end up as left and right arrows) you can change the temperature from one of the presets for that time or the time slot you are playing with or the day. The black line under the relevant item will turn purple (for now).

Scargill's very first Node-Red thermostat flow

If you want to replicate the setting on subsequent hours, press/touch the copy button as often as you need (auto-increment). If you want to replicate the LOT, click on the DAY and then on the copy button and you’ll start whizzing through the days (auto-increment), coping the entire 24-hour schedule across – you can then tweak bits later. When you are happy you’ve not messed anything up – press the save button.

Now this lot is simply stored in an array – 24*7 bytes plus 4 bytes for the temperatures – so as an array, stored on SD it takes up almost no room – by using a 2-level array you could EASILY expand this into different ZONEs – so as well as a DAY field you’d have a ZONE field and a copy operation would copy the whole lot to the next zone –  etc. Seriously this is a DODDLE to set up.

Finally a cancel button…which simply restores the array from SD – that function is also called at power up to get the values in the first place. I could probably do with a timeout on saving to avoid the (admittedly small) write to SD on every change. Still – not something you’d do a lot of.

So now we have a non-volatile global array with all the info in (I jammed the temperature settings on to the end of the array) – a separate page will show the temperature with a nice pretty dial, let you change manually up and down that for a given time – what, 4 hours before reverting to auto? and of course you’d want to show the humidity and pressure – very important they are all super accurate so I’m thinking a single BME280 would do the lot for you!!!

And that’s it – the output of “process heat” is simply the required heat value, sent out every minute. I picked a minute – could be 5 minutes – if you are working with, say, an oil boiler you really don’t want to be changing things rapidly. You can use this value to display in another page as the “set” temperature and to compare with the REAL temperature to decide what to do with, say, a relay.  Options might include a manual override – which should time out after a couple of hours maybe – and maybe a longer-term override in case you want shopping or are away for a couple of days in which case you might want to go to the lowest setting (offset zero in the global array) for some period. Normally for manual override you’d simply ADD your override figure to the automatic figure – i.e. 2 degrees WARMER or COOLER. My next job will be to do a nice job of the main stat display page.

The main page will no doubt also feature the local weather forecast – again from a previous article. One could even add a complete week’s predictions with icons.

More on this in near future – here is the current FLOW for this (no support and it WILL change in time) so you can just drop it in into Node-Red. Aren’t you glad you adopted the latter!

Scargill's very first Node-Red thermostatAuto-learning

To do auto-learning I think I’d change this – instead of 4 fixed temperatures I’d allow arbitrary temperature between, say 14c and 26c for every time slot (could do that now)…

Now, given THAT you could maintain a separate array – and every time someone makes a manual change – this would added to the second array (initially zero in all values).

After, say 4 weeks, you could divide the array down by, say, 4 (so that X degrees updated on the same hour for all 4 weeks would show up as one change) – and merely ADD that to the main array – clearing the second array. That way the system would have learned from the last 4 weeks changes but be ready to adapt to another 4 weeks changes etc. That’s one way – without getting too silly about it can you think of a more USEFUL way of adapting?

Thermostat – The Return of the Stat: Well, it had to happen – once I started writing about this – I started thinking how DAFT that 4-temperature limit is – and so  – well, I changed it a bit…   a lot, actually.

The panels now gives full control for every hour of the week but because of the copy system, it still takes only a moment to set the entire week up and it did occur to me that it would be a doddle to extend this to a ZONE system with umpteen zones, even.

I’ve also spent ages working on colours so as you can see – as you adjust the temperatures, the colour changes per degree and it’s quite pretty.  And there is status help.

I’ve added in frost and away settings as you’ll need those for the front panel controls (up, down, set away, set frost).

I have to say, it looks beautiful on my screen. I’ve stripped out a lot of  CSS and put classes in to make the code at least partly readable. There’s a timeout on all the message that appear when you press buttons – should be 5 seconds but right now they vary a little – any Javascript experts – feel free to take a look at the function – but it all works well enough.

Here’s the second flow – this supersedes my first attempt.  Oh you’ll need to find some images – and change links accordingly. On my Pi2 I have a directory /home/pi/.node-red/public/myicons with a ton of folders in there with png images in them – well you have to make use of all that space.  You’ll need to find your own – there are many out there – make sure they are transparent. But then – if you’re working with Node-Red and Dashboard, it really is worth setting yourself up with a good selection of icons and images anyway.

Oh – the data… in “Process controls” you’ll see that we’re looking at an array of 168 bytes plus 2 bytes to store frost and away temperatures – that’s it. See later articles as this has all been improved.


114 thoughts on “A Thermostat Weekend

  1. Hi Pete,
    for me the “away” function works only for the “days”.
    If I click the >> button, it increases the days, but if I click the > button, it increases just for 1h, if I keep pushing it, nothing happens.

    Another thing that I’ve noticed is that in the debug I often see this message: “TypeError: Cannot read property ‘tout’ of undefined” related to the “trigger 1 min”.


  2. Hi Pete, Just spent the day incorporating this into my HA system. Super easy and works lovely. Many many thanks for sharing all the hard work you have put in on it.

  3. Make sure you don’t have the com port tied up doing other stuff (i.e. serial monitor in the Arduino IDE). Otherwise, it all should work. I’ve found that sometimes I need to supply my own 3.3v power to the serial to usb (FTDI) adapter, depending on the PC I’m using and the ESP8266 board that I’m flashing but other than that, once you get the hang of flashing these ESP based units, they’re pretty much the same.

    I’ve flashed various sonoff devices (basic, TH10, TH16, slampher, POW) and provided I have a good 3.3v power into the device, have a way of invoking flash mode (by momentarily connecting the relevant GPIO pin) and the correct firmware for the flash memory size, I’ve managed to flash ESPEasy, Tasmota and Arduino based code to these devices with ease.

    That’s what I particularly like about SONOFF – they encourage the Maker community and make it relatively easy to replace their proprietary firmware with your own (or alternatives).

    1. Thanks Darren!

      As, 15 minutes earlier I had just finished flashing a Sonoff basic [ 4 of them done the same day and 16 basics all total] without issue and nothing altered on my laptop, other than connecting to a TH10 which failed, I suspect I have missed an important instruction or, like you suggested, maybe the 3.3 Vcc from the USB/Serial device is not up to the task.

    2. Like Darren, I built a programming fixture that contains its own 3v3 supply.

      If you are having problems getting a device to flash, put a voltmeter on the 3v3 wire to make sure it isn’t dropping below 3V.

  4. Is there anything different to be done to flash Tasmota to a Sonoff TH10 rather than Sonoff basic. I have successfully flashed 16 Sonoff basic units with this command

    esptool.exe -vv -cb 115200 -cp COM3 -ca 0x00000 -bz 1M -bm dout -cf sonoff.bin

    Just flashed a basic about 15 minutes ago but cannot seem to get a serial connection to the TH10

    trying to connect
    flush start
    setting serial port timeouts to 1 ms
    setting serial port timeouts to 1000 ms
    flush complete
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    read 0, requested 1
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed

      1. All the information on the wiki pages is how it is “supposed to work”.

        As both a Director of Engineering and Electronics Engineer and a former Technician I found quite often things don’t follow the book and that I why I posted on a site with people who actually use this stuff to see if anyone had any issues with programming a Sonoff Basic vs a TH10.

        When things fail, by definition, they are no longer following the rules be it human error or technical problems.

  5. Hi Pete,
    finally I’ve found a weekly chrono-thermostat that is missine even in most home automation sw (like DomoticZ, Home Assistand or OpenHab).
    I’ve tried to copy your code into Node Red, but it says that these are missing: ui_template, ui_group, ui_tab.
    What am I missing?
    Thanks and well done,

  6. Dear Peter, thank you for your fantastic work.
    I just have a backup and restore problem. When I finish the temperature configuration and I saved the settings, if I restart the PI I lost all the temperature program.

    Do you have any idea to help me ?

  7. Hi Peter

    This looks like a fantastic project. I am completely new to all this, and confused by the installation process of installing this and how to get the icons and gauge to display.
    I think this could be a great way to learn the systems used.
    Is there any chance of a short video or some detailed step by step instructions how to install this please.
    Thanks for you devoted work to this.

    1. Hi Laurie

      This was done some time ago and intended at medium level – I don’t have the time to do a training video I’m afraid. About the only problem I’m aware of that anyone has recently come back to me with is spacing – in Node-Red you need to adjust the cell sizes (in Dashboard – site) to widget size 56 * 40, widget spacing 3 * 9, group padding 6 * 6 and group spacing 3 * 3 – this is because all of this was changed at some point in Node-Red.

      Take it step by step, learning about how the various bits work as you go along – it will all appear straightforward after a while.

  8. Just been getting my head around Node red and really taken by the thermostat, had a play with it but struggling with the icons is there a how to on them as in how to install and where to as i would like to try this control as we are doing some upgrades to the heating and this might work well for this.

  9. Hi Maybe I can add my two-penneth to the suggestions re replacing a thermostat in the heating system.
    1 It would be nice to know what the current wiring setup is (S-Plan, Y Plan or some variant) and whether the existing controller, wiring centre and (if used) Mid position valve were being retained. Incidentally it would seem to be getting only part of the benefits whilst taking on most of the effort not to replace the controller along with the thermostat and missing the chance to utilise the Big Timer.
    2 If there is a standard Drayton wiring centre then all components are on a common neutral and uses mains level voltage to control the diverter valve and fire the boiler so I cannot see the inherent risk of using a Sonoff providing the correct connections are made.

    If I have misunderstood the advice or based my response on different assumptions I apologise, Also if the original query was asking whether he should connect Call to Neutral I would suggest he gets professional advice before he goes ahead as that will not work and may short circuit depending on other connections

  10. Hi Pete, i’ve drawn inspiration from your blogs and started building home automation with SONOFFS, tasmota firmware (which is by far the best ESP8266 firmware in my view in terms of simplicity to get running), MQTT and node-red.
    All working a dream, including connecting to homekit / apple, graphing, kitchen temperature and visual display with weather forecast., google cloud compute + cloudmqtt

    I’d like to now replace a really old room thermostat (RTS drayton) with a sonoff to control central heating. (https://www.diynot.com/diy/threads/replace-rts1-drayton-thermostat-with-simple-ac-on-off-switch.477064/)

    Have you any pointers as to how you’ve physically connected up your (as assume) sonoff to your boiler system. My worry is as sonoff has a shared neutral, if i get this wrong its going to blow something up.

    I’ve succeeded in getting the old thermostat off the wall and connecting neutral and live to sonoff to power it up, but little reluctant to what to connect to output..
    ie do i connect the same neutral + Call or live+call…


    1. I would not chance connecting live or neutral to the boiler controller. Much as I love Sonoffs, I always use a relay that is uncommitted, i.e. just a pair of contacts, when connecting to the heating system.

    1. Ciao Daniel

      I’d like to implement over your panel! How do you control heater when the temperature changes? I have a DS18B20 thermometer in my house, how do you inject the temperature into your thermostat?



  11. Going back to electrothermic actuator heads, these are the ones that Chris Dobson mentioned:
    http://www.plumbingandheating-solutions.co.uk/epages/BT4013.sf/en_GB/?ObjectID=22219355 (4 wire version) £13.71 a piece

    And here’s a slightly cheaper 2 wire version: http://www.plumbingandheating-solutions.co.uk/Emmeti-01213242-Actuator-head-with-indicator-2-wire-240V £10.98 each

    Interestingly these are in the category of underfloor heating but I’ve a feeling they fit regular central heating radiator valve manifolds..only a feeling mind you because I’m not a plumber.

    1. Certainly worth knowing about. A shame by the time you at VAT and postage the price goes up considerably – but still do-able. Can anyone confirm these would fit standard radiators?

  12. Peter
    It might be worth mentioning that the input temperature needs to be an integer otherwise the heat will turn at 20.99 if the set temperature is 21 for instance.
    I am currently experimenting with the input temperature rounded to 1/2 deg to see how that works out.
    Or maybe you could add some hysteresis into the thermostat?

  13. Hi. I have the thermostat working, but I am getting very irritating vertical scrollbars on the two-tone SET, AWAY and humidity blocks in the upper right. It seems the table is just a couple of pixels too tall for whatever container it’s in. Some bizarre css behavior I’m guessing, but I can’t figure it out.

    Just wondering if you have had this issue and solved it.

    1. Somewhere in recent blogs on this subject I have included some CSS – to get rid of wasted space – you should always have that on any page with my stuff in it.

      1. I’ve got the same issue with scroll bars. Did a search re wasted space and could not find the blog you referred to. I pulled the whole flow in and it does have a ‘css etc’ template in it.

        Could you point out where I’m going wrong?

      2. I am not a CSS expert but it looks like the box model on the ‘Set’ box (for instance) is not being calculated correctly. The outer box model reports as being 48×48, but inside this it is 31x 56 which is why the scoll bars are appearing.

        If in the Dashboard side bar I set the Widget Spacing as 12 and the group padding and spacing as 0 I can get rid of most of the scoll bars except the 3 with text in the top right.

        How to fix it is beyond me! 🙂

      3. I like a challenge and this bugged me.

        For me, to get rid of the scroll bars using the std Node-RED widget sizings and spacing;

        In the gauge template;
        I changed the size of the gauge to 156×156

        in the CSS etc Template;
        I changed the thead th style padding to 5,3,4,3
        I changed the tbody td style padding to 5,3,5,3

        In the Settings template
        I changed the main table tag to
        width=”318px” style=”border-spacing:0;”

        It isn’t absolutely right as the height of the settings is less than the 318px it should be so it needs a little padding out but for the moment it works for me 🙂

  14. Hello,
    i install your flow on my C-1, but i have little problems, i have 3 rooms with heating convector’s with 2 heating head + 1 wind fan, i correct code for my configurations, but when made 3 copies of thermostat they show same measures and controls.

  15. Using today’s code I’m having issues displaying the default 40% under Dehum – it is just saying ‘undefined%’ , so highlighting and using ‘<>’ just displays ‘Hit limit’ – everything else is working fine, including my feed from nr for temp/humidity.
    petesstatlog.log is only showing timing 0-169 , 170 is not saved.
    Any ideas appreciated.

    1. See latest update as of 5 mins ago – all appears well now and I’ve made some changes – read the comment under the snippet.

      1. Peter,
        I’m still have the same issue with the latest code – I reinstalled your code and deleted log file.
        Dehum still showing ‘undefined%’ instead of 40%, after doing a ‘save’ checked log file and it did not have 40 at the end, just default away temp of 14 – but your script in function(process control) has added 40 to context.global.timing.
        I added 40 to the log file, did a save and rechecked log file and it had been removed.
        Thanks in advance

        1. Can you clarify – are you saying it works but the code is wrong on the page? I’m off shopping – if you can clarify that I can fix it later.

          1. I am unable to set the Humid value, as it always displays ‘undefined%’ – trying to increment/decrement the value fails because it is not seen as a numerical value.
            Your script in function(process control) shows 40 added to the context.global.timing array, but if I do a save, the humid value is not at the end of the petesstatlog.log.
            Had a quick look at the code, but couldn’t see where the issue is.

        2. Allan – all I can suggest is to shut down Node-Red, delete the file with the stored values and start up again at which point the file won’t exist and the array won’t exist so it will be created with defaults… as I can see no reason why you cannot write that value. The array is big enough… unless you had an earlier version running and you’re restoring from that. I can’t reproduce that issue here.

          That of course is always a possibility and will continue to be so as what you see is merely intended as a starting point for others – it will mutate and change as I learn more.

  16. Hi Peter

    I’m a silent reader for some time now. First, thanks for all your insights you give to this community. I’m about to automate my home slowly with a couple of RasPi’s, some SONOFF switches, SONOFF LED and other devices and sensors. Automation is done trough a combination of Node-Red and Home Assistant. Alexa is the main input device. To keep the whole thing “wife friendly” there will be an old iPad with Node-Red Dashboard in the future.

    The main reason for this comment is your search for gauges with integrated LED. I found this HTML5 gauges which look quite good: https://github.com/HanSolo/SteelSeries-Canvas

    I did not try to implement them with the Dashboard yet, but will soon. Maybe you take a look if you have some spare time 🙂

    Best regards from Switzerland,

    1. Hi Cello

      Yes, seen the Steel Series – good – but look at latest Stat update – the one I’m using I’ve now added a heating LED – and I’m almost at the point of understanding the CANVAS well enough to make improvements – I say almost – because I just added a humidifier indicator – looks lovely but doesn’t actually work…. still – the day is young.

    2. WELL – I went off to have a look at the SteelSeries (I don’t particularly like the steel finish) – anyway as you do I got sidetracked and noted this –


      So I opened a DOS box in Windows and tried the demo (it is “gradlew demo” in Windows, not “gradle demo”) – WOW that looks impressive!!!!

        1. Cello, yes I know how you feel. I’ve played with the Steel Series outside of Node-Red. I do intend to figure out how to drop them in but that’s not on the top of the todo list.

    3. As you will see Cello – I have embraces the SteelSeries full on!! Couple of things – there don’t seem to have been developments for a year – and I’d like to see more examples of changing the styles – I don’t like that thick border and I’m not that keen on the steel colour – but technically – they are superb…

    1. Hi Herve

      I would say that control is pretty cool – my only comment being that it could do with a spot of colour. If those marks all the way around could start in blue and end up in red, then I think we’d be onto a winner.

  17. This is so cool. Has anyone got multiple instances/zones going yet ? I have tried running two, by going through all the code in one changing the varables names in one. got the top half working, but settings bit …..Ruined! Start again.
    Thinking……Rather than run an instance of this for each room, just have the one with a “Room/Zone” Select, same as how the “Day” Select works. Then the basic settings (top half) could be for the user, on a Nextion Display for example. And the settings (bottom half is only available in the ui, away from all the twiddlers in the house.

    1. I suggested that earlier – an array of arrays – and expand the copy metaphor to copy from zone to zone – I definitely need 2 personally.

  18. Hello,
    In my home automation I successfully use Honeywell MT4-230-NC valve + relay and esp board to control it. The prise is about 17 euro. Only downside is switch time – it takes about 3-4 minutes to open/close valve after relay is on/off.
    Best regards,

  19. Hi Pete,
    really good work. Thanks for sharing.

    I’m hacking a bit your flow to learn node-red-dashboard secrets and adapt to my needs.

    I think you can simplify templates using angular directives without using “scope”. To clarify, I changed the setview node to a single line without scripts:


    I have a question about nodes returning multiple outputs. Why you use send function instead array? Docs says to use send with async operations, but I don’t see any here.

    For example, I canged a bit the “Process heat” node returning 3 output and using this syntax :

    var temperature = {payload:msg.temperature};
    var rele = {payload:msg.relay};
    var desired = {desired:msg.desired};
    return [temperature, desired, rele];

    Is that correct?

    1. Hi there.

      I’m using scope without issue with the versions of gauges that are set by Javascript but at a total loss with the versions that are simply HTML and Canvas – if you would care to provide a short example of such code merely using Set {{msg.desired}}c I’m sure I and others would love it. Seems ot me that works for static elements but not dynamic things like gauges – I am more than happy to be proven wrong.

      Sending back arrays – sure – logically that is the sensible thing to do and I often do that – I also often do it the way I have done here and both work just fine. But in your example I’m not sure I see the difference between that and the simpler…

      return (msg);

      Fire away..

      1. Sorry Pete,
        in my previous comment the HTML is not escaped. I don’t know how to insert HTML inside comment 🙁

        Here how I changed the setview node (showing setpoint as number inside HTML element):

        I never tried to use that directive in a javascript gauge, I’ll try and report.

        About sending back messages: you are right if you want return a single message with several payload properties.

        But if you want return multiple output (here the case of “Process heat” node where I now return 3 outputs points) I think an array should be returned, as described in node-red documentation.

  20. i replaced all my TRV’s with Thermo-electric actuators from emmeti.co.uk. about 12 quid each. Each one is switched by a electrodragon / sonoff, with a temp sensor attached. Node red reads /fromesp/auto-temperature from each one into node-red-contrib-ramp-thermostat. with node red ui & basic Nextion as interface. had this going about 3 months now and our gas usage is over 30% less !
    It is all experimental at moment (thats what i tell the wife when she goes on about “tripping over wires everywhere”) but results seem to be very good.
    i have a bit of a limited knowlage of javascript and linux but this blog and google really help me fumble my way through. My UI is very basic using only buttons & Gauges from the UI itself, so this really is going to improve things. I will hopefully, eventually, be running 12 instances of this in node red. But before i start. Where do i put /myicons/png/48×48/actions/The Icons.png. have put them in root, home,home/pi, home/pi/nodered, but the template can’t find them?

    1. Hi Chris that £12 sounded interesting but I went to their site and could not find prices – got a link??

      Put them in home/pi/.node-red/public/myicons

      Then in the /home/pi/.node-red/settings.js file you need..

      httpStatic: ‘/home/pi/.node-red/public’,

      So then the web pages think that the root page for all assets is the above – hence your reference in the web starts at /myicons..

      The reason I use myimages and myicons etc is that Node-Red already has some directories it uses for UI and images is one of them – if you make an “images” directory it conflicts – so I just prefix any of my stuff with “my”.

    2. Chris D

      Do you have an item code for these? I have trawled the 35 page 2017 Selling-Price-List.pdf but could not locate them.

      1. I got them them via a plumbing merchants(John Nichols Witney), as i am heating engineer. Emmiti are right on my doorstep but wouldn’t sell me them direct. i will try dig out paperwork tomorrow…..Found it!
        01213252 Emmeti Control T heads 230v £12.22 + vat.
        90039364 Emmiti adaptor for control heads (pack of 12) £1.13 + vat

        John Nichols Witney 01993 705566

        These are working very well, and are only let down by my pidgon javascript. Some time ago i bought about 15 x 24 volt thermo actuators off ebay. and i built a lovely controller using wemos D1 mini, SPI expander , relay board and power supply. all in a metal box and running Pete’s code of course. (Wemos Di has external antenna connector, and i like metal boxes, just in case something goes wrong!). But this requires running wires to every radiator in the house, and i am just too busy at moment to find time. So i currently have sonoff’s and electrodragons in each room. Each of these has a temp sensor connected. I also built a 8 channel temperature sensor (arduino based to get multiple sensors on one esp)that was to compliment the relay controller. but i feel a bit unfaithful to HC2016. And its a bit flakey.

    3. Another request here for an item code please Chris. I can’t find anything on the site to match that doesn’t have a 3 figure price tag.



  21. Pete,
    On the subject of heating etc, This is a great alternative if you don’t have smart meters – and it only costs £59. (I’m not assocaited with it)
    Can’t recommend it highly enough and its saved me many multiples of the purchase price.
    Anyway, for a one-off cost of £59, you get two measuring devices (electricity and gas) which you install (easy enough) and they send the data over your broadband to their website which you can access for free.
    You can see your consumption in nice graphs per hour/day/week/month and you can download the data (node red maybe!)
    Not only that – the website also recommends alternative suppliers depending on your usage profile.

    Not only is the data thing interesting and certainly still helps me to pinpoint where the energy spend is going (do you really want to heat that room at that temperature?), it has helped me save at least 10 times the initial purchase cost just by taking up their recommendation of suppliers.

    1. Hi Pete…

      Can do all of that with Imperihome for free with as many sensors as you want to use.. It is written up in previous articles. Despite my enthusiasm for Dashboard, the Imperihome display of graphs is very good – I also made a node for Grovestreams – this time online – free within reason – and you can combine graphs which is nice.

      1. “Can do all of that with Imperihome for free”
        Eh no you can’t Pete, and you’re delibrately ignoring the cost of your R.pi, 2 sensors and the time needed to both write the software and to regularly update it with the “deals” available.

        If you want to construct a heating system, its a good idea to get metrics on how your energy consumption is affected – This just seems an easy way to do it and I don’t think a cost of £59 is that much for:
        – Gas flow sensor sensor
        – Electricity meter sensor
        – Sensor hub that connects to your router
        – Free Data hosting with flexible display in the cloud
        – Ability to compare your usage to others
        – Money saving proposals comparing today’s market with your consumption profile whenever you log on.

        What not to like for the “ordinary man?” 🙂

        1. Not deliberately ignoring anything….. Orange Pi under £9 inc shipping


          2 sensors, cheap box, power supply same cost again, relay another £1… so what… all in £22-£23 and so much room to expand..

          Software need patching, not writing – most is out there already. As you brought it to my attention I’ve just been on Grovestreams (node is out there – I wrote it – works – all free) comparing temperature and humidity for the last year. Had I not decided to change how I do things I’d have had it for the last 3 years.

          I seriously doubt that this blog is being read by “the ordinary man”. And it’s nice to get everything in a box – but that’s for other people, other blogs.

          However – you’ve put the link up so anyone interested can go take a look.

  22. I don’t know the language you are using, but, would something like the non-blocking delay in arduino code make your timeout more consistent?

      1. I realize you aren’t using Arduino code. I just thought the concept might transfer. The gist is to have code that looks at the internal counter and when 5000 mS or more have passed do something. In your case something is making the dialog disappear.

        1. Oh right – no – Javascript has that stuff built in – far more powerful – however – it doesn’t seem to be even remotely accurate sometimes – something I’ve done no doubt – but usable.

  23. In case anyone is wondering – I’m quite because I’m working out a bug – I’ve extended the display to show temperature in a nice dial at the top – all fitting in a standard phone display – but I also need 2 buttons for up and down and a display of the SET temperature – along with frost and away settings – just having a hard time with a variable – later today I will likely post a big update once I’ve cracked it.

    1. Have noticed a small issue. I increased the frost value by accident but now I can’t put it back down to 6, due to it not letting me. 12 degrees seems to be the lowest I can set it to.


  24. I would not class myself as anything like an engineer – a title I respect – but the very first thing I did when I left school – going into an engineering company was to get my qualifications as a heating and ventilating technician – our family business made warm air heating systems for industry and the home – including our own. I’ve been interested in home control for… well, it’s all in my CV somewhere – a long time – and monitoring temperatures for many years. The only way to get a true gauge of temperature is to put the sensor AWAY from sources of heat and even THAT isn’t perfect. Take a calm, draft-free room – put your sensor at ground level for 15 minutes and take a reading – then put it at ceiling level. You may be surprised at the difference. Add in a fan and that ALL changes. About the best you can do IMHO is opposite side of the room at maybe eye level. Chris may have a different view on heights.

    The point is – the sensors are wireless using ESPs so not a big deal to dot about the place. Now if wireless, MQTT-controlled, battery operated radiator valves were cheap – that would open up a whole new world of zone control – but they cost more than a Raspberry Pi!

    Go on – someone prove me wrong and point to a dirt cheap WIFI or Bluetooth controlled radio valve we can use.

  25. Autolearning beings back memories of Nyquist and Bode plots. (!)
    From what I remember, If a system is compromised from the outset, It’s impossible to bring optimal results to it’s outputs. i.e. Desired outputs “responsiveness” while damping offshoots and oscillation from any combination of input condition frequencies (e.g. for heating, it would be variances over a day due to outside temperature, bedroom/living room radiator switch on)

    So, any proper “Control Theory” analysis for a heating system is unlikely to satisfy what people want ,because their existing heating systems don’t have all the necessary bits and pieces needed e.g. individual room on/off thermostatic radiator controls and PIRs.
    These things are needed so that the “house computer” can learn where everyone is and goes to – so that the “house computer” can build a picture of when to switch off radiators. e.g. bedrooms after 8am during the week.

    So, after thinking like this, I’m wondering if the best device to come up with would be a PIR / Temp sensor with ability to enter “desired temperature” and occupancy (“I always sleep here”). This is so the physical heating system would have these extra things
    – PIR/Temp/data entry “thing” in every room
    – Wifi (Thermostatic?) on/off valves on every radiator
    – Outside temperature sensor

    All the above interlink to some sort of hub software that records the presence of people in rooms, and automatically adjusts water temperature and boiler times. It is this hub that shows all the temps etc, not each individual device.

    Just some thoughts here

    1. And way too complicated for ordinary people – remember – people who don’t read blogs like this often have trouble with tv remote controls! I spent far too much time thinking about this and really there is no solution that is perfect – especially with a single control point.. but I do think it is worth monitoring repeated manual alterations and if they are regular, then taking that alteration into account in the settings. Another way to do it would be to store the temperature scaled up to 16 bits and whenever a change is made, to alter a fraction of that to the temperature for that day and hour… so that if done over and over, eventually the default would become what the manual changes were intended to achieve – well, almost because as the system learns, people would be making less changes so you never quite get there.

      However, I remain very pleased with the new control so far, I’m not pleased with the accuracy of the timeout after status info – but that’ll come out in the wash in time.

      I may actually add the current temperature and humidity to this display and keep the end-user controls utterly separate – basically a display with up and down controls.

      More coffee first.

        1. It could be just me being slow – but I have never seen the point of radiator valves. Who in their right mind would put a temperature sensor right next to the source of heat. I always put my sensors at the opposite end of the room to the heat source!

          1. “I have never seen the point of radiator valves”
            Pete, I wish I lived in a hot climate and could say that!

            “The replacement of a manual heating control with a TRV has been estimated to save at least 280 kilograms (620 lb) CO2 per year. They are also considerably cost-efficient, using heat only when needed, and can reduce heating bills by up to 17 percent a year.
            As of 2012, electronic TRVs are becoming available which use electronic temperature sensing, and frequently contain programmers so that individual radiators may be programmed for different temperatures at different times of the day. Such increased control allows even better energy and CO2 saving

            1. Trust me it is FAR from warm here in the Northeast of England. I’ve no problem with controlling individual radiators – but to put the sensor right next to the heat source – I’m sorry – is just plain daft. Depending on air movement and rooms size you could end up with an utterly inaccurate control for the rest of the room.

              I think they may be mandatory here in the UK – the first thing I do is take them off.

          2. in Italy, for buildings with centralized heating systems, they’re MANDATORY from december 31, 2016…

    2. How about: modulating heating systems, get temperature from the internet for your place adjusting your water temperature, protocols and API’s to control the existing heating system(like OpenTherm and a few others)?
      You complain about you never get the display right and reliable in special situations! Are there not enough experts(6000+) following this blog who can solve this problem?
      Just some thoughts!

      1. Well, I get the outside temperature from the Internet, I get the internal temperature from a BME280 along with humidity and pressure and the display is now right. All problems solved – and if you think about it – over a long period of time – what has led up to this moment is partly because of people in this blog filling in gaps in my knowledge. We could do with a wider range of input – (I hope those who read but don’t write are taking this in – your ideas are always welcome).

        No problems – only opportunities (and it’s 6,300+ now! – Christmas surge)

  26. Thanks for that and I’m not out of ideas yet – I’m having temporary feelings of suicide because this damned CSS is beating me..

    .thetemps { font-size:70%; color:#888888 !important; }

    Ok, so that applies to the tiny little text showing temperature above the bars (my idea – didn’t steal it from anywhere else)…..

    So we’re talking about the text I’ll inject into V11 with $(“#v11).text(“12c”) or similar.

    I just cannot see why the colour command – even with !important clagged onto the end, is being unreliable…. it’s driving me nuts!!!

    1. As i have no idea what information a nest has – it would be down to you to figure out how to get Nest info in there – but… doesn’t the Nest do all this? What info would you want to pass from a Nest?

          1. I generally agree with you on that – but as I’ve found out – it really isn’t quite THAT simple to ensure that the tablet will show the web page without borders or menus AND always come up – AND always recover from failure.

            My “litmus test” – would I feel comfortable leaving said tablet on the wall in a holiday rental cottage – oh, like http://www.hollyberry-cottage.co.uk for 6 months while I was enjoying the sun in Spain!

            I did that with the Nextion display – no problem.

            1. “My “litmus test” – would I feel comfortable leaving said tablet on the wall in a holiday rental cottage”

              I love your litmus test for the usability index of a home IOT system. Around here, we call it the Grandma test- if Grandma can figure it out, we have success.

              I have been experimenting with various GUI kits with a touchscreen on the Pi. Tkinter is my current favorite, LCD-Show library is much easier to use, but you have no control of button placement or size. My problem is that every library for the Pi simply moves the desktop to the touchscreen. Meaning I still have all the taskbars and other confusing (to Grandma) icons across the top.

              Thanks for the mention of the Nextion display. I ordered a 3.2-inch enhanced board from Amazon to experiment on my bench. Does the esp8266 board that you designed make it so that I can put all of my controls into an mqtt payload? I don’t mind building things from components, but I have had absolutely no success with SMD components. Can you share the schematic so that I can make it with through-hole components??

  27. Pete, This fantastic!! I’ve been following the blog and a new thermostat is next on the to do list. I’m loading your new script as I’m writing this and will drop in and play with what you have up so far. Currently working on the ability to turn on and off the Snow and ice heaters on the roof of the second home in the sierras. Would be nice to warm the place up a bit just before arrival.

    1. HAH – clear the cache on your browser and see the NEW SUPER version at the END of the current blog – I’m still working on the classes so I’ve not put the flow up yet but it’s working perfectly – WAY, WAY better way to do it. Full control for every hour from 14c to 26c (arbitrary based on doing holiday rentals for years). I have to say I’m enjoying this… Guess I’d better go into the house to make sure everyone is still alive.

  28. Hi Pete, HNY (HPY everyone)
    > you had this code on the server which was NOT in the same space as the code in the web page

    Yup, I’ve run into that also and I like to use websockets for this. I pass the json updates to the page as needed. Not sure how this will work with the above but I’ve loaded it up on my home setup and I’ll play.

    1. There is a flow up there in the link you can use – but I’m thinking already of changes (I’ll leave that flow there. Thinking out loud I fail to see the point of the 4 fixed temperatures – why not any temperature for each point. That makes machine learning easier as well.

      1. hey PETER that was amazing .
        But i want to code in respberry pi where i can auto adjust the light according to the intensity of light of the room and also to adjust the fan speed automatically according to humidity of the room . the pir sensor will also work good to detect if there is no person in the room . This would work better for a office where there is wastage of electricity .
        can u help me to make the flow in the node red.

Comments are closed.