Page 1 of 1
LightWaveRF Switch and Link Hub Integration
Posted: Saturday 11 March 2017 14:51
by lonebaggie
I have collected my various lightwaveRF scripts into one universal script. This script will register the Domoticz Server as a lightwave link client. It does not require RFLink or any other third party 433 wireless hardware. It works natively with the LightwaveRF Link hub.
It can currently control lights, dimmers and switches (these are all the devices I have). Parameters are handled via a single user variable.
The script requires luasockets to work correctly
(removed this requirement in 1.4).
EDIT Updated to 2.1 now supports all Lightwave power and lighting API see
https://api.lightwaverf.com/lighting_power.html
Quick Steps
1 Create Dummy Hardware
2 Create as many virtual switches as required
3 Note IDx numbers of switches
4 Create blank variable string LW-Setting
5 Create a blank Lua device event and copy script into event
6 Edit LW-Settings to match virtual switches
All documentation in script header
Please use the latest script currently version 2.0
Code: Select all
-- This program control LightWaveRF switches, dimmers and sockets via the LIghtWaveRF link
-- The program requires lua sockets to be installed
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off and dimmer virtual switches are supported.
-- No configuration of the virtual switch is required.
--
-- The program relies on a user string variable to be created in Domoticz interface with the name LW-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|RnDn|IDx|RnDn
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- RnDn is R=room n=Number D=Device n=Number (example R1D2)
--
-- Room numbers and device numbers are determined by the LIghtWaveRF app
-- Room 1 is the first room displayed in the app. Devices follow the same pattern
-- Repeat sequence for the number of switches, and dimmers required.
--
-- Example configuration 192.168.1.20|67|R1D1|68|R1D2|69|R2D1
--
-- LightwaveRF LInk has a built in security measure and will not allow any device to control lights and switches
-- without being registered to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LIghtWAveRF link this script will not work until registered !
-- To register you will need to setup a temporary switch to be used just once as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string variable in LW-Settings
--
-- ipaddress|IDx|Reg
--
-- Once the virtual switch has been switched on or Off, the LIghtWAveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domoticz Server.
-- Once registered remove the Reg setting from LW-Setting and replace with RnDn settings.
--
-- To de-register the Domoticz Server run the above procedure but substitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.0
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
LWCmd = "001,!"
On="F1"
Off="F0"
Dim="FdP"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
function UDPSend(ip, message)
local port = 9760
local socket = require "socket"
sock, msg = socket.udp()
if sock then
sock:setpeername(ip, port)
sock:send(message)
sock: close()
end
return
end
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all Vars from uservariables
for i,v in pairs(uservariables) do
if i== "LW-Setting" then
Vars=split(v, "|")
end
end
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
IPaddress = Vars[1]
if Vars[3] == "Reg" then
On = " "
Off = " "
Vars[3] = "F*p"
print("Register Device triggered")
end
if Vars[3] == "UReg" then
On = " "
Off = " "
print("Un-register device triggered")
Vars[3] = "F*xP"
end
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
id = tostring(otherdevices_idx[DomDevice])
for i=2,#Vars,2 do
if (Vars[i] == id) then
if(DeviceValue == 'Off' ) then
LWCmd =(LWCmd .. Vars[i+1] .. Off)
UDPSend(IPaddress,LWCmd)
print("Off " .. DomDevice)
elseif(DeviceValue == 'On') then
LWCmd =(LWCmd .. Vars[i+1] .. On)
UDPSend(IPaddress,LWCmd)
print("On " .. DomDevice)
else
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd =(LWCmd .. Vars[i+1] .. Dim .. DomValue)
UDPSend(IPaddress,LWCmd)
print("Dim " .. DomValue .. " " .. DomDevice)
end
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Integration
Posted: Sunday 12 March 2017 10:10
by lonebaggie
Updated 1.2 . See Script
Code: Select all
-- This program control LightWaveRF switches, dimmers and sockets via the LIghtWaveRF link
-- The program requires lua sockets to be installed
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off and dimmer virtual switches are supported.
-- No configuration of the virtual switch is required.
--
-- The program relies on a user string variable to be created in Domoticz interface with the name WL-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|RnDn|IDx|RnDn
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- RnDn is R=room n=Number D=Device n=Number (example R1D2)
--
-- Room numbers and device numbers are determined by the LIghtWaveRF app
-- Room 1 is the first room displayed in the app. Devices follow the same pattern
-- Repeat sequence for the number of switches, and dimmers required.
--
-- Example configuration 192.168.1.20|67|R1D1|68|R1D2|69|R2D1
--
-- LightwaveRF LInk has a built in security measure and will not allow any device to control lights and switches
-- without beging registed to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LIghtWAveRF link this script will not work until registered !
-- To register you will need to setup a temporary switch to be used just once as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string varable in LW-Settings
--
-- ipaddress|IDx|Reg
--
-- Once the virtual switch has been switched on or Off, the LIghtWAveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domiticz Server.
-- Once registeed remove the Reg setting from LW-Setting and replace with RnDn settings.
--
-- To de-register the Domiticz Server run the above procedure but subsitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.2
-- Added error checking on LW-Setting
-- Exit script when switch found and actioned. stop loop quicker
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
LWCmd = "001,!"
On="F1"
Off="F0"
Dim="FdP"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
function UDPSend(ip, message)
local port = 9760
local socket = require "socket"
sock, msg = socket.udp()
if sock then
sock:setpeername(ip, port)
sock:send(message)
sock: close()
end
return
end
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all Vars from uservariables
for i,v in pairs(uservariables) do
if i== "LW-Setting" then
Vars=split(v, "|")
end
end
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
if #Vars < 3 then
print ("LW-Setting invalid EXit script")
return commandArray
end
IPaddress = Vars[1]
if Vars[3] == "Reg" then
On = " "
Off = " "
Vars[3] = "F*p"
print("Register Device triggered")
end
if Vars[3] == "UReg" then
On = " "
Off = " "
print("Un-register device triggered")
Vars[3] = "F*xP"
end
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
id = tostring(otherdevices_idx[DomDevice])
for i=2,#Vars,2 do
if (Vars[i] == id) then
if(DeviceValue == 'Off' ) then
LWCmd =(LWCmd .. Vars[i+1] .. Off)
UDPSend(IPaddress,LWCmd)
print("Off " .. DomDevice)
elseif(DeviceValue == 'On') then
LWCmd =(LWCmd .. Vars[i+1] .. On)
UDPSend(IPaddress,LWCmd)
print("On " .. DomDevice)
else
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd =(LWCmd .. Vars[i+1] .. Dim .. DomValue)
UDPSend(IPaddress,LWCmd)
print("Dim " .. DomValue .. " " .. DomDevice)
end
return commandArray
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Integration
Posted: Wednesday 12 April 2017 23:24
by lonebaggie
Updated to 1.4 to remove the requirement on Sockets. Will now run unmodified on Linux environment, uses Netcat to send UDP to wifi Link. Will require modification to run in windows environment see
https://github.com/diegocr/netcat
Code: Select all
-- This program control LightWaveRF switches, dimmers and sockets via the LIghtWaveRF link
--
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off and dimmer virtual switches are supported.
-- No configuration of the virtual switch is required.
--
-- The program relies on a user string variable to be created in Domoticz interface with the name WL-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|RnDn|IDx|RnDn
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- RnDn is R=room n=Number D=Device n=Number (example R1D2)
--
-- Room numbers and device numbers are determined by the LIghtWaveRF app
-- Room 1 is the first room displayed in the app. Devices follow the same pattern
-- Repeat sequence for the number of switches, and dimmers required.
--
-- Example configuration 192.168.1.20|67|R1D1|68|R1D2|69|R2D1
--
-- LightwaveRF LInk has a built in security measure and will not allow any device to control lights and switches
-- without beging registed to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LIghtWAveRF link this script will not work until registered !
-- To register you will need to setup a temporary switch to be used just once as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string varable in LW-Settings
--
-- ipaddress|IDx|Reg
--
-- Once the virtual switch has been switched on or Off, the LIghtWAveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domiticz Server.
-- Once registeed remove the Reg setting from LW-Setting and replace with RnDn settings.
--
-- To de-register the Domiticz Server run the above procedure but subsitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.2
-- Added error checking on LW-Setting
-- Exit script when switch found and actioned. stop loop quicker
-- Version 1.3
-- Simplified picking up user Variables
-- Version 1.4
-- Removed the use of Lua sockets. Now uses netcat. syntax will need to changed to work on Windows machines
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
LWCmd = "001,\\!"
On="F1"
Off="F0"
Dim="FdP"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
-- UDPSend changed to use netcat please change format in udpcall to work on windows machines
function UDPSend(ip, message)
local port = 9760
udpcall = "echo -n " .. message .. "| nc -4u -w1 " .. ip .. " " .. port .. " &"
os.execute(udpcall)
return
end
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all lightwave config from uservariables
Vars=split(uservariables["LW-Setting"], "|")
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
if #Vars < 3 then
print ("LW-Setting invalid EXit script")
return commandArray
end
IPaddress = Vars[1]
if Vars[3] == "Reg" then
On = " "
Off = " "
Vars[3] = "F*p"
print("Register Device triggered")
end
if Vars[3] == "UReg" then
On = " "
Off = " "
print("Un-register device triggered")
Vars[3] = "F*xP"
end
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
id = tostring(otherdevices_idx[DomDevice])
for i=2,#Vars,2 do
if (Vars[i] == id) then
if(DeviceValue == 'Off' ) then
LWCmd =(LWCmd .. Vars[i+1] .. Off)
UDPSend(IPaddress,LWCmd)
print("Off " .. DomDevice)
elseif(DeviceValue == 'On') then
LWCmd =(LWCmd .. Vars[i+1] .. On)
UDPSend(IPaddress,LWCmd)
print("On " .. DomDevice)
else
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd =(LWCmd .. Vars[i+1] .. Dim .. DomValue)
UDPSend(IPaddress,LWCmd)
print("Dim " .. DomValue .. " " .. DomDevice)
end
return commandArray
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Hub Integration
Posted: Thursday 15 June 2017 21:57
by lonebaggie
Updated again
1.5. Now supports Moods and All Off Room functions of the LightwaveRF Link.
Moods require a Virtual Selector switch created in the same order as the Moods in the LighrwaveRF App. Recommend Selector switch names match Mood names.
Use a Push on Button virtual switch to control the all off feature.
Have updated documentation in program.
Code: Select all
-- This program control LightWaveRF switches,dimmers,sockets and Moods via the LIghtWaveRF link
--
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off,dimmer and Selector virtual switches are supported.
-- No configuration of the virtual switch is required.
--
-- The program relies on a user string variable to be created in Domoticz interface with the name WL-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|RnDn|IDx|RnDn
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- RnDn is R=room n=Number D=Device n=Number (example R1D2)
-- RnO is R=room n=Number O= Turns all Devices in room off
-- RnM is R=room n=Number M=Mood selected by Selector switch (1 to 5)
--
-- For Moods the Selector Switch must match the Mood sequence from LightwaveRF App
-- So Mood 1 is level 10 in the Selector Switch Mood 2 is level 20 , etc .
-- The Selector must have Off disabled.
--
-- Suggest using a pUsh on button virtual switch for All Off (RnO) option.
--
-- Room numbers and device numbers are determined by the LIghtWaveRF app
-- Room 1 is the first room displayed in the app. Devices follow the same pattern
-- Repeat sequence for the number of switches,dimmers and Moods required.
--
-- Example configuration 192.168.1.20|67|R1D1|68|R1D2|69|R2D1|34|R2M|54|R1O
-- This program will make no attempt to sync switch settings. So if you issue an all off command (RnO)
-- this will not switch off any individual Domoticz switches in the room. If this is required use the
-- Sub/Slave Devices option in the All off Virtual switch to turn off all Domoticz switches in the room
-- **************************************************
-- * P L E A S E R E A D T H E F O L L O W I N G *
-- **************************************************
--
-- LightwaveRF LInk has a built in security measure and will not allow any client devices to control lights and switches
-- without being registed to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LightWaveRF link this program will not work until registered !
-- To register you will need to create a single virtual switch as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string varable in LW-Settings.
-- Do not use this setting in conjuction with other settings documented above.
--
-- ipaddress|IDx|Reg
--
-- Once the virtual switch has been switched on or Off, the LightWaveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domiticz Server.
-- Once registeed remove the Reg setting from LW-Setting.
--
-- To de-register the Domiticz Server run the above procedure but subsitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.2
-- Added error checking on LW-Setting
-- Exit script when switch found and actioned. stop loop quicker
-- Version 1.3
-- Simplified picking up user Variables
-- Version 1.4
-- Removed the use of Lua sockets. Now uses netcat. syntax will need to changed to work on Windows machines
-- Version 1.5
-- Added Lightwave Moods and all off for rooms. Updated instructions
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
LWCmd = "001,\\!"
On="F1"
Off="F0"
Dim="FdP"
Aoff="Fa"
Mood="FmP"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
-- UDPSend changed to use netcat please change format in udpcall to work on windows machines
function UDPSend(ip, message)
local port = 9760
udpcall = "echo -n " .. message .. "| nc -4u -w1 " .. ip .. " " .. port .. " &"
os.execute(udpcall)
return
end
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all lightwave config from uservariables
Vars=split(uservariables["LW-Setting"], "|")
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
if #Vars < 3 then
print ("LW-Setting invalid EXit script")
return commandArray
end
IPaddress = Vars[1]
if Vars[3] == "Reg" then
On = " "
Off = " "
Vars[3] = "F*p"
print("Register Device triggered")
end
if Vars[3] == "UReg" then
On = " "
Off = " "
print("Un-register device triggered")
Vars[3] = "F*xP"
end
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
id = tostring(otherdevices_idx[DomDevice])
for i=2,#Vars,2 do
if (Vars[i] == id) then
if(DeviceValue == 'Off' and string.sub(Vars[i+1],3)~="O") then
LWCmd =(LWCmd .. Vars[i+1] .. Off)
UDPSend(IPaddress,LWCmd)
print("Off " .. DomDevice)
elseif(DeviceValue == 'On' and string.sub(Vars[i+1],3)~="O") then
LWCmd =(LWCmd .. Vars[i+1] .. On)
UDPSend(IPaddress,LWCmd)
print("On " .. DomDevice)
elseif (string.sub(Vars[i+1],3) =="O" ) then
LWCmd =(LWCmd .. string.sub(Vars[i+1],1.2) .. Aoff)
UDPSend(IPaddress,LWCmd)
print("All Off " .. DomDevice)
elseif (string.sub(Vars[i+1],3)=="M") then
DomValue = otherdevices_svalues[DomDevice]
DomValue = DomValue /10
LWCmd =(LWCmd .. string.sub(Vars[i+1],1.2) .. Mood .. DomValue )
UDPSend(IPaddress,LWCmd)
print (LWCmd)
print("Mood " .. DomDevice .. " " .. DeviceValue)
elseif (string.gmatch(DeviceValue,"%") and string.sub(Vars[i+1],3)~="M") then
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd =(LWCmd .. Vars[i+1] .. Dim .. DomValue)
UDPSend(IPaddress,LWCmd)
print("Dim " .. DomValue .. " " .. DomDevice)
end
return commandArray
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Hub Integration
Posted: Sunday 18 June 2017 16:17
by lonebaggie
Major update 2.0
now supports all options in lightwareRF power and lighting api
https://api.lightwaverf.com/lighting_power.html
To support new features LW-Setting needs to be amended from 192.168.1.1|67|R1D1 to 192.168.1.1|67|R1|D1
See script header for full details
Code: Select all
-- This program control LightWaveRF switches,dimmers,sockets and Moods via the LIghtWaveRF link
--
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off,dimmer and Selector virtual switches are supported.
--
--
-- The program relies on a user string variable to be created in Domoticz interface with the name WL-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|Rn|Commands|Idx|Rn|Commands etc
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- Rn is R=room n=Number
--
-- Commands
--
-- Dn is D=Device to be off/on or dimmed
-- Ln is L=Device to be unlocked/locked.
-- Cn is C=Device to be closed/opened/stopped
-- O is O=Turns all Devices in room off
-- M is M=Mood selected by Selector switch (1 to 5)
--
-- For Moods a Selector Switch must be used and must match the Mood sequence from LightwaveRF App
-- So Mood 1 is level 10 in the Selector Switch Mood 2 is level 20 , etc .
-- The Selector must have Off disabled.
--
-- For Closed/open/stopped make sure switch is set to a venetian blinds
--
-- Suggest using a push on button virtual switch for All Off option.
--
-- Room numbers (R) and D,L and C numbers are determined by the LightWaveRF app
-- Room 1 is the first room displayed in the app. Devices (D,L and C) follow the same pattern
-- Repeat sequence for the number of domoticz switches required.
--
-- Example configuration 192.168.1.20|67|R1|D1|68|R1|C2|69|R2|L1|34|R2|M|54|R1|O
-- See https://api.lightwaverf.com/ for full details of API
-- This program will make no attempt to sync switch settings. So if you issue an all off command
-- this will not switch off any individual Domoticz switches in the room. If this is required use the
-- Sub/Slave Devices option in the All off Virtual switch to turn off all Domoticz switches in the room
-- **************************************************
-- * P L E A S E R E A D T H E F O L L O W I N G *
-- **************************************************
--
-- LightwaveRF LInk has a built in security measure and will not allow any client devices to control lights and switches
-- without being registed to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LightWaveRF link this program will not work until registered !
-- To register you will need to create a single virtual switch as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string varable in LW-Settings.
-- Do not use this setting in conjuction with other settings documented above. Note the use of two ||
--
-- ipaddress|IDx||Reg
--
-- Once the virtual switch has been switched on or Off, the LightWaveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domiticz Server.
-- Once registeed remove the Reg setting from LW-Setting.
--
-- To de-register the Domiticz Server run the above procedure but subsitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.2
-- Added error checking on LW-Setting
-- Exit script when switch found and actioned. stop loop quicker
-- Version 1.3
-- Simplified picking up user Variables
-- Version 1.4
-- Removed the use of Lua sockets. Now uses netcat. syntax will need to changed to work on Windows machines
-- Version 1.5
-- Added Lightwave Moods and all off for rooms. Updated instructions
-- Version 2.0
--
-- Added all options from LightWaveRF api for power and lighting . see https://api.lightwaverf.com/
-- Simplified logic. Added additinal variables by spliting R1D1 into R1|D1. Allows simple parsing on LW_setting
-- LW-Setting needs to be modified from previous versions or program wull not run correctly !!
--
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
-- LightwareRF Commands
LWCmd = "001,\\!"
On="F1"
Off="F0"
Dim="FdP"
Aoff="Fa"
Mood="FmP"
Reg= "F*p"
UReg="F*xP"
Lock="Fl"
Ulock="Fu"
Close="F)"
Open="F("
Stop="F^"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
-- UDPSend changed to use netcat please change format in udpcall to work on windows machines
function UDPSend(ip, message)
local port = 9760
udpcall = "echo -n " .. message .. "| nc -4u -w1 " .. ip .. " " .. port .. " &"
os.execute(udpcall)
return
end
-- Math rounding
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all lightwave config from uservariables
Vars=split(uservariables["LW-Setting"], "|")
-- ensue LW-Settings conatin info
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
if #Vars < 3 then
print ("LW-Setting invalid EXit script")
return commandArray
end
-- set ip address of LightwaveRF link
IPaddress = Vars[1]
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
-- get IDx number of device
id = tostring(otherdevices_idx[DomDevice])
--loop through all variables parsed from LW-Setting
for i=2,#Vars,3 do
-- if device found action command
if (Vars[i] == id) then
-- set Lrf to 1st char of command
Lrf = string.sub(Vars[i+2],1,1)
-- find command set in variable and load LighwaveRF command into LWCmd
if Lrf =="R" then
LWCmd = LWCmd .. Reg
print ("Device Registered")
end
if Lrf == "U" then
LWCmd = LWCmd .. UReg
print ("Device Un-Registered")
end
if Lrf == "M" then
DomValue = otherdevices_svalues[DomDevice]
DomValue = DomValue /10
LWCmd = LWCmd .. Vars[i+1] .. Mood .. DomValue
print ("Mood " .. DomValue .. " on " .. DomDevice)
end
if Lrf == "O" then
LWCmd = LWCmd .. Vars[i+1] .. Aoff
print ("All devices in " .. Vars[i+1] .. " off")
end
if Lrf == "D" then
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Off
print ("Device " .. DomDevice .. " off")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. On
print ("Device " .. DomDevice .. " on")
else
-- convert 0 -100% Dim Values to Lightwaverf 1 - 32 dim values
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Dim .. DomValue
print ("Device " .. DomDevice .. " dim " .. DeviceValue)
end
end
if Lrf == "C" then
Vars[i+2] = "D" .. string.sub(Vars[i+2],2)
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Open
print ("Device " .. DomDevice .. " opened")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Close
print ("Device " .. DomDevice .. " closed")
else
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Stop
print ("Device " .. DomDevice .. " stopped")
end
end
if Lrf == "L" then
Vars[i+2] = "D" .. string.sub(Vars[i+2],2)
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Ulock
print ("Device " .. DomDevice .. " unlocked")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Lock
print ("Device " .. DomDevice .. " locked")
end
end
--send complete command to LightwaveRF Link
UDPSend(IPaddress,LWCmd)
print ( "Command sent to " .. IPaddress .. " is " .. LWCmd)
return commandArray
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Hub Integration
Posted: Saturday 12 August 2017 18:03
by lonebaggie
Updated to 2.1
Have synchronized Domoticz to match Lightwaverf all Off command in a room, This will ensure all switches in that room are marked off when all off command triggered by lightwaverf.
Also added a random command sequence to ensure commands are registered correctly by the lightwaverf hub.
All documentation in script
Code: Select all
-- This program control LightWaveRF switches,dimmers,sockets and Moods via the LIghtWaveRF link
--
--
-- This program requires dummy hardware and virtual switches to be created.
-- On/off,dimmer and Selector virtual switches are supported.
-- No configuration of the virtual switch is required.
--
-- The program relies on a user string variable to be created in Domoticz interface with the name WL-Setting
-- Use the following syntax for the string value
--
-- ipaddress|IDx|Rn|Commands|Idx|Rn|Commands etc
--
-- Where ipaddress is IP of Wifi link
-- IDx is the IDx number of virtual switch (obtain the IDx value from the Device list)
-- Rn is R=room n=Number
--
-- Commands
--
-- Dn is D=Device to be off/on or dimmed
-- Ln is L=Device to be unlocked/locked.
-- Cn is C=Device to be closed/opened/stopped
-- O is O=Turns all Devices in room off
-- M is M=Mood selected by Selector switch (1 to 5)
--
-- For Moods a Selector Switch must be used and must match the Mood sequence from LightwaveRF App
-- So Mood 1 is level 10 in the Selector Switch Mood 2 is level 20 , etc .
-- The Selector must have Off disabled.
--
-- For Closed/open/stopped make sure switch is set to a venetian blinds
--
-- Suggest using a push on button virtual switch for All Off option.
--
-- Room numbers (R) and D,L and C numbers are determined by the LightWaveRF app
-- Room 1 is the first room displayed in the app. Devices (D,L and C) follow the same pattern
-- Repeat sequence for the number of domoticz switches required.
--
-- Example configuration 192.168.1.20|67|R1|D1|68|R1|C2|69|R2|L1|34|R2|M|54|R1|O
-- See https://api.lightwaverf.com/ for full details of API
-- This program will sync switch settings when All off is issued . So if you issue an all off command
-- all switches in the room will be turned off
--
-- **************************************************
-- * P L E A S E R E A D T H E F O L L O W I N G *
-- **************************************************
--
-- LightwaveRF LInk has a built in security measure and will not allow any client devices to control lights and switches
-- without being registed to the LIghtWaveRF Link first.
--
-- If the Domoticz Server has not been registered to the LightWaveRF link this program will not work until registered !
-- To register you will need to create a single virtual switch as a mechanism to register the Domoticz Server.
-- Once the virtual switch (a simple on/off) has been created. Use the following string varable in LW-Settings.
-- Do not use this setting in conjuction with other settings documented above.
--
-- ipaddress|IDx||Reg
--
-- Once the virtual switch has been switched on or Off, the LightWaveRF Link should start flashing.
-- Press the physical button on the Link box, This will register the Domiticz Server.
-- Once registeed remove the Reg setting from LW-Setting.
--
-- To de-register the Domiticz Server run the above procedure but subsitute Reg for UReg.
-- Once de-registered no further commands will work until the Server is re-registered.
-- Version 1.2
-- Added error checking on LW-Setting
-- Exit script when switch found and actioned. stop loop quicker
-- Version 1.3
-- Simplified picking up user Variables
-- Version 1.4
-- Removed the use of Lua sockets. Now uses netcat. syntax will need to changed to work on Windows machines
-- Version 1.5
-- Added Lightwave Moods and all off for rooms. Updated instructions
-- Version 2.0
--
-- Added all options from LightWaveRF api for power and lighting . see https://api.lightwaverf.com/
-- Simplified logic. Added additinal variables by spliting R1D1 into R1|D1. Allows simple parsing on LW_setting
-- LW-Setting needs to be modified from previous versions or program wull not run correctly !!
--
-- Version 2.1
--
-- All Off now turn off Domoticz switches in the room without the need for slave switches.
-- Added random number to LightwareRf command sequence to ensure command is run if script run in Group
--
-- Setup Variables
commandArray = {}
Vars = {}
Vars[1] = "Error"
-- LightwareRF Commands
Rand=math.random(998)+1
LWCmd = Rand .. ",\\!"
On="F1"
Off="F0"
Dim="FdP"
Aoff="Fa"
Mood="FmP"
Reg= "F*p"
UReg="F*xP"
Lock="Fl"
Ulock="Fu"
Close="F)"
Open="F("
Stop="F^"
id =0
-- functions
function split(pString, pPattern)
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
-- UDPSend changed to use netcat please change format in udpcall to work on windows machines
function UDPSend(ip, message)
local port = 9760
udpcall = "echo -n " .. message .. "| nc -4u -w1 " .. ip .. " " .. port .. " &"
os.execute(udpcall)
return
end
-- Math rounding
function round(n)
return math.floor((math.floor(n*2) + 1)/2)
end
-- Obtain all lightwave config from uservariables
Vars=split(uservariables["LW-Setting"], "|")
-- ensue LW-Settings conatin info
if Vars[1]== "Error" then
print ("No LW-Setting Exit script")
return commandArray
end
if #Vars < 3 then
print ("LW-Setting invalid EXit script")
return commandArray
end
-- set ip address of LightwaveRF link
IPaddress = Vars[1]
print ("LightWaveRF started")
-- loop through all the devices
for DomDevice,DeviceValue in pairs(devicechanged) do
-- get IDx number of device
id = tostring(otherdevices_idx[DomDevice])
--loop through all variables parsed from LW-Setting
for i=2,#Vars,3 do
-- if device found action command
if (Vars[i] == id) then
-- set Lrf to 1st char of command
Lrf = string.sub(Vars[i+2],1,1)
-- find command set in variable and load LighwaveRF command into LWCmd
if Lrf =="R" then
LWCmd = LWCmd .. Reg
print ("Device Registered")
end
if Lrf == "U" then
LWCmd = LWCmd .. UReg
print ("Device Un-Registered")
end
if Lrf == "M" then
DomValue = otherdevices_svalues[DomDevice]
DomValue = DomValue /10
LWCmd = LWCmd .. Vars[i+1] .. Mood .. DomValue
print ("Mood " .. DomValue .. " on " .. DomDevice)
end
if Lrf == "O" then
LWCmd = LWCmd .. Vars[i+1] .. Aoff
for r=3,#Vars,3 do
if Vars[i+1] == Vars[r] then
DomDevice = Vars[r-1] .. "|0|off"
commandArray[r-2]={["UpdateDevice"] = DomDevice}
end
end
print ("All devices in " .. Vars[i+1] .. " off")
end
if Lrf == "D" then
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Off
print ("Device " .. DomDevice .. " off")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. On
print ("Device " .. DomDevice .. " on")
else
-- convert 0 -100% Dim Values to Lightwaverf 1 - 32 dim values
DomValue = otherdevices_svalues[DomDevice]
DomValue = (DomValue/3.14) +0.5
DomValue = round(DomValue)
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Dim .. DomValue
print ("Device " .. DomDevice .. " dim " .. DeviceValue)
end
end
if Lrf == "C" then
Vars[i+2] = "D" .. string.sub(Vars[i+2],2)
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Open
print ("Device " .. DomDevice .. " opened")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Close
print ("Device " .. DomDevice .. " closed")
else
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Stop
print ("Device " .. DomDevice .. " stopped")
end
end
if Lrf == "L" then
Vars[i+2] = "D" .. string.sub(Vars[i+2],2)
if DeviceValue == "Off" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Ulock
print ("Device " .. DomDevice .. " unlocked")
elseif DeviceValue == "On" then
LWCmd = LWCmd .. Vars[i+1] .. Vars[i+2] .. Lock
print ("Device " .. DomDevice .. " locked")
end
end
--send complete command to LightwaveRF Link
UDPSend(IPaddress,LWCmd)
print ( "Command sent to " .. IPaddress .. " is " .. LWCmd)
return commandArray
end
end
end
return commandArray
Re: LightWaveRF Switch and Link Hub Integration
Posted: Friday 20 October 2017 20:43
by dgilbert2
Wow, you have clearly put so much effort into these LightwaveRF scripts!
I have a number of LightwaveRF TRVs, do you know how I can read their temperatures into Domoticz, their API has blown my mind
thanks
Re: LightWaveRF Switch and Link Hub Integration
Posted: Saturday 21 October 2017 14:16
by lonebaggie
Sorry don't have any these. They are two way devices.
I am slowly replacing my lightwaverf kit for
https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara) so I will not be investing in anymore lightwaverf kit. The version 2 lightwaverf kit is stupidly expensive, so this is the last script. Have a look at RFLink this may support the options
Re: LightWaveRF Switch and Link Hub Integration
Posted: Saturday 21 October 2017 17:47
by dgilbert2
Thanks for the feedback, I will take a look at RFlink. In the meantime I have now got your script working as above, version 2.1, so that's a start
Yes, LightwaveRF version 2 is so expensive and does not seem to care about existing customers
Good luck with your new kit.
Re: LightWaveRF Switch and Link Hub Integration
Posted: Sunday 22 October 2017 11:14
by lonebaggie
Good to know . I also use HA-Bridge. This will let you control LIghtwaverf From Amazon Alexa without having to the LIghtwaverf Skill. The advantage is sub second response. Will run on the same PI as Domoticz. I also have config from HA-bridge to control lightwaverf directly. PM me if interested
Re: LightWaveRF Switch and Link Hub Integration
Posted: Sunday 22 October 2017 22:01
by dgilbert2
Thanks, PM sent.
Re: LightWaveRF Switch and Link Hub Integration
Posted: Sunday 31 December 2017 0:04
by pjsgsy
Has anyone got this working on Windows? I think I'm having trouble with the udpcall. I've got windows netcat installed and did in fact register the server manually via the command line with it, sending the command echo ,\\!F*p | nc -v -u -w1 192.168.2.10 9760
That worked fine. The link saw it. Doesn;t see the commands when I click the switches though. I do see the event being triggered. I do not think the command is running. I have nc in the domoticz folder and windows system32, so it's in the default path, too.
Any ideas?
Re: LightWaveRF Switch and Link Hub Integration
Posted: Sunday 31 December 2017 12:12
by pjsgsy
As an update, I did get this working in windows. I had a duff LW-String. It appears that the order of the rooms are not any longer sequential in the app, so a little experimentation is required. I also had to change the os call. Working format below for anyone attempting to get this working with windows (had to install the windows nc as well, of course)
udpcall = "echo " .. message .. " | nc -u -w1 " .. ip .. " " .. port
Re: LightWaveRF Switch and Link Hub Integration
Posted: Monday 01 January 2018 22:54
by lonebaggie
Good to hear it works in Windows . Didn't realise the app changes the order of rooms , is the web app the same ? I am slowly replacing my lightwaverf switches to xiaomi so I only have one lightwaverf switch so I am down to one room

Re: LightWaveRF Switch and Link Hub Integration
Posted: Wednesday 03 January 2018 12:18
by pjsgsy
I've stopped buying the LRF kit too, but I have quite a few switches. V2, with the 'apple' stamp, no interest to me given the huge price premium. Can't afford to replace it all though. I have a bunch of the xiaomi stuff on the way though, having discovered it via this board.
It does appear the latest version of the app do not give you any easy way to see the room id. For instance, I just added room number 9. It appears at the top of my list. Deleting rooms and adding further confuses numbers. I took a look at the web app too. It does not seem to offer any clues. It's been revamped to and is now java based, so no URL's to look at with id's etc. The only ID mentioned seems to be high numbers on rooms like 1511, so no way to easily determine ID's any more. I resort to simply trying all room numbers from 1 up, with device 1, until I see something turn on
Still, very useful piece of code that saved me a lot of time, so thanks for sharing. I'd already got light switches working with php via my own site, but have given in to using something ready built! (domoticz)
Re: LightWaveRF Switch and Link Hub Integration
Posted: Monday 08 February 2021 21:15
by z4mz00
I am using the excellent script created by lonebaggie to control my LightwaveRF dimmers via a LightwaveRF Link box.
I have hit a string length issue with the variable LW-Setting used to feed command parameters into the script.
I have 40 LightwaveRF dimmers but I am allowed only about 195 characters in a Domoticz user variable string and as each command is about 9 characters long, I can only get about 21 dimmer commands to fit within the string variable length limit.
I have looked at lonebaggies's script but am not confident of my shell scripting skills and would like advice as how I should approach the issue of creating a longer string or sequence of strings that can be concatenated to create space for a larger number of dimmer commands, say 511 characters for about 55 commands. I suspect an array of LW-Settings strings with a "for loop" that scans them in turn could work, but I lack the experience to hack this myself.
Can anyone dig me out of this hole please?
Re: LightWaveRF Switch and Link Hub Integration
Posted: Wednesday 10 February 2021 1:10
by z4mz00
As a workaround in the absence of any suggestions, I have implemented the following tactics:
The dummy hardware item, event script and user variable can be replicated by adding for example hardware LightwaveRF-2, adding user variable LW-Setting-2, creating event script LightwaveRF-2, and changing the string referenced in the replicated script as follows:
-- Obtain all LightwaveRF command strings from the User Variable LW-Setting
Vars=split(uservariables["LW-Setting"], "|") <== original
-- Obtain all LightwaveRF-2 command strings from the User Variable LW-Setting-2
Vars=split(uservariables["LW-Setting-2"], "|") <== modified
In fact, all references to LW-Setting in the copied script can be changed to LW-Setting-2.
But nobody seems very interested in LightwaveRF any more. Shame.
Re: LightWaveRF Switch and Link Hub Integration
Posted: Wednesday 10 February 2021 7:40
by pjsgsy
Thanks for the share. I still have some of the original kit. They just went the 'Apple' route and tripled or more the price of all their products. Shame. It was great affordable kit. Simple, but worked.