📜 ⬆️ ⬇️

Household automation. Start

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

Acquaintances to whom I showed my skills were “called names” by their smart home system. Personally, I don’t like this name, since the “mind’ is a rather complicated concept and, in my opinion, not everyone’s proper. Yes, and talk about any mind in computers - too early. I prefer the terms automation and automation. Simplified, the electronic world of my apartment is shown in the following image:



Where functions among devices are distributed as follows:
1) Server - low-power computer, with a large amount of disk space, an uninterruptible power supply and a fairly noisy cooling system. Hidden 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 computational tools: a smartphone, a tablet, a 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 song without getting up from the sofa; at the end of the movie I want to roll over and fall asleep and not get up and turn off the desktop and amplifier. In the end, I want the computer to play a little music before bedtime and turn off, and then he turned on in the morning instead of an alarm clock. Of course, around us a lot of various players that somehow perform such functions, but the computer, for some reason, does not know how (the AVerMedia console is not impressed, but with the transition to x64, it stopped working altogether).

So, I want to automate the following functions of my desktop:
1) 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 a schedule.

Enough to start. Let's analyze what and where we can do.

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

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 site, and ready-made code for C # can be found in Google. The library ( NAudio ) allows controlling the volume of the system, 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 young (Electronics D1-012-Stereo, 1982 release) and does not know anything about sleep modes. Turns on and off with a mechanical button. It is one thing to leave a computer (unencumbered) unattended to a sleeping person, and quite another to leave an amplifier with such an exposure time. On the Internet you can find many possible solutions to this problem for any color and taste. I like the 1-Wire technology that I have come across before. Get a basic understanding of technology here .

After making simple equipment, the device map can be redrawn as follows:



(I don’t consider work 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 large that it worries this is not worth it)

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



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

This is what my socket looks like:
Board with connection to 1-Wire bus (top) and triac (bottom) of triac:



Socket and triac:



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

On the server, we will need to serve the requests of the web interface (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 use ready-made drivers and a wrapper for .Net.
Drivers
Wrap for .Net
ATTENTION! in earlier versions there is an error on working with the thermal sensor according to the external power scheme, I don’t know if it is fixed now, but keep in mind that if you need this functionality, you will need to modify the source code a little.

Ways to organize the interaction between two computers / processes - a great many. I chose the .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 the simplest abstract example, but then I decided that the description is rather cumbersome and does not carry a load of meaning, therefore I will only give screenshots of window interfaces that I use to debug the whole scheme and run-in ideas.

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



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



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



Perspectives
I am sure that everyone, having looked at his surroundings, can offer 5-10 ideas for automating his daily life. And it is not at all necessary to immediately start studying the gas boiler control scheme (if there is one); for the first experiments, the lighting in the apartment and the ventilation in the bathroom and kitchen will be fine.

Synthesis and speech recognition


Microsoft has a freely available platform for the synthesis and recognition of human speech. Download engine and modules for synthesis and recognition here:
Runtime ;
Runtime languages .

It is worth noting that both self recognition and synthesis are done quite well. 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 ran into the inconvenience that I needed to reach for the microphone, and if I reached it, I could do the rest. But it was fun to try. To “access” a computer, I used a code phrase, 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 he had to pronounce the code phrase every time something needed from the computer - damn not convenient. And today I saw a video about Google glasses and realized that there is simply no better for today, and you need to wait a bit with speech control.
But the speech synthesizer harmoniously fit into the morning alarm clock and reports the current time. Next, I plan to “teach” him to report the weather forecast and currency rates.

Security


And last but not least - do not forget about the elementary safety rules. In my case, the web site is inaccessible from the outside world and is not worried 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 good and conscious people. At one time, my modem kept the standard port for RDP connections open and it turned out that the “outside world” was constantly searching through all sorts of logins and passwords to connect. The fact that there will be, if any young (or not) hacker gets into your file server, it is better not to know from personal experience.

Good luck with your experiments!

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


All Articles