The script triggers via the devices table inside on.
How can I reference the list/table of devices in the on section?
This is my code so far, but it tells me
bad argument #1 to 'pairs' (table expected, got nil)
Code: Select all
return {
on = {
devices = {
773,
786,
747,
871
},
timer = {
'every minute'
},
},
logging = {
level = domoticz.LOGINFO,
marker = 'Tryck',
},
execute = function(domoticz, device)
local height = 124
local pressure = 0
-- Calculate mean pressure and correct for height
for _, p in pairs(devices) do
pressure = pressure + domoticz.devices(p).barometer / #devices
domoticz.log('Average pressure: ' .. pressure, domoticz.LOGINFO)
end
-- Update virtual barometer
-- domoticz.devices('Lufttryck').updateBarometer(pressure)
end
}
}
Is there a way to reference devices = { 773, 786, 747, 871} as a table to calculate the average similar to what I try in my code?