E.g.:
Code: Select all
local up = "Up"
local down = "Down"
return {
on = {
customEvents = {
'BedieningRolluiken'
}
},
logging =
{
level = domoticz.LOG_ERROR,
marker = "Bediening rolluiken"
},
execute = function(dz, item)
local function rolluikOpen(rolluik)
if rolluik ~= nil then
dz.log('Rolluik omhoog: ' .. rolluik.name, dz.LOG_DEBUG)
rolluik.switchOff()
end
end
local function rolluikDicht(rolluik)
if rolluik ~= nil then
dz.log('Rolluik omlaag: ' .. rolluik.name, dz.LOG_DEBUG)
rolluik.switchOn()
end
end
local json = dz.utils.fromJSON(item.data)
local command = json[1]
if command ~= up and command ~= down then
return
end
local devices = json[2]
local rolluiken = dz.devices().filter(devices)
dz.log('#rolluiken: ' .. tostring(#rolluiken), dz.LOG_DEBUG)
if command == up then
dz.log('Command was "Up"', dz.LOG_DEBUG)
rolluiken.forEach(function(rolluik)
rolluikOpen(rolluik)
end)
elseif command == down then
dz.log('Command was "Down"', dz.LOG_DEBUG)
rolluiken.forEach(function(rolluik)
rolluikDicht(rolluik)
end)
end
end
}
Code: Select all
local args = {
"Down",
idsRolluiken
}
dz.emitEvent('BedieningRolluiken', args)
E.g.:
Code: Select all
local json = dz.utils.fromJSON(item.data)
Or:
Code: Select all
local rolluiken = dz.devices().filter(devices)
How do I prevent these runtime errors? (pcall can't be used here)