I need this functionality for my alarm system. When an alarm goes off, all kinds of devices switches on, in addition to the fact that there may already be a number turned on. I want to go back to the pre-alarm situation ..
I tried it, but this script is to difficult for me ... especially writing a key with more than one values
[{"devicename":"xxx", "state":"on","type":"on/off"},{...}]
My testscript has to save the state off test2 and lantaarn when device testxx = on and when it is off it has to recover the two devices
a device can be a switch or a selectorswitch...
Code: Select all
return {
on = { devices = { 'testxx' }},
data = {
ondev = { history = true,initial = {}},
},
logging = {level = domoticz.LOG_DEBUG},
execute = function(dz,item,info)
_G.logMarker = _G.moduleLabel -- marker wordt scriptnaam
local checklights = {'test2','lantaarn'}
local lights = dz.devices().filter(checklights)
if item.state == 'On' then -- backup
dz.data.ondev.reset()
lights.forEach(function(device)
if (device.state ~= 'Off' and device.state ~= 'uit' and device.name ~= 'testxx' and device.description == 'backup') then
dz.data.ondev.add(device) -- i need only the device name, state and if the device is a selector do not need the other properties
end
end)
else -- restore
for i = dz.data.ondev.size,1,-1 do
itemx = dz.data.ondev.get(i)
dz.log("data: " .. itemx.data) -- need th device name, state and if the device is a selector and then diferent on/off's for switch or selector
dz.devices(itemx.data).switchOn().checkFirst()
end
end
end
}