Home Thermostat

I have been making a few electronic projects for the house for a long time, but I only recently revisited home assistant. I am on my third (or 4th maybe) iteration of the home thermostat and the latest version’s temperature sensor is not great.

I know my computers and wifi aren’t as reliable as I need for a thermostat, so I need to make sure it works without internet and without any other computers. But I can add some thermometers in the rest of the house and probably get better results.

So this is what I did.

  1. I have an esp32 on my wall, with a built in OLED. It it attached to a relay board to turn the heater on and off. I only have a heater in this part of the house, so I only turn the heater on or off.
  2. I bought some very cheap blue tooth temperature sensors from banggood. They were about $5 each and they can be flashed over bluetooth from a web page, which is just wild to me.
  3. I used ESPHome to read the temperature from these sensors.

Then comes the fun part. The sensors only report their temperature at 5min intervals (and I might even turn that down more). The less they report, the longer their batteries last.

The sensor in the thermostat measures temperature every 10s. So that is good for control. But it is too close to the ESP32 and it is getting too hot. It also is only in one room of the house (a room that is very sunny in the afternoons). So I know it is consistently wrong, and a different amount of wrong depending on the weather and the position of the sun.

So for each temperature sensor, I measure the difference between that sensor’s reported value and the most recent value of the thermostat temp. I run that through a low pass filter. Then I average these 4 offsets to get a number that represents the difference between the thermostat sensor, and the average temperature of the thermostat.

The thermostat reads in that offset from mqtt and uses it as an adjustment on its temperature sensor. The great part is, if the mqtt server goes down, or the temperature sensors run out of batteries, it will just go back to no offset (and the house will get a little colder, but not freeze any pipes or anything).

I’m really impressed with ESPHome firmware. It lets you basically just write a config file in yaml and it reads the file and creates pretty complex C++ to flash to an ESP device. It has good integration with Home Assistant. It really didn’t take me very long at all to get this (somewhat complicated) system of offsets working. If you’re flashing an ESP chip and you plan on connecting it to Home Assistant or MQTT, I suggest you check it out.

I am thinking of making the update rate on the thermometers even longer time frames. If this works, I don’t see any reason they would need to be updated more often then 4-5 times an hour. The offset is very slow to change, and they mostly track well with the sensor in the front room over short periods of time.


What do you have the display showing at idle, cycle through the temps?

It just shows the adjusted temp and the set point and it’s ip address (the last part).


Here is a shot of the data in home assistant. This is only 4 hours because I just set it up today.

to me too. I haven’t heard of that before.

I have a homebrewed thermostat built on an ESP8266 NodeMCU that had a similar issue. I 3d printed an enclosure that has a vertical baffle between the sensor and the ESP. There are also ventilation holes in the top and bottom of the enclosure to help dissipate the heat and allow ambient air to circulate past the sensor. Seems to work pretty well.

I’m also curious about your oled. My current setup has only a web based interface, no display etc. I’ve been considering an update with an esp32 and oled display.

I only use the wifi to change the set point and to track the temp, pressure, and humidity. The thermostat will function just fine if the wifi is down.

I’ve been really surprised at how reliable mine has been. Something will cause it to hang once or twice a year, a voltage spike or something perhaps, but it goes a long time between hiccups. I do have an old school bi-metallic thermostat set to 50* f as a back up.

I did have issues with it at one time. It took me a while to correlate the failures with my occasional use of my ham radio, but once I did I determined that transmitting on the 40m ham band was a sure way to get the ESP to hang. I provide power from a wall wart in the crawl space, with about 6’ leads in a wall to the thermostat. It turns out those dc wires were picking up RF from the ham radio! I twisted the dc wires together and that combined with changing the antenna arrangement a little solved the problem.

1 Like

It came on the chip. TTGO T-Display on banggood. It was pretty easy to program. Esphome can even do that too. I am seriously considering changing that to the ESPHome firmware because it does such a good job of connecting to the mqtt. It can also easily flash over wifi.

I do something similar, but I lucked out and used twisted pair ethernet. So it has not given me trouble. I can push a button and see the uptime. It just never resets on its own.

The web app is running a static javascript page on github (sort of like sandify) and I open the app in chrome on my phone. It is able to connect and flash to these devices right out of the box. I didn’t even open them. After it has the github firmware, you can change settings through the same app.

There is zero security. If someone wanted to flash them with other firmware, they could. But at that point, they would have complete control of a bluetooth thermometer in my house…

Flashing ESP32s over wifi from my Linux command line is oretty neat. But flashing from a website over bt blows my mind.

You could also pull 24v AC using the ©ommon wire off the funace’s control board.

I don’t have a furnace, so this isn’t actually an option for me.

My house is heated by a natural gas log stove. The upside is that the stove doesn’t require electricity at all, as it has a pilot light and uses a thermocouple to provide the tiny current needed to operate the gas solenoid. The stove does have an electric ventilation fan, which helps distribute the heat, but the stove runs without it.

My thermostat is on a UPS so it should run for quite a while even if the power is out, but I also have the bimetallic thermostat I mentioned above which should keep things from freezing as long as the gas isn’t out too.

I was thinking about that on the first iteration. I even bought a rectifier and a DCDC power supply. But mine runs into the basement where I have lots of power, and it is a bigger challenge to hide the extra components topside. Of course, I ended up with a style that is not hidden at all. :man_shrugging:.

It fits well and adds a lot of function to the basement heater. I looked in to diy when researching adding my hvac to ha. I went with a Honeywell zwave to keep a decent look in my hallway though, but have several printed esphome powered boxes tucked in the corners of our home. They have oleds for time/temp/humidity, buttons for automations etc, and an assortment of sensors. Some also have dfplayer sdcard players with speakers for various voice prompts, and sound effects. Ha and esphome rocks.

1 Like

The dfplayer is pretty great. I used one in a halloween costume and it was super easy to use.

I’d smile every time I walked past that thermostat. :slight_smile:

Happy to see another Home Assistant user on here!

Really like your thermostat idea, much cheaper than an EcoBee or Nest!


I got myself some iot sim cards and a simreader for the right network specs (nb iot). I hope to make a similar setup for our holiday house, but being able to monitor and control it over long range and low bandwidth cell coverage.

1 Like

Reminds me of my first job in the PC end of the computer world… I worked for a engineering company writing software for energy management using a PC (DOS based at that time, eventually ran it under Win 3.1 and then XP). Clients tended to be institutional because we’d also do a lot of refit for old florescent lighting. I used the average of all rooms as my median temperature and the highest and lowest to set incoming air temperature. Most of the system were dual duct so I could send a cool side and a warm side then modulate the dampers to give just the right temperature to the room. I ran the control loops on the PC as well as the scheduling and IIRC had six second cycles on the loops (everything was run over an RS422 (RS485?) serial connection to the actual control hardware. I was starting to do work on auto-tuning the control loops when the business started to dry up as industrial control processors got cheap enough to make this system less cost effective. I ended up leaving for Intel the last year he was in business and the owner retired to build custom shocks for race cars…

If your temperature sensors are based on ESP8266s using deep sleep mode the batteries would last a long time.

I could do that. I also do have power, so I could just run them off of usb. But if these last for 3 months, it would be a better solution. I’ll let you know.

I may also consider buying the ones that run off of aaa batteries so I can recharge them.

I’m enjoying this thread. I was not familiar with the ESPHome firmware, and Home Assistant looks interesting as well. It’s fun learning about all this new (to me) stuff.

When I first started playing with a pi based home automation system (7-8 years ago) OpenHAB seemed to be the most capable option, so that is what I’m using. I don’t think Home Assistant even existed then. I don’t think I’ll change, as OpenHAB meets my needs, and I sort of understand how to configure it.

I have started the HA configuration about 10 times, but never got used to it or enjoyed it as much. This time, I am using the lovelace UI and am able to edit it pretty well. I also have a bunch of new projects like the wled projects and I installed some shelly switch thingies and I have reached “critical mass”. I ended up buying the dedicated HA blue computer now and I am in all the way.

My automations right now are for the fish tank lights, the outdoor lights, and a way too complicated setup to indicate to my kids it is ok to get out of bed “stay in bed 'til your light turns blue”.

I also hooked in my laundry status and I have homegrown sprinkler system that I still have to connect up.

It takes way more time than it is worth, but I enjoy it.

1 Like

It can take time to set things up but long term it is low maintenance. I have had my HA setup for almost 2 yrs now and have all the automations I could think of setup and working reliably, and just a pi4 with ssd. The “dryer load is finished” and “washer load is finished” voice prompts everyone loves. I also have a gas dryer vent kinda too close to a window, and an automation to remind us to close it while the dryer is running. Another neat one… flash all the exterior lights and sound sirens when the alarm goes off. That gets enough neighbor attention to not really need a call in service.

I have some esp8266 with dht sensors powered by li-ion cells. They last about 2 months reporting every 10min. Getting to 2months was a pita… had to solder dinky surf mount parts for low quiescent current etc. Esp32 would probably last much longer there because I hear they are better at burst communication like this. I have some pir esp8266 devices that last around 2 years on a single li ion charge. Those ones have a special wake circuits so they burn near zero at idle.

1 Like