X10 extended dim, another solution, works with Homekit, pure lua, no shell calls
Posted: Wednesday 14 October 2020 9:21
I'm completely new to Domoticz, just installed last weekend, learning this system all the time. So this could be stupid way of scripting x10 dimmers, but I couldn't figure out better way.
This works well enough from Domoticz UI and also from Apple Homekit. But it requires 2 devices, one actual X10 device set up as on/off and another one specially named virtual dimmer for each x10 dimmer you have. This is because the device event triggered for set level command to x10 device set as dimmer from Homekit was completely weird and also because x10 dimmers have their dimming slider disabled in domoticz ui.
Device naming, let's say you have following at address A1
"My device name" set up as actual X10 device, on/off type.
"My device name ::a1" set up as virtual dimmer
It uses native mochad support for the usual on/off, and opens tcp socket to mochad for the xdim. So no external bash script calls or anything like that. Just open your events, copy paste this as new script, set it to trigger on device changes, create your special devices with ::XX naming and you're good to go. And you need to install lua-socket if you don't have it yet.
Questions for you experienced domoticz people:
1) Is there a way to get x10 address of a device from within the script? (I couldn't find, so I added it to the device name
)
2) Any way enable X10 dimmer slider? (Needed to play with virtual devices to get the dimming command in domoticz...)
3) Do you see any potential problems with this implementation?
This works well enough from Domoticz UI and also from Apple Homekit. But it requires 2 devices, one actual X10 device set up as on/off and another one specially named virtual dimmer for each x10 dimmer you have. This is because the device event triggered for set level command to x10 device set as dimmer from Homekit was completely weird and also because x10 dimmers have their dimming slider disabled in domoticz ui.
Device naming, let's say you have following at address A1
"My device name" set up as actual X10 device, on/off type.
"My device name ::a1" set up as virtual dimmer
It uses native mochad support for the usual on/off, and opens tcp socket to mochad for the xdim. So no external bash script calls or anything like that. Just open your events, copy paste this as new script, set it to trigger on device changes, create your special devices with ::XX naming and you're good to go. And you need to install lua-socket if you don't have it yet.
Code: Select all
commandArray = {}
local mochadcommand
local tab_deviceName
local tab_deviceValue
local dimValue
local host, port = "127.0.0.1", 1099
local socket = require("socket") --- sudo apt-get install lua-socket
local tcp = assert(socket.tcp())
function split(inputstr, sep)
local t={}
for str in string.gmatch(inputstr:gsub(sep,"\0"), "([^\0]+)") do
table.insert(t, str)
end
return t
end
function trim(s)
return s:match "^%s*(.-)%s*$"
end
function sendToMochad(mochadCommand)
tcp:connect(host, port);
tcp:send(mochadCommand.."\n");
tcp:close()
end
for deviceName,deviceValue in pairs(devicechanged) do
tab_deviceName = split(deviceName,"::") -- device name format for our special dimmer devices "Whatever Device ::A1"
if tab_deviceName[2] ~= nil then -- our specially named dimmer device
if deviceValue == "Off" or deviceValue == "On" then
commandArray[trim(tab_deviceName[1])] = deviceValue -- domoticz native mochad support can handle these just give it the first part of the name
else
if deviceValue:sub(1,9) == "Set Level" then -- now we're dimming
tab_deviceValue = split(deviceValue.."","%s")
dimValue = math.floor(tab_deviceValue[3]*0.63)
mochadCommand = "pl "..tab_deviceName[2].." xdim "..dimValue
print("Trigger dimmer "..tab_deviceName[1]..": "..mochadCommand)
sendToMochad(mochadCommand)
end
end
end
end
return commandArray
Questions for you experienced domoticz people:
1) Is there a way to get x10 address of a device from within the script? (I couldn't find, so I added it to the device name

2) Any way enable X10 dimmer slider? (Needed to play with virtual devices to get the dimming command in domoticz...)
3) Do you see any potential problems with this implementation?