DIY Smart Home EP4 – Smart Heating & Custom Automations

Hi and welcome to episode 4 of my DIY smart home series – last episode we covered a whole lot about Home Assistant, custom components and lighting controls, this time though is all about making my heating even remotely intelligent. And that starts with this, the MOES BHT-002-GCLZBW Zigbee thermostat, and two of these SONOFF SNZB-02 Zigbee temperature and humidity sensors. Assuming you already have Home Assistant up and running as covered in episode 2, and a Zigbee dongle, also in episode 2, that’s all you need!

Getting these tiny temp sensors running is super easy, pop the back off and remove the battery protector tab, then stick the included 3M adhesive pad on the back and stick it somewhere. Ideally not directly next to a radiator, but somewhere that can get a representative sample of the room’s temperature.

As for the thermostat, there are a few things you should know. First, make sure you get the right model. As shown by the silk-screen text on the PCB, this comes with either WiFi or Zigbee for communication with other devices. I can’t stress this enough, make sure you get the Zigbee version, not the WiFi one. To see why, check out episode 1 of this series. On top of the connectivity, there are actually three different version of the Zigbee model and again you’ll need to be careful to get the right model here too. My boiler only needs two wires just connecting together like a switch, but if your boiler (especially electric water heating style units) need to be actively powered through the thermostat you’ll need a different model to me.

I got the C model – GCLZBW specifically, rather than the A or B versions, which takes 4 wires in: Live; Neutral; Dry contact 1; Dry contact 2. Those dry contacts are the two wires from the boiler’s room-stat pins. Seeing as I’m not a qualified electrician or plumber, I’ll refrain from giving you much advice on installing this yourself. I’m confident in my knowledge and experience, and understand the risks involved, enough to install this but I’m not confident enough to be giving out at level of advice. This is legitimately dangerous, hell even the dry contact pins are live at mains voltage so if you aren’t sure, have a professional do this for you.

Once it’s all hooked up though, you’ll want to have the thermostat powered but switched off so the central LED ring is orange, then hold the down arrow for around 8 seconds, then head back to Home Assistant and via our Zigbee Home Automation integration search for new devices. You can press the pairing button on the temp sensors now too so they pair up too. Home Assistant should automatically find and connect to them all and will even automatically add them to your Home Assistant controlled dashboard – and yeah, works exactly as expected. Perfect!

Except, it’s not all that smart. It only bases it’s control on the temperature sensor built into the thermostat, not the temperature sensors we have connected and installed. Now, much like the lighting control in the last episode, there are a million ways to automate this to achieve similar results but for the purposes of this video I want to walk you through some slightly more advanced automation methods.

Home Assistant itself has ‘Automations’ built in, they aren’t the most user friendly but it’s worth having a quick peek. On the Automations page, when you click the add automation button you will be asked if you’d like to use a Blueprint or start fresh. Blueprints are basically automations other people have already created and you just need to tell it what devices to use and any little tweaks you want to make, whereas starting from scratch means you have to build it yourself. Here you have three main things: Triggers; Conditions and Actions. Triggers are what start the action – in our case that could be the temperature in my office gets too low so once it does that will kick our automation into action. But, only if the conditions are met. Like, the heating has to already be off, the temperature is low enough and even if I’m home. Finally there are the actions. This is what to actually do, like turn the heating on.

These are a little limited, or at least they are a pain to deal with and personally I find them really unintuitive to work with, so let’s use something else instead. That ‘something else’ is an Add-On you’ll find on the Add-On Store, called Node-RED. Once you install it and likely restart Home Assistant, you’ll also want to head to HACS and install the Node-RED Companion integration too, restart again, then you should be good to go.

Node-RED is a flow-chart style programming tool, you have little boxes with lines you click and drag between other boxes to connect them together. Now I’ve already got my main flow, my “code”, set up so let’s create a new tab here so I can explain the basics. On the left you have all the nodes you can use, grouped in sections like Home Assistant or common. In the middle is your code space, this is where you drag new nodes into and hook them all up. If you double click on a node in the middle section, you’ll see it’s properties on the right, and further right is more info – although you’ll want to click on the little bug icon as that is the debug console – your best friend when building these flows.

For debugging purposes, the “inject” and “debug” nodes are the two you’ll use the most. Inject basically gives you a button in this window you can press to trigger your ‘code’, rather than say having to wait until 3am AND the temperature in your room drops below your threshold. And the debug node? That dumps information to the debug window so you can see what’s going on. The main idea is that these nodes pass messages along the chain. See, if I add a new item to this inject node, let’s call it “dataItem” and the value can be a little message, now if I hit deloy – the save button here – then click the inject button, boom that little message came through to the debug node under that msg.dataItem.

You can also do conditional tests with switch nodes. Say I add a boolean – a true/false value – and call it “showData”, and tell the switch node to look for it and only let the message through if showData is true, well now if I deploy this and hit the button, yep still works fine. Now if I change showData to be false, deploy again, then click the button and.. Nope, no message comes through. You can also get information from Home Assistant devices, like our temperature sensors. Just pick the device and that’s it. I’ll add a switch to check if the temperature is less than 22°c, deploy that, and yep all good, comes through fine. Now if I swap that to 20°c, well now it doesn’t pass the message through, as expected!

So, what did I do? Well instead of triggering it manually, I used the poll state node to check the temperature readings from both of my temperature sensors, with the condition that they should be below or above my thresholds before sending any messages out, and only updates once per minute. Since I only want the bedroom sensor to be considered when I’m in bed, I have a time range switch which then outputs to a current state node which gets what the current temperature the thermostat is both sensing and set to, and passes that to a function node. These let you write custom javascript code which I use to alter the set temperature up or down by 1°c at a time. I have it output the new temperature, which I then pass to a call service node which sets the thermostat to that new temperature.

There is plenty more that I want to add to this, including checking if mine or my wife’s phones are connected to WiFi and if not generally keep the heating low or off, and add more temperature sensors and even smart TRVs (thermostatic radiator valves) to control each room’s temperature independently. That’ll be great as at night I can close all but the bedroom valves so any heating is exclusively heating us and not being wasted on the rest of the empty house, and during the day only the rooms we actually use will be heated again saving on energy costs.

So that’s a look at both how to set up a smart thermostat and temperature sensors, and a look at how to do custom automations both in Home Assistant itself and through the visual programming tool Node-RED. Next episode I’ll be walking you through how to make your Home Assistant system accessible from anywhere with internet access, securely and privately – so make sure you are subscribed so you don’t miss that!