From home automation and smart homes in general to case studies


Recently, a lot has been written about home automation and smart homes. I would like to share my experience, general thoughts and a specific project. This article will be useful to those who simply would like to know what a smart home can be useful / convenient in principle, as well as those who would like to control (or just watch) from any device with a browser (phone, tablet, reader, HTPC, laptop, desktop computer, etc.) home automation system. And this can be done from anywhere in the world. My experience and the example described in the second part of this article (Arduino, JQuery Mobile Web interface, etc.) can be useful to those who already have some kind of home automation system (such as X10) or those who begin this thorny path.

The main reason home automation systems have not yet become so popular is the emphasis on lighting, which is usually done when promoting them. After all, blinking light (like LEDs on Arduin) without getting up off the couch is a pampering that has no practical value and pushes people away from serious thoughts about introducing and using home automation systems in their homes and apartments. No one needs to blink light (which is usually used for 90% of functionality), but for example, controlling heating individually in each room is convenient and saves energy = money. Sky-high prices for the components themselves (penny at cost) of ready-made, sold home automation systems, along with integration prices, only add fuel to the fire. I hasten to assure that the most expensive component will be the $ 20 Arduino Mega.
> climate control of temperature (heating / air conditioning) and humidity (humidifier / dehumidifier),
> natural light control (blinds, shutters, awnings)
> and watering of lawns, flower beds and lawns around the house (if there are any and you need to water them).
Of the decentralized systems, it is convenient to have a local (without 1-2 central control sensors that directly control the backlight) triggered by motion (presence) sensors, low-power LED lighting for stairs (sometimes floors) and parts of tables in the kitchen that are obscured by conventional ceiling lighting by hanging cabinets and shelves. The same illumination in combination with those listed above is indispensable at night when you need to get into the kitchen (and cut something off from something and eat without sharing it) without waking anyone and first of all yourself or stumbling into another institution about prudently scattered children's toys. It also makes sense to turn on the main lighting ONLY in technical rooms with motion sensors: cabinets, pantries, garage, laundries, etc. Motion sensors and centralized systems are not practical to use for main lighting in residential premises. Exterior and decorative holiday lighting at home is most conveniently turned on from penny ready-made blocks with light sensors and / or timers. Real security systems connected to response services (not just sensors and webcams scattered around the house) usually do not make sense to mix with smart home systems for many reasons.

Thus, we begin with the most relevant. An ideal object is heating which can be controlled for example: electric (batteries on wheels on a wall outlet and wall-mounted batteries) and centralized or not very heated private house. In my example, we will consider working with the Thermo Pomp system (Heat Pump in North America) with fuel oil heating by means of direct connection to an existing Control Unit (thermostat) and additional devices. In the first version of the system, I used devices and sockets of the X10 protocol. But unfortunately they didn’t work well, due to the slow interface and very high-profile switches when they woke up, they woke up all the people at home. Later I switched the system to radio sockets, which turned out to be much simpler and quieter than x10. These sockets are available in a huge range of radio frequencies and voltages. All this, applicable to a huge variety of other systems. It all started with the fact that my friend and my neighbor gently dripped on my head about the enormous role of the miracle of miracle - Arduino in modern society and that I, as a person who knows how and loves to hold a soldering iron, is simply obliged to catch this Arduino mania as soon as possible. I waved it off in every way and said that the area of ​​practical (not robot toys) use of her house is very doubtful and to make LED rulers on the basis of a powerful microcontroller to illuminate the steps of the stairs (instead of one shift register and generator) is just a gun for sparrows and the rest is pampering . But still they managed to lay the Arduino grain in my head, and like all the grains with the advent of spring and on the outskirts of summer, the sprout began to break through. I do not like hobby projects for the sake of the projects themselves.WAF (Wife acceptance factor) or as my dad says it is easy to legalize.

And as always, laziness was the engine of progress. We sat a little later in the afternoon on the veranda, the sun was pleasantly baking, and at the same time, my little son was sleeping in the bedroom on the top floor and judging by a Chinese thermometer for $ 2 (which you still had to go to and see without waking your son)the temperature was over 26. So now we need to go into the living room and turn on the central air conditioner, and then we need to turn it on and off so that it does not turn on every time the temperature rises a little. This is especially unpleasant to do in the summer at night, if you freeze under a light blanket, you need to jump up and again without having woken all the household members to run into the living room to the console and cut down this achievement of the last century. Then I realized that it was time to stop such an outrage and call a friend with the words "Where is your vaunted Ardunya, Come on here right now, we'll see what she is capable of!" I must say that I didn’t choose it at all and did not think that it would turn out to be so worthless (for example, when working with strings), and even out of anger and powerlessness, I almost moved on with it in the middle of the project on STM32. In the end, he still stayed with her, but first things first.

To make it easier to understand why everything was done in this way and how you can spread my experience and best practices on bread, we start with a description of what I have / had on hand:
1) A private house in Canada (I would like to say that it is mine, but of course it is it belongs to the bank and no matter how absurd it sounds, but having it fully paid at current rates is not even profitable) built in 1959 as they are called Split Level, the house is two-story but half of it is shifted vertically relative to the other half to the floor floor.
2) Arduino Uno (due to the small number of I / O for X10 and radio, Mega was required)
3) expensive and native Ethernet Shild. I still couldn’t start something and find an adequate library for ENC28J60
4) Desire, time and some money.
As is customary here, the bedrooms are on the top floor and for me it turns out this is half a floor above the living room where the ominous control panel for the cooling heating system is screwed to the wall. Here such systems are called HVAC (heating, ventilation, and air conditioning)in fact, it’s an ordinary huge one (tens of thousands of BTUs or they measure them here in tons) split air conditioning an external heat exchanger and a compressor which are located on the street and inside the heat exchanger is built into the central ventilation system, which takes an air and a half kilowatt fan from the floor level the living room is driven through two heat exchangers (one to the air conditioner, the other from a fuel oil or gas burner) and according to the duct system it drives into each room. Convenience and the very name of the heat pump is due to the fact that this device can drive freon in both directions and, accordingly, not only cool but also heat the air in the house. It should be noted that he can heat it more or less efficiently only if the heat outside is enough more than 0 or -5 (depending on the model and design).

I started my project and my ambitions with a small one, so let’s and we will analyze how this HVAC is madeand how to manage it. In fact, the devil is not so terrible. One of the conveniences is the liquid standardization of everything domestic and not very in America, this allows you to cross hedgehogs with snakes according to an open, simple (sometimes too) and well-known (usually ancient, condo) protocol / standard. In our case, the system itself (a burner fan, heat exchangers can be bought from one manufacturer, an air conditioner from the second, a humidifier from the third and the Control Unit with all this from the fourth. Honestly, I don’t know if such devices are also called / controlled in Europe, but I think that everything is either slime or very similar As far as I understand, such systems already exist in Russia and they are being transported from anywhere / cheaper, so you have great chances to encounter just such a system.
As we see, almost everything is clear at a glance. The only thing that needs to be explained is that the control unit is powered and the heat itself is controlled by alternating 24 volts. which are supplied from the input transformer R and C. Line C is common and always connected. Accordingly, when applying R (short circuit) to Y, O, W or G, respectively, is switched on. block. From this we will build on. So if they include then the worse we are? We will make our new system complement the existing one. Those control can be carried out from the old remote control and controller as before, but only when necessary, Arduino can disconnect the old system from the control and take the furrows into its own hands and then give them back.

And we put them so that without power and generally disconnected, they retain the previous design. R-0 disables the standard control module and transfers control to our Arduin. R-1-4 supply the desired voltage to the appropriate line. This control voltage R is supplied to each relay by a green wire. It’s good to manage, of course, but the system is serious and if we accidentally or not really turn on something wrong or in the wrong combination. For example, the heat exchanger will heat up and the fan will not drive air and remove heat from it, it may overheat and cause a fire, but we don’t need it at all. To avoid such situations, let's make a triple defense. And so, the first bastion will be the voltage sensors on each line S1-4 (those should be 4p).

They are a diode with two resistors (divider) and a small electrolyte. It can be a hinged assembly as in the photo. As a result, we can know in Arduin whether there is actually voltage on each of the control lines or not. Accordingly, if the current state of the control lines (Y, O, W, G) does not correspond to what should be, we display an error code and turn off the system. The next bastion is our optional plenum sensor. If there it is too hot or cold (close to 0C) then we again output the code and turn off the system. Obviously, it is impossible to power the relay directly from the arduino outputs, so you either need to pile on a transistor for each relay or buy a ready-made module with several relays and transistors on one board. I buy 99% of the components on ibei. For example, Ibei is full of such 8 channel modules (8 Channel Electronic Relay Module) for about $ 9. or you can buy 4 + 2 (since in reality we need only 5 and one spare)


As sensors for temperature and humidity, I used Chinese digital DHT22, which worked well. They only need three wires +5, GNd and Data. Wires can be quite long without loss of accuracy and signal. One sensor is thrown into the street in the shade and under a canopy from direct moisture. One sensor in the house. In a house already built many years ago, usually the biggest problem is to run new wires, so I tried to make the most of the current wiring. There are several libraries for DHT22. I had problems with everyone except this. I put the internal DHT22 next to the wall-mounted remote control. If the HVAC control system used to be installed in your house, just like in mine, then you should already have a 6-core cable going from the control unit to the place where the remote control itself with the indicator and buttons hangs. Modern remotes (like mine) require only 2 wires. Thus, we have at our disposal 4 already laid wires. In them we run + 5V, GND, Data for the internal DHT22 and the last Serial (UART) Tx from Arduina to display information on the display.

As a display, I used a small (2.5 cm) OLED screen with a serial interface .Yes, it is a little expensive, but there are several unique differences from the ones available: the Serial (UART) interface, which allows you to use only one wire to connect it, the presence of five digital pins on the screen controller (where we connect the RGB LED for additional display of the system status) and finally, compactness combined with contrast and excellent readability both in bright light and at night, and it does not illuminate the entire corridor at night like any LCD with constant backlight on.

Next, the problem arose of how to put temperature sensors in each room, without additional wires, power and radio modules. As the sensor, I chose the digital DS18B20,(having good accuracy + - 0.5C) which needs only two wires (ground and signal). They can be hung on these 2 wires a lot in parallel (each has its own unique MAC address). But even to stretch two wires in all rooms is hellish labor. It dawned on me here. After all, a telephone cable is laid in all rooms and it is 4-core and in the best case 2 wires are used for the telephone (usually red and green) and the rest (yellow and black) pass through all the places I need and remain free. Thus, not cutting the wires, but only exposing the necessary two, I soldered to them in each room on the DS18B20.The total length of the wires turned out to be quite large, and if the signal wire was propped up (by + 5V) with the recommended 4.7 kOhm, then in my case the sensors were practically unreadable and I reduced the backing resistance by half to 2.3 kOhm and everything worked fine.

Then I got confused by the pressure sensor and settled on the expensive BMP085, but it has an I2C interface, which again saves legs and the number of wires. Since he can still read his temperature, I put it in the basement, where it was closer and easier to pull new wires (as much as 4). I tried to make maximum use of standard telephone cables and connectors (RJ11) so that the design was disassembled and repaired - replaced by a suitable one.When connecting this barometer to the same I2C bus as the RTC (non-volatile clock module), not very clear problems arose. They interfered with each other and until I set a slight delay before reading the barometer everything worked unstably. Since a short temporary power outage is not so rare and the RTC moduleworth a penny I added it for non-volatile time. basically needed when using x10. Using it, there was a desire to automatically synchronize it with NTP via the Internet (since we already have it), but something I did not manage to cross the webduino server and NTP. As a result, NTP time (Unix epoch) is sent to the Arduino (and RTC is updated) every time you change any settings or modes in the web interface. Which has its drawbacks as it is taken by JavaScript from time on the current computer or mobile device and is not always accurate and in the correct time zone.

I send commands to my radio sockets Arduina on the air with a penny ($ 2) transmittermodule. They are a dime a dozen in Ibei (search for "RF transmitter 315 Mhz ..") and in any store. The only thing is to choose the right radio frequency that matches your outlets. Unfortunately, my sockets were not correctly supported by the standard RCswitch library. in the description of the library there is a list of supported chips , but don’t be upset if yours is not in the list, it worked after analyzing the broadcast manually and without a library. Much has been written about similar sockets and work with the library. In particular, here: http://habrahabr.ru/post/213425 http://habrahabr.ru/post/212215 I used 110V sockets. Despite the fact that radio control requires a non-standard solution, it is the simplest and most cost-effective solution to the problem. Namely, turn on and turn off electric batteries or any other device (not necessarily resistive) in time or manually and sometimes turn on and turn off the external light. Insteon, Zwave and others have many sometimes unnecessary additional functions, but they are much more expensive and have problems with the openness of the interface so that Arduino can send simple commands to devices. The only problem with the sockets x10, Insteon and others is that they click very loudly during switching. This is especially annoying on a quiet night. Another nuance: x10 was imprisoned and popular in North America and, accordingly, under 110 Volts. Here, everyone chooses for himself. Or pay a lot for:
Z-Wave - there are no ready-made sockets, there are relay-shaped relay modules that also click quieter and somewhere, somehow you need to hide them in the walls, then walled up, it is not clear how to service them - change / repair. But then there were USB modules for sending commands. But for this, you still need a microcomputer (maybe a router is suitable) with the correct OS drivers, etc.
Insteon - there are sockets, but they also click disgustingly like x10 and as far as I understand there is no open module for sending commands and the system is again sharpened for 110V;
You decide to bother with the integration and sending commands to this network or pay 5-10 times less for each radio device and, if necessary, grind the code for it. Like any other thing, everything for 110V is cheaper. Of course, there are also extreme ways, such as the one described by several authors here, the idea of ​​entangling the entire apartment (house) with a pair (and in fact a bunch) of hammer wires and collecting each control and controlled device from scratch manually using the 1-Wire protocol. Some went even further and are developing their own protocols ...

Also, as a kiter, I screwed an anemometer (wind speed sensor). To measure it, I used a hand-held cup sensor with a reed switch closing 1 kOhm between two contacts during cup rotation.The program uses an interrupt and measures the number of times + 5V is applied (transition from 0 to 1) to a digital input (powered by 5k ohms on the same + 5V). This value is multiplied by a coefficient suitable for your sensor, and the wind speed in knots is obtained from the number of faults in one second. Also, for each hour, the maximum and minimum values ​​of speed (gusts) are measured and the maximum for an hour is displayed. On the web, the current and maximum are given. Each sensor must be individually calibrated and the correct coefficient selected. To control the garage door, I used a spare radio remote from it and using an additional relay (sixth) emulated a button press on the remote control (by opening the remote control and soldering the buttons in the contacts).

The communication protocol of the standard control unit of the thermal pump with its remote control (usually 2 wires) is usually closed and our arduino cannot know which mode and settings are set in the standard control unit, but with the help of our sensors we can know in which mode the HVAC is now and although they also have there is a temperature sensor in the heat exchanger; additional protection with the help of Arduina will not hurt. People often ask me: Isn’t it scary to trust Arduin to manage such a responsible system with his house? My code is open and transparent. I understand what is happening and I can always catch and correct the inaccuracy (if such remained after six months of using the system). And most importantly, I can add any functions that I need. In the same box, most likely a less powerful controller and of course there is nothing to change and you can’t add. Without arduins, adding again limited features like Internet access to a standard control unit costs a new box of hundreds of dollars. It all startednot that I wanted to save money, but I needed functions that were convenient for me that I couldn’t buy from equipment manufacturers for any money. But of course, if you take into account the price of a person’s hours spent by me, and even if you just decide to do this on the basis of my and other developments, this project is certainly cheaper to buy ready-made, but say goodbye to the flexibility and necessary functions. It’s about how to install FreeBSD and painstakingly for every reason dig into the flea market of Internet knowledge and manually twist it from the command line for yourself in comparison with Mac OS, which is beautiful ready-made but limited based on the same BSD. The main one is the inclusion of heating / cooling to the desired temperature not forever or according to a schedule, but only for an hour-2-4. It sounds simple and convenient but does not exist in standard controllers.

If you want to control only a heat pump without RF, RTC, a barometer and other troubles, Uno also has enough memory and legs (I did just that in the first phase of my project). In the full version, Mega is indispensable. Let's look at the features and interface.

The interface itself is made in the framework of just one html page using Ajax technology for exchanging data with the Arduino web server (webduino) and is based on the JQuery Mobile libraries. Therefore, to work, you need several image files and the libraries themselves, which can be replaced by links.

In the upper left corner, we see the moon, which means that according to the settings of day and night (in the first line of the blue block), now the night mode. If the daily regime there will be the sun. Next we see our house. In the house a lot of temperatures in each room and in the center are temperatures with tenths, this is the temperature in the living room at the main level. At the green below the house, we see the relative humidity inside the house. A snowflake to her right is an indicator that the air conditioner is working now. At this point, the remaining operating modes are displayed with different icons (heating by a thermal pump or AUX or x10). If the icon is muted (translucent), then the system is in this mode but not active. Those. for example, in air conditioning mode to a temperature of 21 degrees, but since now 20 degrees, the air conditioner is not active. If two modes work simultaneously, e.g. heating x10 and heating pump, then two icons will flash sequentially. On the left and right of the house we see the rays, when clicked, they become bright and, when pressed again, are again muffled. This is the inclusion of external lighting at home. I have an external light in the backyard and in front of the house. Control is transferred by x10 and the numbers of the corresponding devices are written in the html (JS) code, Arduina only sends commands to the device numbers transferred to her from HTML. To the right of the house we see an automatic garage door. which opens and closes when you click on it. At the top right of the house we see the current (averaged over 1-2 minutes) or the maximum wind speed in knots per hour. The value of the wind speed is highlighted in different colors from blue to red depending on the speed and in accordance with the internationally accepted colors of the Beaufort scale. On the top right, we see the temperature outside and below the current atmospheric pressure. A pink background for the pressure value is a graph of its relative change over the past 24 hours (x-time, y- relative pressure value). Under pressure green relative humidity outside.

Now consider a group of white selects and the SET button. The left selector selects the desired temperature / mode. Right for how long to enable this mode. If the mode is active, then the inscriptions will change slightly, as in this example.
If the heating mode is active, then the button will additionally be painted red and if the cooling is blue. To turn it off, you need to leave the temperature and the selected mode on the left and the remaining minutes on the right and then the SET button will change to OFF and pressing it will turn off the mode. The cooling or heating mode is automatically selected depending on the outdoor temperature. If the street is less than the value of the heat_temp constant described in the html (JS) file, then only heating will be offered, otherwise only cooling.

Now let's look at the blue x10 block. Clicking on the first line opens the general settings: ON - All Sockets Always On (for example, in summer), OFF all sockets always off (for example, if you are on vacation), Split - the individual settings of groups and rooms come into effect. Then you can choose at what time the day starts and at what night.To save the settings, do not forget to click the Apply button below. further each row reflects a group of rooms which may consist of one or more rooms. I did a floor grouping in my house. On some floors there is only one room and on some more. We can set the mode of each group to ON - all sockets of this group are always on, OFF all sockets of this group are always turned off (for example, you need to turn on the vacuum cleaner and if the battery works at the same time, it will blow a fuse), Split (available only for groups with more than one room) - the individual settings of rooms within the group come into effect, Day - maintain the indicated temperature only during the day (always off at night), Day & Night - maintain the indicated temperature for the day and another temperature at night. Each room has all of the above except Split.

The very last line is the setting of the Override mode. This mode was made to force the inclusion of sockets in the selected room or lamp for a while. For example, you need to heat the room as much as possible for a certain period in order for the child to massage there and continue to maintain the usual temperature in it in an hour. Or turn on the light on the street for half an hour. On the left, you select the room on the right for how long to turn on the mode and click the Overrride button. If you need to early disable the mode on the right, select OFF and press Override. All information is updated every upd_interval (constant from html file) seconds. Default = 60 seconds. When the information is updated, the entire top of the page with the house blinks.

I would also like to talk about the concept of combining outlets (pool). Let’s say you have one large room which is not able to heat at -5 overboard, or it will take a very long time to heat up. You can put a second RF socket with the same code / address and plug a second battery into it and they will always turn on. That at a relatively warm temperature will lead to frequent clicking and turning on and off these two or more batteries. There is another option, you combine these batteries in a pool in the Arduino code x10pools [17] = {0,0,0,0,0,12,0,0,13,0,0,0,0,0,0,0,0 , 0}. Zero means there is no pool at the given outlet address; number means the address of the child outlet of the pool. The child turns on if the street is colder than the poolt (constant from the html file) or the gap between the desired temperature in the room and the current temperature is greater than delta_temp * poolf (constants from the html file). I would like to say more about delta_temp (constant from the html file) is the Delta temperature. It is needed so that the modes often do not turn on and turn off, as the readings of the sensors can slightly jump + -. Heating turns on if the current temperature is less than (the desired - delta_temp) and turns off if it is higher (the desired + delta_temp). The default is 0.5 Grad C. Heating turns on if the current temperature is less than (the desired - delta_temp) and turns off if it is higher (the desired + delta_temp). The default is 0.5 Grad C. Heating turns on if the current temperature is less than (the desired - delta_temp) and turns off if it is higher (the desired + delta_temp). The default is 0.5 Grad C.

Now consider the issue of security. Of course you can’t leave accessible control for your home. Since our system consists of a client (JS Ajax html page) and a server (Arduino) you can organize various levels of security. For example, you can put an HTML page on your computer, phone, tablet, etc. (without exposing it to public hosting) and then only you (from devices with this file) will be able to open this control panel of your home systems. Arduino web server weighs on the internal IP and therefore if you do not forward it on a router to the outside world, then you can only access the arduino from your internal network. Access to the HTML page itself can be password protected on the Web server where you want to put it. It is also fashionable to raise an HTTPS server regarding it. The simplest and, in my opinion, reliable enough is the public hosting of the page, but the page itself is not connected at startup unless it passes the Arduino server address (pre-configured Dinamic DNS and Port Foewarding) to it as a parameter. It looks like this in the browser, such a link is introduced http://myhosting.com/index.html?http://myhome.slyip.net:8081/hvac. If an attacker accidentally stumbles on your client page, then he will not be able to do anything with it without knowing the address of the Arduino server. This is the easiest and most convenient compromise option that I now use. Yes, to me, too, this whole design with a wretched (slow, not supporting HTTPS, etc.) Arduino Web Shield server, in addition to which you still need to separately host the client page from the icon, do not like it.a router that instantly turns into a wifi bridged web server with a Serial (UART) interface for Arduine, I will immediately screw it to the arduine (or it to it) and throw it off the shield and wreck the wire. Thus, it will turn out even more of what I wanted so unsuccessfully to get from the STM32 controller, namely that everything was in one device (not a separately consumed client page and a separate executive server) and a normal web server on which you can implement a decent degree of convenience of speed and security. B lastly, an example of the interface sources for arduins checked for 1.0.1, my library package and HTML GUI .



Also popular now: