Page 1 of 1
is it possible to use an array to declare persistent data?
Posted: Thursday 04 July 2019 21:36
by papoo
I want an easy way to declare my persistent data
the devices are declared at the beginning of the script in MyDevices array
how can i do a loop on this array to declare the devices in data ={ }
Code: Select all
local MyDevices = {'device1','device2','device3'}
return {
active = true,
on = {
timer = { 'every 5 minutes' },
},
data = {
-- here i want to do a for loop to declare device1 device2 and device3
},
Re: is it possible to use an array to declare persistent data?
Posted: Thursday 04 July 2019 21:48
by boum
Using the local array should work.
Of course you should put it into form first.
Code: Select all
local MyDevices = {'device1','device2','device3'}
local myData = {}
for i,v in ipairs(MyDevices) do
myData[v] = { initial = -1 } -- put your initial value here if there is one
end
return {
active = true,
on = {
timer = { 'every 5 minutes' },
},
data = myData,
Re: is it possible to use an array to declare persistent data?
Posted: Thursday 04 July 2019 21:58
by papoo
Unfortunately no
Re: is it possible to use an array to declare persistent data?
Posted: Thursday 04 July 2019 22:15
by boum
I tried and the persistent data is not written to disk unless there is an initial value set. So I modified the script in my first post to reflect it
Re: is it possible to use an array to declare persistent data?
Posted: Thursday 04 July 2019 22:21
by boum
I did a few more tries with persistent datas (never tried them before).
It looks like you can pass directly MyDevices to data, but the data will be written to disk only when you set a value in the execute function. I suppose when your script has ended, the dzVents system go through the data table and if something has been set in your domoticz.data table, then the new value is serialized to disk. (If you do a domoticz.data.glop = "foo" in your execute function but glop is not in the declared data, it won't get dumped).
Re: is it possible to use an array to declare persistent data? [Solved]
Posted: Thursday 04 July 2019 23:03
by papoo
thanks
work fine