I made a script in DZVENT.
It works as follows:
Triggering on a detection
Extraction of the list of sensors and the lastupdate values in seconds
Memorization in a table
In orders the array in ascending order on the lastupdate value
Code: Select all
return
{
on =
{
devices = { -- detection
'myDetector1',
'myDetector2'
}
},
execute = function(domoticz, detec)
local message=""
local capteurs = {}
--FILTER ON DEVICE SWITCH TYPE
local Detec_Devices = domoticz.devices().filter(function(device)
return (device.switchType == 'Door Contact' or device.switchType == 'Motion Sensor')
end)
--EXTRACT DEVICES AND LASTUPDATE IN SEC
Detec_Devices.forEach(function(deadDevice) -- Derniere detection device
local level=""
level = tostring(deadDevice.lastUpdate.secondsAgo.." sec") -- affiche en sec
local devname = tostring(deadDevice.name) -- nom device
message = message ..'- '..devname..' : '..level..'<br>'
-- FILL TABLE
table.insert(capteurs , num1 = level, val2 = devname)
end)
-- READ TABLE
-- ORDER ASCENDING ON num1
table.sort(capteurs, function(a,b) return a.num1 < b.num1 end)
for i, capteurs in ipairs(widgets) do
print("SENSORS : "..widget.num1);
end
end
}
I have an error on the storage in the table.
This ligne :
table.insert(capteurs , num1 = level, val2 = devname)
my_script_6.lua:31: ')' expected near '='
I will need help if possible.
Thank you