Remix.run Logo
▲ ssl-3 a day ago

I couldn't fall sleep the other night and it was cold in my bedroom, so I got up for a bit.

I thought about plugging in a space heater, but those suck for a few important reasons that anyone who has ever used one can probably relate to. One of those reasons is that the temperature regulation they provide for the room that they're in is usually very lousy, since the location of their integrated thermostat is right next to their source of heat.

On a whim, I decided to improve that thermostat. I already had a bag of cheap DS18B20 temperature sensor clones and some Raspberry Pi Pico Ws that had been looking for a project for years. I soldered those two things together and had Codex configure and install ESPHome for it, and tie that to Home Assistant.

That process went fast (only about 15 minutes) and provided a responsive wifi temperature sensor that was powered by a random USB wall-wart. Easy-peasy.

I also found a disused smart plug in the box of random electrical widgets.

The next move was to set up the Generic Thermostat card in Home Assistant. It reads the probe, and it switches the relay in the smart plug to turn the heater on and off.

This left me a heater over there (gestures) where sleeping-me won't be able to toss my bedclothes onto it or anything. That heater is ultimately controlled by a little sensor-probe on the nightstand next to my head, and a dial on a screen on my phone.

The room warmed up quickly and the temperature leveled off. Safety was maintained (the heater and its own thermostat are unmodified). Sleep came easily. Data was logged.

---

(It could have stopped there, and I might guess that most people would have been satisfied with the performance.

But the data showed that the DS18B20 clone was very noisy on the LSB regardless of sample bit-depth. That noise looked a lot like PWM to me so I had the bot concoct a 10-second rolling average for samples in ESPHome which solved the noise well-enough.

And the Generic Thermostat card is pretty dumb, as the name suggests. It just responds to observed temperature with a deadband around the setpoint, which works... But PID is better, so I've spent some time on that because I think PID is fun.)

▲naftalibeder 12 hours ago | parent [-]

This is one of my favorite HN comments possibly ever. Thank you :)

(Reminds me a bit of https://xkcd.com/196.)

▲ssl-3 5 hours ago | parent [-]

XKCD 196 is closer in spirit to a different thing I did last week.

While analyzing my power usage (mostly to quantify the running expense of the space heater vs. other real things) I noticed that it was cheaper to buy another smart plug than to run the power amplifiers at my desk 24/7 for yet another month.

So I set up a thing that watched for pipewire activity. It would switch on a smart plug when there was audio happening and then just switch it back off after a time of being idle. This worked, but switch-on latency for that plug wasn't very good (tens-of-milliseconds was common).

To fix that, I rearranged things to use a hackable plug running ESPHome and made the turn-on command a one-shot UDP packet that I put right into the IP handler[1], which resolved the latency pretty well.

Except: I noticed that it wasn't working. It stayed on and it never turned off.

After half an hour of figuring out that this was because of a tab opened with AliExpress that was "Checking" my "browser" by faffing about with audio every 477 seconds (for anti-bot, fingerprinting, literal spying, or some other needless dark pattern), I realized that we were all just doomed and started thinking about Amish potato farmers. I reckoned that they probably sleep pretty well at night.

[1]: oh noes the evil haxxors are going to get into my network, turn my stereo off, and overflow my buffers