Smart House. Development and Implementation Experience

In this article we will review the experience of developing and implementing a smart home in a two-room apartment. Here, the author’s point of view on the approach to the design and development of a smart home will be presented, as well as a turnkey solution that has been successfully working for 4 years.


Welcome to those who want to make their home smart.

What is a smart home? We will get away from official definitions and look at it from the point of view of the consumer. When the author first shared his ideas of a smart home with his friend, he said, “Can't you get to the switch and turn on the light yourself?” In his own way, he is right - the author is lazy (a joke). The idea of ​​a smart home consists precisely in the fact that he himself would perform manipulations for us to control lighting, power supply, and at the same time, save resources and ensure safety. Thus, a smart home is a complex of software and hardware solutions aimed at improving the quality of life of those living in the house. Yes, that's right, a smart home should be considered as what makes your life more comfortable, and not as a big and expensive toy. In this concept, the author of the article recognizes voice control of a smart home as unnecessary and considerswhat a smart home should realize, and in the future, also anticipate typical human behavior.

Behavior patterns


Where to start when you think about a smart home? With the choice of technology, a central controller? No and no again. First of all, ask yourself the question - why do I need a smart home? What will he do for me? According to the author of the article, there are four groups of functions that a smart home can provide:

  • Behavioral patterns - support for the typical behavior of living in an apartment, in terms of the use of electrical appliances and lighting.
  • Comfortable environment - creating comfort depending on the conditions, for example, day, night, guests, romantic evening, etc.
  • Information support - various tips for people living in the apartment about the weather, traffic jams, current events, such as friends' birthdays, etc.
  • Safe home - emergency prevention, quick shutdown of electrical appliances, security functions.

All these groups of functions should be carefully thought out, coordinated with all those living in the apartment, and only after that we can talk about designing a smart home system. We show an example of such a design, using the example of the smart home function of the author of the article.

So, let's start with behavioral patterns. To see them, you need to watch yourself and your family for some time. In the framework of observations, we record: what time does a person get up, does he always take food at the same time or in a certain interval, the route around the apartment, from the moment he wakes up to leave the house, the route along the apartment from the moment he arrives home to the end time. As a result, we get some picture in which it is important for us: what kind of light sources a person uses, what he needs for a comfortable existence — the inclusion of a warm floor in the bathroom, soft lighting, dim lights at night, etc. Such patterns must be found for each family member and get something in between that won’t upset the comfort of others. Suppose a husband gets up earlier than his wife every day.

In order not to wake up the wife, you can turn on a weak green light on the ceiling for five minutes instead of overhead lighting, and then turn it off (From the author’s experience, a weak green light does not interfere with other people’s sleep). As a result, two patterns were realized - the weekend morning and the morning of the week. Within the framework of these patterns, the smart home itself turns on the lighting at the right time, the radio turns off itself and tells with the help of various colors of the ceiling lights how much time is left before going to work. The patterns themselves are launched by the smart home on the basis of calculations of the necessary time for the morning procedures before the onset of an event from the Google calendar. For this, a special intelligent alarm clock was developed that analyzes data about upcoming events.

To create a comfortable environment, it is also necessary to observe what kind of lighting is comfortable for us when we go to the kitchen at night, do we turn on the warm floor in the morning every day or only on weekends, what kind of lighting do we set when we watch TV? As a result of such observations, the author realized a green backlight in the rooms, and in public places the overhead light was 10% of the nominal, which is turned on and off by the command of motion sensors. When guests arrive, you can realize a smooth change in the colors of the backlight, “twist” the video with a fireplace on the TV, and play pleasant music from the audio column. And all this by one command from the control panel or telegram. In the framework of this group of functions, the author realized, in addition to the night mode, turning on the bright white backlight while turning on the TV,guest mode with a smooth change in the color of the backlight.

Information support is optional, but enjoyable. It's good, after all, when you go to work, a caring smart home with a human voice reminds you of the need to take an umbrella, because it is raining outside. And in the evening, upon returning home, it is always pleasant to listen to calm music, after a long working day, which the same smart home automatically includes for you.

And finally, a safe home. The basic function of any smart home is to turn off lighting and appliances when people leave home. But what if you have a curious student at home who can do things while his parents are at work? A smart home will turn off all sockets, leaving almost no chance of causing trouble. And when the parents come, the system recognizes this, and turns on the power supply in the entire apartment. The author of the article had a case when he forgot to turn off the electric stove and went to work. And only due to the fact that the smart house automatically turned off all appliances did not happen unhappiness.

Architecture


After all the wishes are formulated, you can begin to develop the architecture of a smart home. Here, it is important to take into account the scale of the room that the system will manage. You must decide on the topology of electrical and control lines in advance. The ideal option is a “star” topology, when each consumer has its own power supply line, and all control electronics are assembled in one panel, next to the classic panel, where panel switches are installed. A more economical option is when the “common bus” wiring is used as builders in Russia build), and the control relay is connected to the circuit directly in front of the device. The disadvantage of this method is the complexity of the subsequent maintenance of the relay, since then it can be closed by a stretch ceiling, tile or wallpaper.To date, there are relays that can be mounted directly in the mounting boxes along with electrical equipment, but deeper than those that are massively installed in new buildings in Russian cities.

The next important point that defines the architecture of a smart home is control communications. Management communications are of two types:

  • separate communication lines to each switch or relay, or a relay group controlled by one communication line, for example MegaD-2561 (https://ab-log.ru/). Advantage - reliability, disadvantage - high costs for additional communication lines
  • radio control. Each relay is controlled by a command transmitted over the air. The advantages of this method include ease of installation and the absence of additional control lines. The disadvantage is the radio signal, which can attenuate due to external interference and then the command may not reach the relay. As an example of such relays, we can cite the Noolite system (http://noolite.by/), which is used by the author of the article

Based on economic considerations, the author of the article for a smart home chose a radio channel. To increase the flexibility of the system, each "consumer" had its own electric line laid.

The most important decision in the architecture of a smart home is the control scheme - decentralized or centralized. We will analyze each of them in detail
In a decentralized control scheme, all devices are interconnected and there is no single decision center in the system. Here the connection “each with each” is realized. In fact, this is no different from the usual lighting control circuit, except that the switches and the relays themselves receive a little bit of “intelligence” and, for example, are able to turn off the lights by timeout, or from a single switch, immediately turn on several light sources controlled by different relay. In such a scheme, the presence of a smart home controller is allowed, which also receives notifications about the state of the light sources and can, in accordance with the embedded logic, send control commands to the relay.



The diagram shows that the command from the button (Button) is sent directly to the relays associated with it, however, this command is also transmitted to the controller, which is simply notified of the fact of pressing. At the same time, the relay, when changing its state, also notifies the controller about this. Such a scheme is absolutely reliable, since in the event of a controller failure, the lighting will still work, but there will be no additional functions. On the other hand, such a scheme is less flexible, since it will be more difficult to implement changes in the logic of operation of one switch with different relays, for example, depending on the time of day. For such a task, a centralized scheme is suitable.



From this diagram it is clear that all the commands are sent to the smart home controller and all control is also carried out by this controller. The main disadvantage of such a scheme is a single point of failure. When the controller fails, the whole system becomes inoperative, however, an important advantage of such a solution is great flexibility in device management, the ability to completely change the logic of work, depending on the preferences of the residents. Based on the fact that the probability of controller failure is small (during the four-year operation of the system there was only one serious failure due to the memory card), the author chose a centralized architecture scheme for the smart home.

Implementation


To implement a smart home, in addition to hardware solutions, the review of which is not the purpose of this article, you need to choose a software platform. Now on the market there are a lot of solutions based on free software. According to the author, the following projects are worthy of consideration (included systems with which the author worked directly):

  • Majordomo - the system is written in PHP. For programming, the concept of objects, their properties and methods is used. It supports a large set of devices and has a large Russian community. Good for a quick start, however, the use of the MySQL DBMS and the architecture of a classic web application by this system is its significant drawback. This system was used by the author in the first version of the smart home. You can use PHP or Google Blockly as a logic programming tool.
  • OpenHAB — , Java. , . Google Blockly
  • Node-red — , , (rest, mqtt . .). , , , . .
  • ioBroker — JavaScript (Node JS). , . — . JavaScript, Google Blockly Node-red, ioBroker . , 2019 .

The smart home itself is currently implemented on the basis of the Rapsberry PI 3 and the Rapsberrian operating system. As already mentioned, the ioBroker system is used as a control system. Lighting and power management is based on Noolite technology. As a hardware add-on, a GSM module is used, which is used for emergency notification in the absence of the Internet, and also as an additional system control channel via SMS from trusted phones.

The logic of interaction between devices is implemented based on JavaScript, Google Blockly and Node-red scripts.

JavaScript is a regular program for NodeJS. For example, the chime of chimes is implemented in the author’s smart home like this:

schedule('0 0,8-23 * * *',() =>
	{
	 let currentTime = new Date();
	 let hour = currentTime.getHours();
	 if(hour > 12)
		hour -= 12;
	 let file = hour.toString() + 'h.mp3';
            playSound('audio/' + file); 
           });

Here, the ioBroker code calls every hour in the interval 8: 00-23: 00 a function that generates the name of the file in which the chime of the chime is recorded for the corresponding hour and plays the required audio file on the external device.

Google Blockly allows you to write code in a visual programming language without going into the details of JavaScript. For example, the inclusion of light in the hallway according to the motion sensor is implemented in this way: when the sun has set, the light turns on at 100%, in night mode - at 10% brightness:



Here we see a subscription to the event of a change in the state of the motion sensor. This code will be called when the state changes and contains “true”.

Using Node-red, we can implement simple control scenarios. For example, in the bathroom, we can use a simple code to control the light from the motion sensor:



At the moment when the motion sensor changes its state, the Node-red script blocks are automatically executed. When the motion sensor sends a “turn off” command, the script gives a delay of 5 minutes, after which it turns off the light. If within 5 minutes the motion sensor sends a “turn on” command, the delay will be reset and the light will remain on. A discussion of implementation details for Node-red blocks is beyond the scope of this article.

Thus, thanks to the approach to smart home as a system that improves the quality of life, the author of the project was able to realize his dream of a smart home without experiencing significant economic costs. At the time of the launch of the project for a two-room apartment, the costs amounted to about 50,000 rubles ($ 811).

All Articles