"Smart home" with your own hands. Part 5. X10 technology

    image

    In the last article, we fastened 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 conceived - load management. By load is meant any electrical device that makes sense to control.
    For details of the implementation, I ask under cat.


    A small introduction or what is 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 home electrical appliances. So what is its advantage over the 1-wire protocol? The thing is that for communication with receivers, the X10 controller uses conventional wiring, which avoids unnecessary wires and gets to hard-to-reach places (for example, someone does not want to spoil the repair;)

    What's inside?


    To transmit X10 signals, “packets” of oscillations are used at a frequency of 120 kHz for a duration of 1 ms. 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 bulb holder) “listens” 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 denoted by a Latin letter (from A to P), and the device code is indicated by a number from 1 to 16.

    Each x10 command also has its own binary code. The last bit in the 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 the so-called start code - it corresponds to sequence 1110. It is followed by the house code, and then the device code or command. The sequence of the start code, home code and device or command code 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 start code bits, is accompanied by a complementary (complementary) bit - after 1 there is a complementary 0, after 0 - one. Thus,

    To send the X10 command, you must first send a frame with the code of the device to which the command is intended, and after it - 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 does not need to be transmitted.

    When transmitting a sequence of addresses and / or commands, between each pair of frames there must be a gap of three cycles of alternating voltage - that is, the sequence 000000. For example, the device address and the command for it are transmitted in two pairs of frames with the specified interval. To transmit such a sequence, 22 + 3 + 22 = 47 voltage cycles are necessary. At a frequency of 50 Hz, this operation takes about one second. Perhaps this is the biggest minus 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 signal transmission in a single-phase network. In three-phase networks, signal transmission occurs in a similar way, but is "timed" to zero of each phase. X10 teams are usually do not pass between different phases. This means that you must either connect all devices to a certain phase, or use special devices - repeaters, which are far from always available for sale. In addition, repeaters contribute to the delays associated with the transfer of commands, actually doubling them. This is actually a big problem, because usually with a 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 a room will be powered from the first phase and the other from the second . associated with the transfer of teams, actually doubling them. This is actually a big problem, because usually with a 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 a room will be powered from the first phase and the other from the second . associated with the transfer of teams, actually doubling them. This is actually a big problem, because usually with a 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 a room will be powered from the first phase and the other from the second .

    Equipment


    What is needed to organize a smart home with such technology? 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 range from extremely simple to very smart.
    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
    • Brighter (Brighten) / Darker (Dim) (last selected device)
    • Turn on all lights / Turn off all

    Smarter controllers can control a large number of devices and / or include timers that execute pre-configured commands every day at a given time. Devices that use passive infrared motion sensors or photocells to turn lights and other modules on and off are also available.

    Finally, there are devices that can be programmed or they can be used by a program running on a computer. These systems can execute various synchronized events, respond to external sensors and commands, execute scripts, turn on and off the lighting, level its brightness and so on.

    It is the latter type of controllers that interests us. A short Google session suggested that the most appropriate model in my case isCM11A . This miracle looks something like this:

    image

    As you can see, on the one hand it is inserted into a regular outlet (preferably not in a filter), and 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 .
    It comes with the ActiveHome program, which, however, does not interest us;) We

    figured out the controller, now let's move on to what it controls.

    X10 technology helps solve a variety of home automation tasks. For example, you can turn the light on and off at a given time, remotely change the brightness of the lighting, control electrical appliances using a computer, open the curtains, turn on the security and fire alarms, and do many other useful things. For this, various types of devices supporting x10 have been developed. I will list them:
    • Executive modules (receivers) - receive and execute x10 commands. Each receiver has an address consisting of a house code and a device code, such as A10. Multiple receivers can have the same address - in this case they are controlled simultaneously. The receivers can be, for example, lamp and instrument socket modules, wall switches, dimmers in the lamp socket, blind drives, dimmer modules for resistive load control
    • Transceivers - receive signals from remote controls (IR or radio), convert to x10 format and transmit to the mains
    • Remote controls - provide remote control of X10 devices via infrared 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 X10 Signal Attenuation

    In systems based on the X10 standard, auxiliary equipment is also used, which itself does not transmit or receive signals using the X10 protocol. This, for example, motion sensors, lighting, glass breaking, opening doors or windows. They transmit information via radio or IR channels to transceivers, and they send it to the executive modules via the X10 protocol.

    It is worth noting that there are many executive modules on the market, using which, you can solve almost any task of home automation. I, for sample, I took the executive module in the form of a lamp cartridge called LM15S. The module bribed with ease of installation (screw in, like an ordinary light bulb), and relative cheapness. The module has become an additional separate source of illumination in my chandelier when I want dim lights. It is worth noting that it is quite inconvenient for them to control using a conventional switch.

    Software


    What do we need to do to be able to control our module using a computer? To get started, install the necessary software. There are several systems for communicating with the controller under Linux. I settled on HEYU ( offsite ).

    Installation is simple and straightforward: download the sources, look at the contents of INSTALL, follow the instructions;)

    Let's try it in action! First, we need to set an address for our module. I’ll do this: screw the module together with the controlled lamp into the cartridge. To assign the LM15S house code and module code, you must apply voltage to the LM15S module with a switch. Then, within 30 seconds, we submit 3 commands to enable 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 simple commands: Accordingly, the first is to turn on the lamp, the second is to turn off. Some modules allow you to smoothly change the illumination: Which sets the lamp brightness to 10 steps out of 22. Having figured out the controls, let's move on to integrating into our software.

    nix@nix-boss:~$ heyu on a1
    nix@nix-boss:~$ heyu off a1



    heyu dim a5 10




    Integrate X10


    Add the srv.pl script to the checkcmd () subroutine 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. Here, of course, there is not enough verification 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. Further, it all depends on your imagination and capabilities.

    I want to express my gratitude to those who were interested in these posts. Perhaps I described everything I wanted. If anyone has any questions - please, I’ll try to answer everyone.

    Thanks for attention ;)

    Also popular now: