This script has a lot of groups and timers. Lot of the groups are the same, only difference is to put the devices On or Off...
So i tried to write my first function in a script to reuse some of the code.
What i cant script is how to make a variable on/off command
dz.devices('lantaarn1').<on/off variable> same for a parameter for/aftermin
When this works i can delete the half of my groups...
Code: Select all
return {
on = { devices = { 'test' }},
execute = function(dz, item, info)
local logcode = 3 -- log alles, 0 = niets, 1 dom, 2 global, 3 alles... evt per regel ook in te regelen
local messageTable = {}
local add = 'add'
local del = 'del'
local chg = 'chg'
local function globalMessage(action, message, logcode)
if logcode == nil then logcode = 3 end
if action == add and logcode > 0 then
messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
elseif action == del then
dz.globalData.mylogging = message
dz.devices('timerlog').updateText(message)
elseif action == chg then
dz.helpers.dumpMessages(dz, messageTable)
end
end
local function groep1(action,timer)
dz.devices('lantaarn1') .. '.switch' .. action .. '()' -- also paste afterxxxx
dz.devices('lantaarn2') .. '.switch' .. action .. '()' -- also paste afterxxxx
dz.devices('lantaarn3') .. '.switch' .. action .. '()' -- also paste afterxxxx
dz.devices('lantaarn4') .. '.switch' .. action .. '()' -- also paste afterxxxx
dz.devices('lantaarn5') .. '.switch' .. action .. '()' -- also paste afterxxxx
globalMessage(add, ' Groep1 is ' .. action,3)
end
groep1(item.state) -- also .afterMin(30) as a parameter has to be optional
globalMessage(chg) -- dump
end
}