📜 ⬆️ ⬇️

My comfortable home

Relatively recently, there was a text about home automation, and in the comments one comrade expressed an idea, which I also think about for a long, long time. The bottom line is that automation should work so that this, if possible, is generally not noticeable.

That is, a smart home is a home that can do anything. A comfortable house is a house that does everything itself can.

Let's first, I just boast that my house is able now, and you decide whether it makes sense to read about my bitter (and sometimes even nothing) experience further, ok?

')


Basic functions:

1) Control of four radio sockets (this is a background light and a tablet with acoustics);

2) Control of 8 buttons of four radio light switches;

3) Reboot the router when the Internet is lost;

4) Turn on and off the webcam;

5) Monitoring 8 wireless sensors OPS (three smoke sensors, three leak sensors, a pair of door opening sensors);

6) Receive data from two meteorological sensors - in the room and outside the window (a radio channel and two service controllers on the Arduino Pro Mini) - and transfer them to the Internet;

7) Control of TV, media player and air conditioning (radio channel + service controller on the Arduino Pro Mini, it is also a meteorological sensor);

8) Manage the cat feeder;

9) Monitoring the wired motion sensor (“security” and service functions);

10) Managing music in the bathroom (it's like in fashionable shopping centers — you went to WC, and there you have such relaxing music);

11) Event notification by email.

Service functions (scripts):

1) Automatic control of light in the wardrobe (a tiny closet, in fact, you can love me again);

2) Automatic control of the light in the hallway;

3) Automatic control of night lighting in the kitchen;

4) Automatic control of light and music in the bathroom;

5) Turning off everything that turns off remotely, turning on the camera and switching the motion sensor to protection mode when leaving home; and turning off the camera with turning on the background light, the light in the hallway and switching the motion sensor to the previous one, before guarding, on return.

You can control almost all (except for those that are absolutely automated) from any computer, from a smartphone and a tablet with Android through an app or voice through a bundle of app. On the local network or via the Internet. The method is the simplest - the command is transmitted by a POST request (the essence is a set of the address in the browser).

From the beginning, and until now, the Arduino Uno board remains the core of the system. Her assistants are three service controllers from the Arduino Pro Mini plus a pair of radio relays in places where special intelligence is not required (a feeding trough, for example, and music in the bathroom). Scripts - partly in the Arduino code, partly - in the Android whistle connected to the TV. The whistle just gives the necessary requests in accordance with the schedule.

Well, I did it all with the help of a mass of smart guys who wrote excellent instructions and libraries, and, surprisingly, their crooked hands.

The beginning of time

When exactly it all started is hard to say. Either when I bought a pack of radio-controlled outlets, or when my wife reported that in this their Japan, “every light bulb on the remote control”.

Probably all the same, when Japan. So at once for some reason it became a shame for the power, I could not sleep straight. Therefore, I immediately acquired from the Chinese radio-controlled switches Livolo to replace the densely key-mechanical.

. these are cool switches
image

Radio is very important, because at the repair stage I conscientiously tried out all these smart things. Of all the low-current, I came up with only a local network, and then the rest was not enough neither mind nor time. Not the workers were caught, but simply some Stakhanovites: they barely had time to explain to them that the network was laid using the point-to-point method, and not like a telephone.

That is, I had no choice - wiring or radio. Only radio.

But even radio-controlled switches were boring, so everything is farther away like everyone else. And all at some point acquire Arduino. This, as I understood then, is such a magical thing that attracts newbies and rays by ... honoring hardened ironworkers. Fortunately, the first excitement about the weak point was already long gone, so I had an idea what I wanted.

Namely - to control radio outlets in the amount of four pieces and radio switches in the amount of the same four pieces (eight buttons). And to manage it in different ways - locally, via the Internet, from a computer and a telephone, with buttons and voice. Hence, the basic set:

- Arduino Uno
- Ethernet Shield (legendary W5100);
- two blocks of 4 relays with keys for direct connection to the Arduino;
- several sets of AM-receiver and 433 MHz transmitter.

If you think that this is a riddle in the style of “cross out the superfluous,” then all is completely wrong. The fact is that I was not sure about taming the sockets and switches, so I decided that in a pinch, I would simply tie the available consoles to the relay. Roughly, but effective. And not quite ashamed - many did.

Fortunately, extreme measures were not needed, but the relays were still useful. And later, the list of equipment was supplemented with receivers / transmitters, several Arduino Pro Mini boards, motion sensors and a scattering of wireless sensors from simple Chinese alarms.

In general, by the time Arduino arrived from China, I was theoretically savvy and, without the slightest delay, poured a classic flasher into it. I guess she was disappointed, but it did not last long. Because the next number was the management of outlets.

Only radio, only hardcore

On hand was the RC-Switch library, sockets, their remote, and the Arduino Uno with a receiver-transmitter. Fortunately for me, everything coincided, so that the flashing lights (and the background lights were plugged into the sockets) reached a fundamentally new level. Especially if we consider that in the examples RC-Switch turned out to be a very useful code with a web server, so the management of sockets via the Internet started right away.

. By the way, about the sockets - everyone saw them like that, right?
image

True, the first nuance was designated. An attempt to draw a control page directly in the Arduino code turned out to be a failure: starting from a certain moment, the board was frozen at the start. Experimentally I found out that, most likely, the matter is in a huge number of text lines, for which Arduino lacked any resources.

In general, I acted like a real hero - I went around. He left only a web server with a command handler, and the teams themselves began to keep in mind. Such a solution, of course, is full of flaws, but there are also pluses: if an evil hacker does get through to the Arduino, he will still have to sweat to figure out which command I came up with to turn on the light. In short, the real secret is a secret that nobody knows about.

But with the light switches came out some nonsense. That is, they are, of course, very cool, but RC-Switch refused to recognize them. The Chinese seller, in response to questions about the protocol, as a parrot answered “433 Mhz switch”. And then I did not read on the box that this is a 433 MHz switch. Opening the console didn’t end with anything good either: just some kind of PIC inside, that is, there are signs of a custom solution with incomprehensible perspectives.

At first I was sad, and then I found at least a cool, than RC-Switch, thing - Protocol Analyzer . And although this utility did not help solve the riddle of switches, it became clear which direction to go further. So assembled on the occasion of a set of receiver and divider used along with Audacity . And here I understood a lot.

Or, more precisely, I understood not so much how many considered packets of commands and counted the number of impulses and their duration with a toothpick. Yes, that's right, a toothpick, right on the laptop screen. I did not understand the protocol then, so I stupidly pressed the buttons and encoded the corresponding sequences.

Looking ahead - this is then vague guesses and an obscure itching in the brain formed the Livolo switch control library , which later more competent comrades supplemented the decoder commands of the native console and the port of this whole farm on Raspberry. But first, the teams were encoded in Russian senselessly and cruelly, i.e. I tritely transferred the accepted pulse sequence of each button used to the code on a 1: 1 scale.

I was still bothered by the idle relays. The money spent aimlessly was a pity, so the relay screwed on the modem's power supply (Huawei from MGTS is surprisingly often hung up) and the webcam (well, and what does it always glow in front of evil hackers?). Yes, yes, I understand, these are just two of eight, but at least something.

You might be interested to know why I fought hard with AM transmitters without error correction and normal bidirectional communication instead of using fancy nRF * or XBee. Probably because at first I didn’t know anything about them, and bought something that was cheaper. And then it happened so historically: after all, the entire periphery, which I planned to control, used this type of modulation. And it seemed to me not very rational to hang a second receiving-transmitting set on the Uno.

Then it became even more interesting. At some point, I met my gaze (well, or whatever the call buttons are meeting with homeowners) with the wireless bell button and felt an overwhelming desire to find out what was inside. It turned out - a 433 MHz resonator and a coding chip of the same system as in radio rosettes.

And when I dig a little in the descriptions of the sensors of simple Chinese wireless alarms, it turned out that they use exactly the same communication method.

. typical chinese sensors (leakage and door)
image

. and inside
image

Do you understand, yes? I got access to a large number of inexpensive and versatile sensors and peripheral devices with which my controller could already work without doping.

So the result was a black box that could control the light throughout the house, turn the webcam on and off, notify by mail if someone rang the doorbell, monitor the door sensors, leaks and smoke, and at the same time - reboot the modem, when the internet went down. Cool? Of course. Conveniently? It turned out that it was not as convenient as it seemed.

. box
image

.
image

And it’s not even the case that you had to keep teams in your head and type endless POST requests in the browser. You do not need any of this, because for the smartphone I was planning to control, there is an incredible Tasker app , in which it is extremely easy (although a bit dreary, but with geyas it is always so) to make a remote control. The finished console, by the way, is elementarily exported to a separate application, and thus the deployment (what I know of words) of the system to all phones and tablets takes place.

. no interface designer, no designer
image

.
image

Nevertheless, I was surprised at how quickly it bored the fact that an on-off switch needed a remote control. And I wanted more.

Comfortable home.

The house should be comfortable

I realized this principle, it seems, on an unconscious level. Imagine the situation: you were ready to go out, already shod, shook a hundred clothes, and realized that you forgot to turn off the lights in the kitchen, in the room and, for some reason, in the toilet.

If you do not have a smart home, you will have to undress and bring order lighting (and even look at the toilet on the road - plus, in general, who argues). If you have a smart home, then you take a left in the hallway wise to console or open dohryukalas-walled control panel. Again, if everything is correct, then to turn off the whole world you will have one button. But maybe a few. And if the smart home is not very literate, then the whole world will turn off immediately.

And you will be left alone with the darkness of the hallway.

But I fear the darkness, and I don’t want to be confused with the lace buttons. Therefore, at the first stage of natural cleverness, he again turned to the topic of wireless calls. Since I remembered that the bell button was similar to the one-command socket panel, and the commands of these Arduino RC-Switch panels were received once or twice, the bell button turned into the “I am at home” button.

This trigger button hangs next to the front door. Press on exit - and everything that the home controller can reach will be turned off in a minute. And then the webcam will be turned on. So there is quite a time for myself even to glance in the mirror and quietly go out, unnoticed by the all-seeing eye.

And if you press the same button at the entrance, the camera will turn off immediately. But the background light will turn on in the room and in the kitchen, as well as the light in the hallway. And no cat on the tail of an oversight will not come, so everyone is happy.

In parallel, I studied the potential of the popular motion sensor HC-SR501. Why is he, and not a wireless motion sensor, since “only radio, only hardcore”? It's very simple: a wireless motion sensor will constantly clog the air with its cries, and at the same time it will distract the controller to process them. And the controller and other cases is complete. Therefore - a wired sensor, and without interruption, so that, again, not to confuse the controller.

Lyrical digression. In a bout of enlightenment, besides the local network, I puzzled the builders with a small niche for every telecom in the hallway. Structurally, the niche is located almost under the ceiling (about 2 m), next to the entrance door.

. here you can see everything at once - and the smoke sensor (next to the lamp at the top), and the “I'm at home” button on the panel door, and the telecom niche cover located above. And on the door - a motion sensor and a webcam with a wide-angle lens-nozzle from a smartphone
image

. camera and sensor are larger. The untidy wire in the lower right is the controller reset button, which I haven’t yet figured out what to do.
image

In turn, the door to the room and the tiny kitchen corridor are easily visible from the entrance door. That is, it is like a strategic place to control movements around the apartment. That is why the above-mentioned motion sensor turned out to hang three functions at once: control of the light in the hallway, in the kitchen and, to some extent, security.

The logic is simple. If the automatic light control is on, then depending on the time of day (controlled by the Android remote control on the TV and Tasker), the light is turned on either in the hallway or in the kitchen. And if the “I am at home” button was pressed when exiting, instead of controlling the light, the sensor goes into security mode, and reports every detected movement by mail.

And although the sensor HC-SR501 is as simple as two kopecks, it was not without fun. At first, the light worked like a flasher. I thought it was a matter of air flow, since the sensor looks at a rather busy place from this point of view. Therefore, infinitely long regulated the sensitivity and direction of his "look".

I was confused by the fact that sometimes after adjustment everything worked. True, not very long. And it was only quite by chance that it dawned on me that it was either electromagnetic interference from the transmitter and the power cables passing by, or from pickups on the Arduino board. The unpleasant effect was minimized by the maximum possible spatial separation of the transmitter and motion sensor, the reduction in the length of the cable connecting the sensor and the controller, as well as the cleverly laid out cable. The latter is exclusively empirical.

Rule of three

After several experiments, I settled on the following light algorithms. In the hallway, the light turns on for a minute with a single pass, and if several movements are recorded in a row, then each subsequent movement prolongs the work of the light by three minutes (not totally, but resets the three-minute timer to zero).

Minute switching on is, on the one hand, so that the lamps do not blink every second, and on the other, so that they do not have to turn under the sensor so that the light will turn on at all. The fact is that I did not modify the motion sensor, but “out of the box” it holds an activity signal for 3 seconds after detection, and then another 2.5 seconds for it is a well-deserved rest.

That is, one cycle of the sensor operation - 5.5 seconds. Of course, it is logical to turn on the light in the hallway with repeated movement, I understand. But in this situation, the sensor will have to spin for at least 6 seconds, and this, as practice has shown, is too. And that is why the light turns on with each pass.

As for the rule of “three minutes”, this is also suffered. It seems that one could confine the same minute, right? Not true. It turned out that even rather restless guests can say goodbye to us in the hallway, keeping them still for more than a minute. But one rarely succeeds in freezing for three minutes at once - hence the interval.

Avtosvet work in the kitchen is less intricate. The need to generally manage the light there arose because one especially tailed cat requires that he be accompanied at night to eat. In one face, he can not.

And since I am in a semi-unconscious state at night, it would be advisable to walk to the kitchen and go back to bed in approximately the same condition. In other words, mental activity (searching for a switch, squinting eyes, etc.) is undesirable.

In general, if the motion sensor records the passage at night, the controller turns on the background light in the kitchen for 10 minutes. This is enough to feed the cat and go back. Of course, it would be possible to turn off the light when re-passing, but after all my wife may follow me, or, on the contrary, I will follow her. So why do we need a flasher or an extra garden with controllers and sensors in the kitchen?

The light in the closet has a similar level of intelligence. There, the trigger is a banal wireless reed door sensor. One opening of the door - the light turns on, the second - turns off. And so in a circle. Of course, to trigger the sensor, the door must be completely closed each time, but for the wardrobe it is just a prerequisite, otherwise cats penetrate, which is undesirable. It is also assumed that usually only one person is inside, but this is also a common thing - it will not fit there anymore.

Completes the parade of Avtosvet bathroom. I also didn’t come immediately to the current scheme with a motion sensor. At first it was easiest to use the same door sensor and the same algorithm: the door opened - the Christmas tree was burning, the door opened again - the Christmas tree was not burning. And again in a circle.

Only here the wardrobe algorithm, although it worked, turned out to be imperfect. First of all, several people can enter the bathroom (well, you never know), and you have to slam the door once more to turn on the light. Secondly, the door is not always convenient to close completely, and often (during cleaning) there is a need to run back and forth.

Still, as it turned out, it is very difficult to explain to all guests that the light-music system will work correctly only if every time you open and close the door completely. And do not touch the light switch.

The upper room is full of people

Actually, the bathroom is one of the classic examples of intractable ACS tasks. For some reason, with the help of a reasonable set of technical means and at no less reasonable cost, it is problematic to accurately control the presence and number of people in the room. I've read that the people of the city - and was horrified. Infrared barriers, ultrasound range finders, RFID tags (they are happy to say, “but you can even implant them!”) And so on and so forth.

I had to creatively rethink, impose strict restrictions and test the theory in action.

. the sensor hangs so as not to annoy the presence, in the same package with it both the controller and the receiver with the transmitter
image

I immediately refused to count the number of people. And then I did not see how the office plankton three by one in the gate passes through one pass. The presence sensor stands for a home-made system of quite space money, so I forgot about it too immediately.

In general, when Occam's razor finished cutting my dream, it left a pitiful sight — that is, the same motion sensor, the “three minutes” rule and the kamikaze psychology.

TK is quite simple:

1) The light should turn on when people appear in the bathroom;
2) The light should not turn off while someone is in the bathroom;
3) Music should work if the light is on and time resolved.

A solution that more or less satisfies all conditions, including a shower cabin - a combination of a motion sensor, a light sensor and a sensor for closing the doors of a shower cabin. The latter, incidentally, is important, because we remember that the motion sensor does not “see” through the glass.

. light sensor from a flashlight and reed switches to control the closing of the shower door. There was no blue tape, I had to get by with black
image

.
image

The basic principle of operation is that the light tends to turn off if within three minutes nothing interferes with it. This is the psychology of kamikaze.

And to prevent the act of self-switching can either a motion sensor or a shower door sensor. So while someone moves or the shower doors are closed, the light will work. In turn, the music (if allowed) plays in sync with the light.

The peculiarity of such a scheme is that it is absolutely adequate in any situation. Even if guests who do not want to learn, use the switch. Therefore, here, in contrast to the simple trigger in the wardrobe, you do not need to resort to using a door or switch to bring the light to the desired position, if someone did not open the door at the same time or pressed the button of the same switch.

But there are nuances.It turned out that you can sit quite motionless on the pot for more than three minutes, and then you have to wave your hands. This, of course, a minus. Therefore, I think that we need another weight sensor - you know, for what. Although it is extra wires in the bathroom.

No street magic

If everything is folded, it turns out exactly what I wanted. I dig in the hallway - the light turns on itself. I go to the kitchen at night - the background lighting turns on. I go into the wardrobe and also do not disappear in the dark. And the light in the bathroom works while I make an evening or some other toilet.

The house just follows the natural behavior of the inhabitants.

.so to speak, a music module for the bathroom. In the white box of the radio relay, which simply turns on the speaker-player
image

A, press the buttons, and you don’t even need to think about them. Well, except that one button that turns off all the lights and sockets at home, and turns on security at the exit, and returns everything back when returning.

Or about one more button - which includes a feeding trough, when one of the cats is passionate about wanting to eat at night, and we are just as passionate as I don't want to get up and go somewhere.

You can always see the temperature overboard either on the controller page (along with the last significant state), or on the Internet, or in the app / widget on a smartphone thanks to the People Monitoring service .

. weather in the smartphone
image

.And this is our weather dealer in the case of the bell. DHT21 sensor hangs out of the window, connected by a white cable with a plug
image

.inside, like me - a mess


Plus some things that are made just to be. That is - control of TV, media player and air conditioning. For example, pressing a button on the Android remote control simultaneously turns on the TV and starts the file browser so that you can immediately watch movies. So no need to look for a TV remote.

.The “media controller” is almost hidden in the rack niche, you can see the IR diode wire for the TV and player
image

. In general, there is no problem to automatically turn on the air conditioner depending on the room temperature, but the wife categorically refused this idea. As well as from automatic overlapping of water on triggering of leakage sensors

He thinks I’ll be somewhere nosy. Not unreasonably, however. Therefore, the fact that sometimes there are failures in the operation of controllers is rather a feature of the system, and not its disadvantage. After all, I honestly did not plan to do something for the critical areas of the national economy.

PS Yes, I know that it is quite funny to mention OPS and ACS in this context.

Source: https://habr.com/ru/post/210664/


All Articles