wizzard72 wrote: Wednesday 26 August 2020 17:03
How to do something similar with persistent data variables? If looping through the persistent data variables names is possible, this is also a solution for me.
Please note that
initial = has no meaning for historic persistent data and is therefore ignored.
As most other objects in dzVents, persistent historic data is a Lua table. Lua table with a string type key can be accessed via two different styles (the one without brackets is so called " Syntax sugar")
dz.data.myVar1.data = dz.data.myVar1['data'] = dz.data['myVar1'].data = dz.data{'myvar' .. 1][data] -- etc..
Hope below example helps understanding
Code: Select all
return
{
on =
{
timer =
{
'every minute',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = ' persistent' ,
},
data =
{
myVar1 = { history = true, maxItems = 4 },
myVar2 = { history = true, maxItems = 3 },
myVar3 = { history = true, maxItems = 2 },
myVar4 = { history = true, maxItems = 5 },
},
execute = function(dz, item)
for i = 1, 4 do
dz.data[ 'myVar' .. i ].add( i * dz.time.minutes )
end
dz.log('Raw Date Time of first record in myVar4: ' .. dz.data.myVar3.getOldest().time.raw,dz.LOG_DEBUG) -- direct access via
for i = 4, 1, -1 do
dz.log(dz.data[ 'myVar' .. i ]['getOldest']().data,dz.LOG_DEBUG)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki