Controlling the heating

Tuesday, November 27th, 2018 at 9:52 pm

After achieving my first long term goal of a clock that I do not need to adjust for Daylight Saving, I moved onto remote control of my central heating. Thanks to some Home Assistant components this came together quite easily.

I have gas ducted central heating with a controller mounted in a central location. You could say I didn’t need to change a thing as it was already “smart”:

Yeah, nah…

This is what is referred to as a 5+2 programmable thermostat, there are two sets of schedules, one for the five days of the week and another for the two days of the weekend. The interface between this thermostat and the heating unit itself a pair of wires carrying around 25VAC, close the circuit to turn the unit on, this would be done instead by a relay connected to an Arduino.

On the user interface side I was planning to use a Google Calendar as I could put in events to represent the schedule and I could already manipulate it from my phone the the web interface which covers off remote access. The regular schedule would be in as repeating events, but I could adjust them as needed if I knew I wasn’t going to be home until later than usual.

My original plan had been to write something that would query the google calendar and push that information to the thermostat Arduino which would compare the target temperature against the current temperature and set the state of the relay appropriately. This approached changed when I saw that there was a Generic Thermostat component in Home Assistant that would handle the logic of being a thermostat. I wouldn’t need to implement that on an Arduino, it could just be a dumb relay control for Home Assistant to turn on or off. As Home Assistant can use any type of switch component for this and I was already basing things around MQTT I looked at the MQTT Switch component.

I don’t really know how a switch should be implemented, but from the desired behaviour it was easy to work out that the Arduino would listen on a topic for a state (OFF/ON) and ideally it would publish the new (or current) state on another topic. An additional thing I added was a failsafe, the relay would timeout after five minutes, if something went wrong (eg wireless went down or Home Assistant crashed) I didn’t want the heating to run forever.

I did encounter one snag with the relay shield that I had, it was hardwired to have the relay on pin D1, but that was one of the default I2C pins. While I wasn’t using one of the I2C displays in this situation, I was trying to share code between my devices. Later versions of this relay shield let you configure which pin it uses, so in my case my I pulled out the D1 pin (I had already soldered it up) and ran a wire around to another pin.

Adding the switch logic to the Arudino sketch didn’t take long, nor did adding the configuration to Home Assistant, so it wasn’t long until I has it connected up for testing:

This worked well, so I moved onto implementing the scheduling aspect using the Google Calendar Event component and automations.

Despite parts of the documentation not matching the implmentation (I need to follow that up, possibly asking on the forum or even submitting a patch…) it wasn’t long until I had automations configured to set the target temperature when a calendar event started, and to then turn off the thermostat when the event ended.

It was now a waiting game as I needed to let the automations trigger over time, and I also needed the weather to cooperate. Fortunately I am in Melbourne where despite it almost being summer we had a week or so of cool enough weather for this to happen:

I was quite happy with this, just in time for summer to really kick in and I no longer have a need for central heating… but that does give me time to sort out a proper mounting and power supply. I was initially thinking about finding some kind of unobtrusive box to mount on the wall, but the idea of featuring the electronics (such as a Tripler Base mounted to a blank plate) is growing on me…

Tagged with: