Node-Red Thermostatic function

So – I was asked recently if I would go into detail about the Node-Red thermostat node I wrote some time ago.. I was at pains to point out that I’ve not developed this further because I’m finding FUNCTIONS to be more useful. With the latter it is easier to just “dig in” and make changes – important when you’re developing..

The whole flow of my Thermostatic controls with add-ons, bells and whistles is way too much to go into – however the central function – the bit that controls the temperature is really quite simple.



There it is – so every 10 seconds it runs, reading some global variables and outputting an MQTT message to turn the heater on and off. As you can see it gives a summary underneath (I know the Node-Red guys are not keen an adding visual elements but that status display was a GREAD add in to functions).

And so the output just goes off to an MQTT node to turn the heat on and off. But what’s inside the function?

I originally put it in here but it is so long it will bore the PANTS off anyone only vaguely interested so I’ve put the entire code into a snippet on Bitbucket.

So just a couple of things to help with anyone wanting to look at this – PLEASE don’t ask me to support this as by the time you read it I’ll probably have changed the original – it’s a work in progress.

However reading the code above you’ll need a little help.


The above is just me being lazy – “stat” allows me to access the global var and it’s bits without having to type in the long name – I’ve a large object full of things like 5 sets of times per day during the week, same again for the weekend – each with an accompanying target temperature, there’s a manual offset to the temperature and last but not least, in the ESP board (MQTT) that is sensing the temperature I also control some serial LEDS to light it up blue when the heat is off and orange when it is on  – that of course is totally over the top but I like going over the top.

There is also a frost temperature setting in there… most should be fairly obvious and if anyone wants to cannibalise this for their own use – by all means.