
In the
last article, we screwed a small web interface to our smart home system. It's time to turn to the part of the case for which all this is being done - load management. By load is meant any electrical device that makes sense to manage.
For implementation details, please under the cat.
A small introduction or something like X10
The X10 communication protocol and the standard based on it have been known to the world for a long time. The standard was developed in 1975 by Pico Electronics for the management of household electrical appliances. So what is its advantage compared to the 1-wire protocol? The fact is that for communication with receivers, the X10 controller uses conventional wiring, which allows to avoid unnecessary wires and get to hard-to-reach places (for example, someone will not want to spoil the repair;)
')
What's inside?
To transmit X10 signals, “packets” of oscillations at a frequency of 120 kHz with a duration of 1 ms are used. The signal transmission in X10 is synchronized with zero voltage in the AC circuit. When the voltage reaches zero, the X10 signal receiver (for example, built into the lamp holder) “listens” to the network for 6 ms. If at this time the x10 signal transmitter sends a “packet”, the receiver perceives it as a unit. The absence of a “package” is perceived as zero. Each device controlled by x10 has its own address consisting of two characters. The first is the house code, the second is the device code. Each of them can have 16 values, and the total number of different addresses reaches 256. The house code is indicated by a Latin letter (from A to P), and the device code is a number from 1 to 16. By wiring, each house and device code is transmitted by its own sequence of zeros and units - binary code.
Each x10 command also has its own binary code. The last bit in binary codes of the device and the command is used to distinguish the type of codes: 0 corresponds to the device code, 1 to the command code. In order for the receiver to know when the transmission of the useful signal begins, the transmitter first sends a so-called start code - sequence 1110 corresponds to it. It is followed by the house code, and then the device code or command. The sequence of the start code, house code, and device code or command is called an X10 frame (or frame). Each frame is transmitted twice in a row - for greater reliability. Each information bit of the frame, with the exception of the bits of the start code, is accompanied by a complementary (complementary) bit — after 1 there is a complementary 0, after 0 - one. Thus, it takes 11 cycles of alternating voltage to transmit one frame.
To send an X10 command, you must first send a frame with the device code to which the command is intended, and after that - a frame with the command itself. The exception is group commands, for example, “All Units Off” - they are sent to all devices, so the device code in front of them is not necessary to send.
When transmitting a sequence of addresses and / or commands between each pair of frames, there should be an interval of three cycles of alternating voltage — that is, the sequence 000000. For example, the device address and the command for it are transmitted by two pairs of frames with the specified interval. To transmit such a sequence, 22 + 3 + 22 = 47 voltage cycles are necessary. With a frequency of 50 Hz, this operation takes about one second. Perhaps this is the biggest disadvantage of this technology compared to 1-wire, where commands are transmitted almost instantly. I note that the commands "Bright" ("Brighter") and "Dim" ("Darker") follow each other without a gap between the codes. This is an example of signaling in a single-phase network. In three-phase networks, signal transmission occurs in a similar way, but is “confined” to zero of each phase. X10 commands usually do not pass between different phases. This means that it is necessary either to connect all the devices to a specific phase, or to use special devices - repeaters, which are not always commercially available. In addition, repeaters contribute to the delays associated with the transfer of commands, actually doubling them. This is actually a big problem, since usually with 3-phase power supply they try to separate the phases so that the load on them is uniform, which means that it is likely that one group of outlets or the room will be powered from the first phase, and the other from the second .
Equipment
What is necessary for the organization of a smart home on this technology? To begin with, first of all - the controller. This is the head of the entire X10 network. It is he who sends control commands to the network.
X10 controllers vary from extremely simple to very “savvy”.
The simplest controllers can control four X10 devices with four consecutive addresses (1-4 or 5-8). Such controllers usually contain the following buttons:
- Device 1 On / Off
- Device 2 On / Off
- Device 3 On / Off
- Device 4 On / Off
- Brighten (Brighten) / Darker (Dim) (last selected device)
- Turn All Light On / Off All
Smarter controllers can control a large number of devices and / or include timers that execute pre-configured commands every day at a specified time. Devices are also available that use passive infrared motion sensors or photocells to turn lights and other modules on and off.
Finally, there are devices that can be programmed or they can be used by a program running on a computer. These systems can perform various synchronized events, respond to external sensors and commands, execute scripts, turn lights on and off, equalize its brightness, and so on.
It is the last type of controllers that interests us. A small Google session suggested that the CM11A is the most appropriate model in my case. This miracle looks like this:

As you can see, on the one hand it is inserted into an ordinary socket (preferably not in the filter), on the other - into the COM port of our computer. For those who do not have COM, there is a controller option with a USB-COM adapter -
CM11USB .
Comes with ActiveHome, which, however, does not interest us;)
With the controller figured out, now move on to what he manages.
X10 technology helps to solve a variety of home automation tasks. For example, you can turn the lights on and off at a given time, remotely change the brightness of the lighting, control electrical appliances using a computer, move the curtains apart, turn on the security and fire alarms and do many other useful things. To do this, developed various types of devices that support x10. I will list them:
- Executive modules (receivers) - receive and execute commands x10. Each receiver has an address consisting of a house code and a device code, for example, A10. Multiple receivers can have the same address - in this case they are controlled simultaneously. Receivers can be, for example, lamp and device socket modules, wall switches, dimmers in lamp holders, blind drives, dimmer modules for controlling resistive loads
- Transceivers - receive signals from remote controls (IR or radio), convert to x10 format and transmit to the grid
- Remote controllers - provide remote control of X10 devices via IR or radio channels. There are also universal remote controls for controlling x10 devices and audio / video equipment
- Equipment for improving the quality and reliability of X10 systems - signal amplifiers and repeaters, filters for suppressing electromagnetic interference. In simple systems, you can often do without these devices.
- Measuring equipment - designed to measure the attenuation of X10 signals
In systems based on the X10 standard, ancillary equipment is also used, which itself does not transmit or receive signals using the X10 protocol. This, for example, motion sensors, light, breaking glass, opening doors or windows. They transmit information via radio or infrared channels to transceivers, and they send it to the executive modules using X10 protocol.
It is worth noting that there are a lot of executive modules on the market, using which you can solve almost any home automation task. I, for the test, I took the executive module in the form of a lampholder called
LM15S . Module bribed ease of installation (screw, like a regular light bulb), and the relative cheapness. The module has become an additional separate light source in my chandelier when I want a dimmed light. It is worth noting that they are quite inconvenient to manage using a conventional switch.
Soft
What do we need to do to be able to control our module using a computer? First, install the necessary software. There are several systems to communicate with the controller under Linux. I stopped at
HEYU (
offsite ).
Installation is simple and uncomplicated: download the source, look at the contents of INSTALL, follow the instructions;)
Let's try it in action! To begin with, we need to set the address to our module. Let's do it: screw the module together with a controlled lamp into the cartridge. To assign the LM15S code for the house and the module code, it is necessary to energize the LM15S module with a switch. Then, within 30 seconds, we will send 3 commands to be turned on by our controller to the address that we want to assign to the module:
nix@nix-boss:~$ heyu on a1
nix@nix-boss:~$ heyu on a1
nix@nix-boss:~$ heyu on a1
After that, our module is assigned the address A1 in the X10 network. Simple enough.
On some devices, the address can be set using jumpers. For example, on devices manufactured by
Marmitek .
Now we can control our lamp with uncomplicated commands:
nix@nix-boss:~$ heyu on a1
nix@nix-boss:~$ heyu off a1
Accordingly, the first - the inclusion of the lamp, the second - off. Some modules allow you to smoothly change the light:
heyu dim a5 10
That will set the lamp brightness to 10 steps out of 22.
With the management figured out, let's move on to integration into our software.
Integrating X10
Add to the
checkcmd () subroutine of the
srv.pl script after the lines:
201 if($text =~ //) 202 { 203 my $up = `uptime`; 204 $up =~ /(.*?) up/; 205 sayText(" $1"); 206 return; 207 }
Following:
208 if($text =~ //) 209 { 210 system('heyu on a1'); 211 sayText(" "); 212 return; 213 } 214 215 if($text =~ //) 216 { 217 system('heyu off a1'); 218 sayText(" "); 219 return; 220 }
It's simple;) Now, if you can say: “System, turn on the lamp” or “System, turn off the lamp” and see the result. There is certainly not enough checking, if there will be a lot of lamps or it will be possible to turn on not only the lamp. Just add one more condition:
208 if($text =~ //) 209 { 210 system('heya on a1') if $text =~ //; 211 system('heyu on a2') if $text =~ //; 212 sayText(" "); 213 return; 214 } 215 216 if($text =~ //) 217 { 218 system('heya off a1') if $text =~ //; 219 system('heyu off a2') if $text =~ //; 220 sayText(" "); 221 return; 220 }
Here you can add and experiment endlessly. Then everything depends on your imagination and capabilities.
I want to thank those who are interested in these posts. Perhaps I described everything I wanted. If someone has any questions - you are welcome, I will try to answer everyone.
Thanks for attention ;)