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