This is one of my older projects that I occasionally work on.
The fun thing about it is actually how it got started. It all began with me working the night shift at a factory. I used to have a very hard time sleeping during the day for two reasons; it was hot in my bedroom, and it was very bright. I got around the problem with the light by wearing a sleep mask, but it was still much too warm.
I experimented with different methods. First I put a couple of fans in the windows. This turned out to be a little bit too noisy, and the constant draft was annoying. After that I tried an air conditioner. This also wasn’t very good, as it was even noisier and I had to leave a window open to let the hot air out. This let more hot air in, however, and I quickly abandoned it.
Next I decided to try experimenting with timers. I wrote a simple Arduino sketch that let the fans be on for 15 minutes, then off for 15 minutes. This had the effect of making the room to alternate between being too hot and too cold throughout the day, and fiddling with the numbers didn’t really help. What worked on one day didn’t work the next.
This is when I decided to make better use of my Arduino. I connected a simple thermistor to it, and gave it some upper and lower temperature bounds, and let the code decide when it was time to turn the fans on and off. This was much better. On colder days the fans didn’t have to run at all, on hotter days they were working overtime to keep the heat down. I could live with the noise on those days, and the quality of my sleep improved a lot.
I still had a problem with the light. I experimented with different methods of keeping the room dark, and I eventually found something that worked pretty well. Too well. Now I had my perfectly dark, and nicely temperature controlled room, and I couldn’t wake up! I would frequently sleep through all of my alarms, to the point where I could swear that it never rang at all.
I went back to the drawing board. I already had a simple machine that could control my fans. What if I added a few relays and let it control my lights as well? I had it turn every light on in the room at the same time as my alarm went off, and had the worst waking experience in my life. The sudden pain in my eyes and the blaring alarm came together to scare me awake. It also wasn’t very flexible, as I couldn’t really set the time when it should go off. On work days it was okay, but it didn’t work well for weekends, and I didn’t want to upload a new sketch twice every week.
That’s when I decided to dig out an old laptop, and move all the decision making to it. The Arduino would report its temperature, and a program on the laptop would decide what the fans should do. It would also keep track of time, and start turning the lamps on in a sequence. Lamps far away from me would turn on first, and end with the one on my bedside table. The experience was again much better and waking up was much easier.
It was at this point that I realized I had just created a home automation system, but I didn’t have a good name for it; systems like this has existed for decades, but they were only made popular in the last few years, and I didn’t know of one at the time.
At this point I was very proud of what I had made, and I decided to add another feature to it. Unsure what it would be, I decided to look over what I had access to. I realized that the laptop I was using to control it had a perfectly good sound card that I wasn’t using. I decided to add a script that would start playing music a few minutes before my alarm. I again discovered that this was a little bit too crude. The laptop speakers were a little too weak, yet having it start blaring distorted music at full volume was annoying. I decided to hook a stereo into it with a fairly big speaker. Another relay would turn the stereo on at the appropriate time, and the laptop was plugged into it. The laptop would start playing its music, but with its volume set to 0%. It would then gradually, over the course of 5 minutes, raise the volume until it hit 100%. The stereo’s own volume knob was set to a comfortable volume.
At this point I got to sleep in a nice and cool, dark room, and my machines would wake me up in a very comfortable and effective manner. It was perfect!
It was perfect. It was perfect until I realized that one very important piece was missing; it wasn’t making me coffee in the morning. I went out and bought a very simple drip coffee maker, and put its power switch in the on position, then I connected its outlet to a relay so it would turn on as soon as it got power. It would then turn on at the same time as the stereo, and I would wake up every morning with the smell of coffee in my nose.
This was perfect. I used this system for years, and only stopped because I moved to a different apartment. Some version of this system has always survived, though. This summer I experimented with having it water one of my plants. It took complete care of this plant’s water needs for about six months. This is the longest I have ever kept a plant alive, so I’m very happy with the results.
The latest iteration of this system is using Raspberry Pi computers instead of the old laptop, and they communicate over the MQTT protocol.