Sunday, June 7, 2015

DIY "Smart Home"

It is time to brag again. :)

This time it is with my attempt at "Smart Home", which turned out pretty nice.

Here is how the "front end" looks currently:

When you move the mouse to the bottom, the bottom row changes like this:

It shows:
- Date and time (pretty obvious)
- Today's weather forecast (overall for the day in top middle and hourly on the bottom)
- Room temperatures (in the living room and in the terrace)
- The first 2 buttons on the bottom row turn the living room air conditioner on/off, the second 2 are for the AC in the terrace and the other 3 control the vacuum cleaner robot (made by Samsung, ironically).
You can also see one of my two cats in the reflection :)

Room temperature data and IR control are possible thanks to this:

And it is currently located here:

There is also a web page I can access from anywhere, which looks like this:

Not pretty at all, but fully functional and loads fast.
"Billy" is the name I gave to the vacuum cleaner robot, it is short from "Debil" :)

If you're wondering what's the deal with terrace's room temperature and air conditioning - my terrace is closed, so it is like a small room. And I use it as a smoking room, cabinet and lab at the same time. In other words, a "man cave" (as a friend of mine calls it).

Anyway, now I can check the temperature in my home any time from anywhere, and if I wish I can turn the air conditioners on/off. This is quite handy, because my windows look to the west and during the summer it gets quite hot in the afternoons. Instead of turning the ACs on when I get home and sweat until they do their job, I now turn them on shortly before I go home and when I get there, the air is already nice and cool.

I also have live video from my home (so I can watch my cats) and sometimes I see that Billy (the vacuum cleaner) is stuck. It does that sometimes (its Samsung after all). When that happens, it stops and starts beeping annoyingly until you tell it to shut the fuck up. When I am not home and it is stuck (it is programmed to start cleaning at 16:30 every day), it annoys the cats constantly until I get home and turn it off. And I can see that on the video feed - the cats would not sleep (as they usually do most of the time when I am not home). But not anymore! Now I just use the web access to put Billy out of his misery and restore the peace and quiet for the ladies :)

It would be nice to find a way to hide that USB cable better or at least paint it with the same color as the wall. I might do that some day :)
Putting the arduino part in a box would be also cool, but it would have to be a very special box, which lets infrared light through and blocks visible light, to hide the electronics inside. I have no idea what material would that be, where to get it and how to build the box.
Oh, and I need to burn the red LEDs on the arduino or at least stick some black tape on top of them :)

If you're not interested in how it is done, you should just stop reading now :)

Technically, the whole system is a mess of C# (the program that acts as a web server and shows the UI), C++ (the arduino code), some JavaScript and HTML (on the web page).
The arduino part has a temperature sensor, infrared receiver (so it can learn new IR codes and eventually be controlled with whatever remote I have closest to me) and 8 infrared LEDs (to transmit IR signals). I used 8, because I need to cover the entire room (you never know where Billy will get stuck) and I couldn't find LEDs which are wide angle and powerful enough. So I just put 8 in parallel and spread them to point in different directions. Because you can't power 8 LEDs from a single data pin of the arduino, I used an NPN transistor, so they get power from the aruino's 5V pin.
The arduino talks to the C# program over USB. I even made the effort to make the C# part scan through the COM ports and find the arduino.
There are 2 instances of the C# program - one running on the old Asus Eee PC you see in the pictures, and one running on the laptop in the terrace (which is connected to another arduino running the same code, but with only one temperature sensor and one IR LED connected).
The 2 C# programs talk to each other via HTTP requests, because they are web servers anyway, so it was the easiest way.
For the weather forecast I just do an HTTP get request to (just like browsers do) and then get the information I need from the resulting HTML (typical web scraping).
On the laptop in the terrace, the same C# apps runs in "minimized" mode, where it only shows a small (150x150 pixels) black box with two temperatures in it. Double click toggles full screen / minimized mode. Right click when minimized toggles the AC on/off (so I don't have to reach for the remote).

Now I am in the process of adding a small LCD screen to the arduino part on the terrace to show me the time and temperature, so I can still see them when I have something full screen (e.g. when watching a video, playing a game, etc.). Besides, I already have the LCD, so why not :)
I had to solve some unexpected problems to do that, and I feel very proud with the solution! I did learn something, which I believe deserves a separate post (coming very soon).
Update: I did it, here it is:

The whole project was relatively easy, because I happen to have enough PCs at home to do the actual job and use the arduino only to handle sensors and LEDs. But it is not that difficult to do it without PCs involved at all (except the UI part obviously) and use only arduino and ESP8266 (these are very cool WiFi modules, cheap and powerful, look them up if you're interested in electronics). I just don't need to.

The live video stream is not part of this project. I had it set up long ago. It is pretty simple - another old and unused netbook is placed in a kitchen drawer and runs Skype. When I call it, it automatically accepts and turns video on. So when I am at work I just call it via Skype and it picks up. Or I could call it from my phone from anywhere. Simple and effective. At least it was before Microsoft bought Skype and turned it into the piece of garbage it is now. But that is a subject for a separate post (in the rant series).
When someone is home (me or my son) - we just close the kitchen drawer's door to hide the netbook and not feel uncomfortable that someone might be watching. The mic on the netbook doesn't work so no one can listen either.
The only problems (besides Skype crashing on a daily basis) are that I must open the drawer's door and leave the lights on when I leave home. The lights are LED, so they don't consume too much electricity (so bills are not too high and I am not polluting the planet too much). It would be nice if I could turn the lights on/off and open/close the kitchen drawer's door remotely. Some day I'll make it possible :)
Or ... I might just buy a real IP camera with pan/tilt/zoom and night vision and use it instead :)

No comments:

Post a Comment