X10 with CM11a
Purpose
The purpose of the the first part is to connect the hardware. The second part of this page is to enable Domoticz to send X10 commands over the powerlines with the CM11a module. The third part enables Domoticz to listen to commands that are send over the powerlines by X10 modules. The CM11a is not supported from Domoticz directly but by following the below explanation it works nicely. I have got it workling together with a Raspberry PI.
Preparation
Like always before doing an installation on a live system make a backup of the domoticz.db and better also a copy of the whole SD card (Image) before starting.
Part 1: Hardware
The CM11a was sold under various brand names and with various powerline connections. The connnection to the computer needa to be done with a serial to USB converter. The serial to USB converter delivered with the CM11a is supported by the raspberry PI already. If you have multiple USB devices please also read the page for persistent USB devices on this wiki.
Part 2: Enabling Domoticz to send X10 command using Heyu software
First Heyu software needs to be installed on the computer. This website will explain you how that works in more detail. Heyu Homepage
The raspberry installation does not come with a compiler. I used this compiler to compile the software.
sudo apt-get install build-essential
Try to get the usb device on port "ttyUSB0" please also see persistent USB devices. If you need to use an other USB device please alter this in the Heyu configuration file.
# /home/pi/.heyu/x10config
TTY /dev/ttyUSB0
To test if the Heyu software can see the CM11a use this command in the terminal
heyu info
After installation of the software you can test sending commands from the command line in the terminal.
heyu on i7
heyu off a2
This command will send the X10 command "on" to the X10 housecode i number 7 and the off command to adres housecode a number 2
If this part is working you can add a dummy x10 device to your Domoticz setup. This dummy is to trigger a LUA script. This script execute the above mentioned HEYU system commands belonging to the X10 device module we want to configure in Domoticz.
-- ~/domoticz/scripts/lua/script_device_Apparaat01.lua
commandArray = {}
if (devicechanged['Apparaat01'] == 'On') then
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu on i11')
elseif (devicechanged['Apparaat01'] == 'Off') then
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu off i11')
end
return commandArray
To enable X10 dimmer modules in Domoticz we need to do a litlle more. First we need to setup an user variable the remembers the last dimm setting of the dimmer. This need to be done in Domoticz going to settings -> more options -> user variables. There an integer needs to be defined with a logical name. The this LUA script needs to be setup that executes the HEYU commands.
-- ~/domoticz/scripts/lua/script_device_LKantoor.lua
commandArray = {}
if (devicechanged['L Kantoor'] == 'On') then
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu on i1')
elseif (devicechanged['L Kantoor'] == 'Off') then
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu off i1')
elseif (devicechanged['L Kantoor'] == 'Set Level' and tonumber(otherdevices_svalues['L Kantoor']) > uservariables["L KantoorDimStand"]) then
DimstandDelta = otherdevices_svalues['L Kantoor'] - uservariables["L KantoorDimStand"]
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu bright i1 ' .. math.ceil(DimstandDelta/14*22))
commandArray['Variable:L KantoorDimStand']= tostring(uservariables["L KantoorDimStand"] + DimstandDelta)
elseif (devicechanged['L Kantoor'] == 'Set Level' and tonumber(otherdevices_svalues['L Kantoor']) < uservariables["L KantoorDimStand"]) then
DimstandDelta = uservariables["L KantoorDimStand"] - otherdevices_svalues['L Kantoor']
os.execute('sudo -u pi /home/pi/heyu-2.10/heyu dim i1 ' .. math.ceil(DimstandDelta/14*22))
commandArray['Variable:L KantoorDimStand']= tostring(uservariables["L KantoorDimStand"] - DimstandDelta)
end
return commandArray
Please read the Heyu manual in the terminal for more nice functionality. Like "shopen"
heyu help
Part 3: Enabling Domoticz to listen to X10 command using Heyu software
First start heyu to work on the background
heyu start
To check if Heyu is indeed running execute this command, you now should see two lines of background processes
ps -A|grep heyu
To test if everty thing is working properly run the command in the terminal prompt.
heyu monitor
If you now send x10 command over the powerlines with a x10 transmitter you will see them in the terminal passing by.
To start Heyu at reboot and in case it fails (it does sometimes) it must be restarted again every hour. Run this command to edit the cron.
crontab -e
Now add these line to the file,
0 * * * * /home/pi/heyu-2.10/heyu start
@reboot /home/pi/heyu-2.10/heyu start
Now we can first define our aliases for x10 housecode and module numbers that we need in the heyu configuraton file. These aliases can also be used to send command from the tetrminal prompt. Please see some examples of defined
# /home/pi/.heyu/x10config
ALIAS Switch_Keuken_Midden I1 StdLM
ALIAS Switch_Keuken_Hoog I3 StdLM
ALIAS Switch_Badkamer I5 StdLM
ALIAS Switch_Kamer I6 StdLM
We can use the json api to let Heyu send commands to Domoticz. Please see this wiki for more explanation on json api. Please add in domoticz the IP adres of your pi to the safe ip adresses that do not need to login. This can be done in the setting, setting, local networks.
Here are some examples to use the domoticz api with json in the heyu configuration file.
# /home/pi/.heyu/x10config
SCRIPT Switch_Keuken_Midden off rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=121&switchcmd=On&level=0"
SCRIPT Switch_Keuken_Hoog on rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=121&switchcmd=On&level=0"
SCRIPT Switch_Badkamer on rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=121&switchcmd=On&level=0"
SCRIPT Switch_Badkamer off rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=121&switchcmd=On&level=0"
SCRIPT Switch_Kamer on rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=92&switchcmd=On&level=0"
SCRIPT Switch_Kamer off rcvi :: curl "http://192.168.0.124:8080/json.htm?type=command¶m=switchlight&idx=92&switchcmd=Off&level=0"