Building an open thermostat

Have tou recntly tried purchasing a smart thermostat? Not sure about you, but i was a little bit disappointed. The zigbee ones don’t refresh often enough and have high histerosis and the wifi ones need a wired connection. Plus, if tou love minimalism as i do, tou won’t appreciate the bulky box that now needs room on tour nightstand.

What if we could make our own miniature wireless thermostat, with readings from multuple rooms, fully customizible and for a much lower price than anything available on the market? 

We could use a shelly plus relay that is connected to the boiler and pair it with a few blutoothe twmperature and himidity sensor and have them work as a themrostat.

Have tour interest? Great, but there are some caviats. 

As mentioned, this is mainly intended for an apartment or a tiny house with a si gle dource of heating, eg a boiler or an electric heater. Also, since we are using bluettoth sensors, range is limited and tou can only pair 3 of them to one thermostat. Also, there won’t be a phisiclay display to cottrol the temperature, bit rather we’ll rely on the home assistant dashboard, but to me that is an upside, as i have a cleaner house. Yes, this only works with home assistant, sorry.

Well if you are still interested here’s how tou can do that.

First we’ll take a couple of xiaomi bluetooth and temparature sensors. Since by default they send their data encrypted with a bindkey, we’ll need to flash them with a more open firmware. But son’t worrry, this is all done wirelessly. Pvvx is a great software in this regard and tou can find all instructions here.

Secondly, we’ll need a relay to connect to our heat source so it can command the heating. If tou are using a boiler, then tou will need a shelly plus 1, the blue one without power monitoring, as this has a dry contact which is needed for the boiler connection. If you are using an electric heater, you can use a shelly 1 plus pm (the red one) or also the blue one and make sure you supply power to the dry contact- either will work.

I will provide full instructions on how to connect any of these, but first let’s write the proper firmware.

We wnat to use the plus series as it’s based ob esp32 and thus has bluettoh coonectovity to reas our tou guessed it, bluettoth sensors.

We’ll be usign esphome. All the code is available ant the end of the article and i’ll describe shortly how it works.

First we enable bluettoth. Then we define two bluettoth sensors based on their mac addreses. each will report temperature and humidity. Ee create two variables. This will appear in the dashboard, and enabling them will make the sensor be taken into account in the average temperature. Living it unchecked, it’s temperature will not be taken into account by the thermostat, and eill simply just appear in the dashboard. We average the sensors to create a third, average temperature sensor. Keep in mind that a sensor is taken into he average only if its variable is turned on and id it reports a value (aka it’s not dead either by having its battery die, or being too fr away). 

Think about it: you can control wich rooms to be taken into account in the acerage temperature for the house, and if a sensor is no longer working, it will automatically be excluded from the average so that your boiler doesn’t run continously or never runs leaving you in the cold.

To get this working i had to get it messy: i am using a bit of lamba, and also converting all the physical sensors in virtual ones and only then averiging them. If you onow of a better solution, please leave a comment on how this can be done more efficiently. Thank you!

We can now  create a switch for the rely part.

Finally, we bring everything together with a thernostat. It’s inout will be the average sensor ans it’s output the relay. You can set the heat and cold tolerance, as well as some presets to make it more confortable to use. I’ve included this in the code linked at the end of the article.

For flashing the code, you can follow this guide. You will need a finnicky connecte that is relatively rare. I manage to find one here.

Now let’s wire it. 

You want to wire this to the thermostat terminal on your boiler. If there is already a nu per in place, remove it. You will also need to power the relay from a socket. Oh and one more thing: always make sure you know what tou are doing or call an experienced electrician! Some boilers use high voltage ac that can harm or kill you! You have been warned.

 If tou have an electric heater you need to Wire it to a socket and to the load (electric heater). Again, read the warning above!

You can do the initial provisiong by a blueetoth connection to input your credentials. 

Add it to home assistant and enable the toggle switches for the sensors which you want taken into account. 

I hope you like this and makes you think of other creative use cases. If so, let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *