My comfortable home

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

That is, a smart home is a home that can do anything. A comfortable home is a home that does everything it can does on its own.

Let's first, I just brag about what my house can do now, and you decide whether it makes sense to read about my bitter in some places (and in some places even nothing) experience further, ok?




Basic functions:

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

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

3) Rebooting the router when the Internet goes down;

4) Turn on and off the webcam;

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

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

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

8) Management of a cat feeder;

9) Control of a wired motion sensor (“security” and service functions);

10) Music control in the bathroom (it’s like in fashionable shopping centers - I went to the WC, and there is such relaxing music);

11) Email notification of events.

Service functions (scenarios):

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

2) Automatic light control in the hallway;

3) Automatic control of night lighting in the kitchen;

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

5) Turn off everything that turns off remotely, turn on the camera and switch the motion sensor to security mode when leaving the house; and turning off the camera with the inclusion of background light, light in the hallway and switching the motion sensor to the previous one, before guarding, the mode on return.

You can control almost all (except unconditionally automated) functions from any computer, from a smartphone and tablet with Android through the app or voice through a bunch of app. On a local network or via the Internet. The technique is the simplest - the command is transmitted by a POST request (the essence is a set of addresses in the browser).

From the beginning, and now the core of the system remains the Arduino Uno board. Her assistants are three service controllers from the Arduino Pro Mini plus a couple of radio relays in places where special intelligence is not required (a feeder, for example, and music in the bathroom). The scripts are partly in the Arduino code, partly in the Android whistle connected to the TV. The whistle simply issues the necessary requests according to the schedule.

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

The beginning of time

It is hard to say exactly when it all began. Either when I bought a pack of radio-controlled sockets, or when my wife said that in this of their Japan “every light is on the remote control”.

Probably still when Japan. So immediately, for some reason, it became a shame for the power, I could not sleep directly. Therefore, he immediately purchased from the Chinese radio-controlled switches Livolo to replace the dense keyboard and mechanical.

. such cool
image

radio switches are very important, because at the stage of repair I conscientiously proclaimed all these clever things. Of all the low-current, I came up with only a local network, and then the rest did not have enough intelligence or time. Not the workers were caught, but simply some Stakhanovites: I barely managed 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 the radio.

But even the radio-controlled switches were boring, so then everything is like everyone else. And at some point, everyone gets an Arduino. This, as I understood then, is such a magical thing that attracts newcomers and rays to ... veneration of seasoned piece of iron. Fortunately, the first worries about weakness were long gone, so I had a rough idea of ​​what I wanted.

Namely - to control radio sockets in the amount of four pieces and radio switches in the amount of the same four pieces (eight buttons). Moreover, to manage in any way - locally, via the Internet, from a computer and phone, buttons and voice. Hence the base kit:

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

If you think that this is a “cross out the unnecessary” mystery, then this is not so at all. The fact is that I was not sure of the taming of sockets and switches, so I decided that in a pinch I would simply tie the existing remotes to the relay. Crude, but effective. And not entirely ashamed - many did.

Fortunately, extreme measures were not needed, but the relays were still useful. And later the list of equipment was supplemented by 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 in China, I was already theoretically savvy and without any delay poured a classic flasher into it. I suppose she was disappointed, but it did not last long. Because the next number was the control of outlets.

Only radio, only hardcore

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

. By the way, about sockets - after all, everyone saw such, right?
image

True, the first nuance was outlined. An attempt to draw a control page directly in the Arduino code turned out to be a failure: starting at some point, the board crashed at the start. Empirically, I found out that most likely the matter is a huge number of text lines, for which Arduino did not have enough resources.

In general, I acted like a real hero - went around. He left only a web server with a command handler, and began to keep the commands in his head. This solution, of course, is full of shortcomings, but there are pluses: if an evil hacker nevertheless reaches out to Arduino, then he will still have to sweat to find out what kind of team I came up with to turn on the light. In short, a secret that no one knows is the real secret.

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

At first I was sad, and then I found no less cool than the RC-Switch thing - Protocol Analyzer . And although this utility did not help to solve the riddle of the circuit breakers, it became clear in which direction it was necessary to move on. So the kit assembled on occasion from the receiver and divider was used together with Audacity . And then I understood a lot.

Or, to be more precise, I didn’t understand as much as I looked at the command packages and considered the number of pulses and their duration with a toothpick. Yes, right, with a toothpick, right on the laptop screen. I didn’t understand the protocol then, so I stupidly pushed the buttons and encoded the corresponding sequences.

Looking ahead - this is then vague guesses and an unclear itch in the brain took shape in the Livolo circuit breaker control library , which was later supplemented by more competent comrades with the decoder of the commands of the native console and the port of this whole farm on Raspberry. But first, the commands were encoded in Russian meaninglessly and brutally, i.e. the accepted sequence of pulses of each used button I trivially transferred to the code on a 1: 1 scale.

I was still bothered by the idle relays. It was a pity to spend money aimlessly, so the relay screwed on the modem (Huawei from MGTS surprisingly often hangs) and webcams (well, why should it constantly shine before evil hackers?). Yes, yes, I understand, these are just two out of eight, but at least something.

You may be interested to know why I persistently struggled with AM transmitters without error correction and normal bidirectional communication instead of using fashionable nRF * or XBee. Probably because at first I didn’t know anything about them, and I bought what was cheaper. And then this happened historically: after all, the entire periphery that I planned to control used exactly this type of modulation. And it seemed to me not very rational to hang on the Uno a second transceiver kit.

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

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

. typical Chinese sensors (leakage and door)
image

. and inside
image

you understand, right? I got access to a large number of inexpensive and universal sensors and peripherals, with which my controller could already work without doping files.

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 door, leak and smoke sensors, and at the same time reset the modem, when the internet disappeared. Cool Of course. Conveniently? It turned out that it was not as convenient as it seemed.

. box, such a box
image

.
image

And it’s not even a matter of keeping commands in your head and typing endless POST requests in the browser. You do not need any of this, because for the smartphone that I planned to control, there is an incredible Tasker app, in which it is extremely easy (albeit a bit dreary, but always with gui) to make a remote control. The finished console, by the way, is simply exported to a separate application and in this way the system is deployed (in what words I know) to all phones and tablets.

. I'm not an interface designer, not a designer
image

.
image

Nevertheless, I was surprised how quickly it annoys me that I need some kind of remote control to turn it on and off. And I wanted more.

Comfortable home.

The house should be comfortable

I realized this principle, it seems, on an unconscious level. Imagine a situation: you are about to go out, have already put on shoes, wound up in 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 the lighting to order (or even look into the toilet on the road - plus, in general, who argues). If you have a smart home, then you take the remote control reasonably left in the hallway or open a sniff-walled up control panel. Again, if everything is correct, then you will have one button to turn off the whole world. But maybe a few. And if the smart home is not very competent, then the whole world will turn off immediately.

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

But I’m afraid of the dark, and I don’t want to get confused in the lace buttons. Therefore, at the first stage of natural home improvement, I again turned to the topic of wireless calls. Since I remembered that the call button is similar to a single-command outlet panel, and the Arduino with RC-Switch accepts the commands for one or two, the call button has turned into the “I'm home” button.

This trigger button hangs next to the front door. Click on exit - and everything that the home controller can reach will be turned off after a minute. And then the webcam will be turned on. So there’s quite a time for yourself to even glance at the mirror and calmly go out, unnoticed by the all-seeing eye.

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

In parallel, I studied the potential of the popular HC-SR501 motion sensor. Why is it he, and not a wireless motion sensor, since “only radio, only hardcore”? Everything is very simple: the wireless motion sensor will constantly clog the ether with its screams, and at the same time it will distract the controller to process them. And the controller and other things are full. Therefore - a wired sensor, and without interruptions, so, again, not to confuse the controller.

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

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

. The camera and sensor are larger. Untidy wire in the lower right - the controller reset button, which I have not yet figured out where to put
image

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

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

And although the HC-SR501 sensor is as simple as two pennies, there were some oddities. At first the light worked like a flasher. I thought that the matter was in the air flow, because the sensor looks at a rather lively place from this point of view. Therefore, infinitely long regulated the sensitivity and direction of his "gaze".

What was confusing was that sometimes after adjusting everything worked. True, not very long. And only by accident it dawned on me that the matter was either in electromagnetic interference from the transmitter and power cables passing nearby, or in the leads from them on the Arduino board. It was possible to minimize the unpleasant effect by the maximum possible spatial separation of the transmitter and the motion sensor, reducing the length of the cable connecting the sensor and the controller, as well as by crafty cable laying. The latter is an exclusively empirical way.

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 extends the work of light for three minutes (not in total, but resets the three-minute timer to zero).

A minute inclusion is, on the one hand, so that the lamps do not blink every second, and on the other, so that you do not have to turn under the sensor, so that the light turns 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 for another 2.5 seconds it has a well-deserved rest.

That is, one cycle of the sensor is 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 much. And that is why the light turns on with each pass.

As for the “three minutes” rule, this is also a pain. It seems that one could limit oneself to that minute, right? Not true. It turned out that even rather restless guests can say goodbye to us in the hallway, while remaining motionless for more than a minute. But rarely does anyone succeed in freezing for three minutes - this is the interval from here.

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

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

In general, if a motion sensor detects a passage at night, then the controller turns on the background light in the kitchen for 10 minutes. This is enough to feed the cat and come back. Of course, it would be possible to turn off the light during repeated passage, but after all, my wife can follow me, or, conversely, I can follow her. Well, 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 switch for the door. One door opening - the light turns on, the second - turns off. And so in a circle. Of course, for the sensor to operate, the door must be completely closed every time, but for the wardrobe this is just a prerequisite, otherwise cats will penetrate, which is undesirable. It is also assumed that there is usually only one person inside, but this is also a common thing - it will not fit there anymore.

The bathroom completes the auto-light parade. I also did not immediately come to the current circuit 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 burn, the door opened again - the Christmas tree do not burn. And again in a circle.

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

Also, as it turned out, it is very difficult to explain to all guests that the light music will work correctly only if each time the door is opened and closed completely. And do not touch the light switch.

Full of people

Actually, the bathroom is one of the classic examples of intractable ACS tasks. For some reason, using a reasonable set of technical means and at no less reasonable cost, it is difficult to accurately control the presence and number of people in the room. I read that the people are foolish - and was horrified. IR barriers, ultrasonic rangefinders, RFID tags (they gladly say “well, you can even implant them!”) And so on and so forth.

I had to creatively rethink, introduce stringent restrictions and test the theory in action.

. the sensor hangs so as not to annoy the presence, in one housing 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 office plankton in three at the gate passes through one pass. The presence sensor costs quite a lot of space money for a home-made system, so I immediately forgot about it too.

In general, when Occam’s razor finished cutting my dream, she left a miserable sight - i.e. the same motion sensor, the “three minutes” rule, and 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 there is someone in the bathroom;
3) Music should work if the light is on and allowed in time.

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

. light sensor from a flashlight and a reed switch to control the closing of shower doors. There was no blue electrical tape, I had to do black
image

.
image

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

A self-shutdown act can be prevented either by a motion sensor or a shower door sensor. So as long as someone moves or the doors of the shower are closed, the light will work. In turn, the music (if allowed) plays synchronously 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 study, use the switch. Therefore, here, unlike a 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 this door on 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, is a minus. Therefore, I think that we need another weight sensor - you yourself understand why. Although these are 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 simply 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 includes the player column
image

A, you do not have to press the buttons, and you don’t even need to think about them. Well, except for one button that turns off all the lights and sockets at home, and turns on security mode when exiting, and returns everything back when you return.

Or one more button - which turns on the feeding trough, when one of the cats has passion as he wants to eat at night, and we also have passion as we don't want to get up and go somewhere.

You can always see the temperature overboard either on the controller’s page (together with the last significant state), or on the Internet, or in the app / widget on your smartphone thanks to the “People’s Monitoring” service .

. weather in the smartphone
image

. and this is our weather dealer in the housing from under the bell. The DHT21 sensor dangles outside the window, connected by a white cable with a plug
image

. inside, like mine is a mess


Plus, some things that are done just to be. That is - control of the TV, media player and air conditioning. For example, pressing a button on the Android remote control simultaneously turns on the TV and launches a 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 niche of the rack, you can see the IR diode wire for the TV and the player
image

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

He thinks that I’ll definitely mess up somewhere. Not without reason, however. Therefore, the fact that sometimes there are failures in the operation of controllers is more likely a feature of the system, and not its drawback. I honestly did not plan to do something for the critical areas of the national economy.

PS Yes, I know that mentioning OPS and ACS in this context is rather ridiculous.

Also popular now: