Household automation. Start

Electronic computing tools, today, are quite tightly integrated into our daily lives, but many of us are not aware of the potential of these tools and how we can use it; either guess, but find it difficult for a layman. I want to talk about my experience of expanding the functionality of my home electronics.

My acquaintances, to whom I showed my achievements, “called” them a smart home system. Personally, this name is not to my liking, since “mind” is a rather complicated concept and, in my opinion, not inherent in every person. Yes, and talking about any mind in computers is too early. I prefer the terms automation and automation. To simplify, the electronic world of my apartment is depicted in the following figure:



Where the functions among the devices are distributed as follows:
1) Server - a low-power computer, with a large amount of disk space, uninterruptible power supply and a fairly noisy cooling system. Tucked away somewhere in the closet and does not interfere with sleep.
2) Desktop - a quiet non-gaming computer with an audio system for watching movies, listening to music and surfing.
3) A number of other computing tools: smartphone, tablet, wife’s laptop and my laptop.

In my opinion, a very common list of “guests” for any modern family. Very often the desktop is used as a media player, but turning on / off and controlling the process while sitting near it is not comfortable: I want to switch the composition without getting up from the couch; at the end of the film, I want to roll over to the other side and fall asleep rather than get up and turn off the desktop and amplifier. In the end, I want the computer to play some music before bedtime and turn off, and then turn on itself in the morning instead of an alarm clock. Of course, there are many different players around us that perform such functions in one way or another, but the computer, for some reason, does not know how (the remote control from AVerMedia did not impress, but completely stopped working with the switch to x64).

So, I want to automate the following functions of my desktop:
1) Turn on / off;
2) Media player control (forward / backward, quieter / louder, start / stop)
3) Turn on / off the stereo amplifier;
4) perform all of the above on schedule.

Enough for a start. We will analyze what and where we can do.

1) Computer
Turning off the computer is very simple - call the Windows API function (SetSuspendState from the Powrprof.dll library).
Turning it on is a little more difficult, but the task becomes much easier if you do not turn off the computer and put it into sleep mode. Now it can be woken up either by the activity of USB devices (with appropriate settings) or by using Wake-on-Lan technology (you can read about what it is here) Given that I have an always available server, it could send a wake-up command to the desktop without any problems.

2) Audio player
Almost any modern player has a description of its API. I use AIMP. A description of its API is available on the developer's website, and ready-made code for C # can be found in Google. To control the volume of the system allows the library ( NAudio ) which, by the way, can do a lot of useful things and can be taken as the basis for an alternative audio player.

3) Amplifier
Here things are somewhat more complicated. Personally, my amplifier is quite old (Electronics D1-012-Stereo, 1982) and does not know anything about sleep modes. Turns on and off with a mechanical button. It is one thing to leave a computer unattended while sleeping (the usual thing) and quite another - an amplifier with such an exposure time. On the Internet you can find many possible solutions to this problem for every color and taste. I like the technology of 1-Wire, which I have already encountered before. You can get a basic understanding of technology here .

After manufacturing simple equipment, the device diagram can be redrawn as follows:



(I don’t consider working with temperature sensors here and displayed them for clarity and demonstration of functionality, as well as the presence of more than one controlled outlet. Theoretically, the maximum number of simultaneously connected devices is limited, but the size, in the scale of a one-room apartment, is so great that it worries this is not worth it)

First we need to assemble the adapter of the computer's communication port into the 1-Wire bus. Since I used the COM port, I first assembled the RS232 -> UART converter ( according to this scheme ),
and then the adapter itself - according to the following (since I’m not particularly in electronics, I turned to a specialist for help in choosing and consulting on the schemes):



Unfortunately, there were no photos as it turned out, because I hid this case in a hard-to-disassemble case (and used a lot of electrical tape, I know that it is bad manners, but I really wanted to see everything in work as soon as possible).
To control the outlet - use the scheme . In general, at this address you can find a lot of useful information.

This is what the socket looks like in my version: A
board with a 1-Wire bus (top) and a remote transistor (bottom):



Socket and triac:



Now we have all the necessary “equipment” in our hands and you can proceed to programming.
I defined a typical control path as follows: tablet -> server -> computer. Since there are three devices, we will need three modules, one for each device.

On the server, we need to serve web interface requests (this is the simplest solution, covering a fairly wide range of portable, and not only devices), manage the outlet and send commands to the client. As for the 1-Wire bus, I decided not to reinvent the wheel but to use ready-made drivers and a wrapper for .Net.
Drivers
Wrapper for .Net
ATTENTION! in early versions there is an error in working with the temperature sensor according to the scheme with external power, I don’t know if it is fixed now, but keep in mind - if this functionality is needed - you will need to slightly modify the sources.

There are a lot of ways to organize the interaction between two computers / processes. I chose .Net Remoting technology, which, although outdated, is completely suitable for our purposes. With its help, the web form communicates with the server and the server with the client.

At first, I wanted to describe either my test project or an abstract simplest example, but then I decided that the description is rather cumbersome and does not carry a semantic load, so I will only give screenshots of the window interfaces that I use to debug the whole scheme and run in the incoming ideas.

Server form.
The heart of the system is the collection of temperature data from external (1-Wire) and internal (motherboard, using the openhardwaremonitor project ) sensors.
Support for the entire infrastructure and monitoring the status of the ADSL modem via telnet (mine does not know how to reconnect, I have to help juggle the shutter):



Client.
Displays incoming commands from the server and allows you to initiate some of them:



Web form.
Primitive, bulky, but it looks good on the tablet and works;)



Prospects
I am sure that everyone, looking at their surroundings, can offer 5-10 ideas for automating their everyday life. And it’s not at all necessary to immediately take up the study of the gas boiler control scheme (if any), for the first experiments, lighting in the apartment and ventilation in the bathroom and kitchen will come down.

Speech synthesis and recognition


Microsoft has a freely accessible platform for the synthesis and recognition of human speech. You can download the engine and synthesis and recognition modules here:
Runtime ;
Runtime Languages .

It is worth noting that the recognition and synthesis itself are very well done. This is certainly not what we see in science fiction films, but it is something that works and can be used in practice today.
When testing voice recognition, I encountered the inconvenience of reaching for a microphone, and if I reached for it, I can do the rest. But it was very funny to try. He used a passphrase to “access” the computer, after which he began to “listen” to the command (some time after the first command, the following were perceived without a preliminary phrase), but it turned out that pronouncing the passphrase every time something was needed from the computer damn not comfortable. And today I saw a video about glasses from Google and realized that there is simply no better thing today and you need to wait a bit with voice control.
But the speech synthesizer harmoniously fit into the morning alarm clock and reports the current time. Further I plan to “teach” him to report weather forecasts and exchange rates.

Security


And last but not least, do not forget about basic safety rules. In my case, the web site is inaccessible from the outside world and it is not worth worrying about intruders, but if you plan to open access to the outside world, be vigilant, because it is very naive to expect that you are surrounded by exceptionally kind and conscious people. At one time, my modem kept open the standard port for RDP connections, and it turned out that the “outside world” was constantly sorting through all kinds of logins and passwords for connecting. About what will happen if some minor (or not so) hacker penetrates your server file, it is better not to know from personal experience.

Good luck with your experiments!

Also popular now: