waaren wrote: Thursday 28 June 2018 23:48
Please have a look at below example of storing devices (objects ) in a Lua table and get some of the attributes of the devices in a for loop.
as an Array like Lua table
...
Thanks, this saved my day. I am glad with your help, because the online examples didn't work for me.
One more question:
Now I am able to read my inverter value in the for..next loop, I want to store it in a persistent data field in dzVents.
I have defined the different parts in the beginning of my script:
Code: Select all
data = {
Ratio1to5 = { history = true, maxItems = 7 },
Ratio1to5dev = { history = true, maxItems = 7, maxHours = 7*24 },
Ratio2to5 = { history = true, maxItems = 7 },
Ratio2to5dev = { history = true, maxItems = 7, maxHours = 7*24 },
Ratio3to5 = { history = true, maxItems = 7 },
Ratio3to5dev = { history = true, maxItems = 7, maxHours = 7*24 },
Ratio4to5 = { history = true, maxItems = 7 },
Ratio4to5dev = { history = true, maxItems = 7, maxHours = 7*24 },
and now try to call out the average values of the stored data (with a check for nil value afterwards to catch the initial call of the script with an empty table):
Code: Select all
RatioName = 'Ratio'..i..'to5'
print('Ratio name is '..RatioName)
RatioAverage = domoticz.data.RatioName.avg()
if RatioAverage == nil then RatioAverage = Ratio end
.
However, the domoticz log comes back with this error about the code line "RatioAverage = domoticz.data.RatioName.avg()":
"... attempt to index field 'RatioName' (a nil value)"
I'm guessing that the error is in the same ball field as the first question, but maybe slightly different? RatioName is nog recognized (for i = 1) as Ratio1to5 and therefore doesn't get the average out of the stored data either.