A special kind of persistent variables: history = true[edit]
In some situation, storing a previous value for a sensor is not enough and you would like to have more previous values for example when you want to calculate an average over several readings or see if there was a constant rise or decrease. Of course you can define a persistent variable holding a table:
return {
active = true,
on = {
devices = {'MyTempSensor'}
},
data = {
previousData = { initial = {} }
},
execute = function(domoticz, sensor)
-- add new data
table.insert(domoticz.data.previousData, sensor.temperature)
-- calculate the average
local sum = 0, count = 0
for i, temp in pairs(domoticz.data.previousData) do
sum = sum + temp
count = count + 1
end
local average = sum / count
end
}
A special kind of persistent variables: history = true[edit]
In some situation, storing a previous value for a sensor is not enough and you would like to have more previous values for example when you want to calculate an average over several readings or see if there was a constant rise or decrease. Of course you can define a persistent variable holding a table:
This quote is from the actual wiki. Docs should be updated, the example is outdated