I use the following adapted script to record min and max values of temperature and calculate the avg() of both for the last 72h:
Code: Select all
-- Source: https://www.domoticz.com/forum/viewtopic.php?p=204082#p204082
local httpResponses = 'getMaxTemp'
return {on = {timer = {'at 00:00'}, -- Um Mitternacht die Max Temp der letzten 24h ermitteln
httpResponses = { httpResponses }
},
data = {
tempMaxHist = { history = true, maxItems = 3},
tempMinHist = { history = true, maxItems = 3},
},
logging = {level = domoticz.LOG_INFO,
marker = '_var_MaxAvgTemp',
},
execute = function(dz, item)
local tempDevice = dz.devices('Außen')
local extremes = {}
local tempMaxHist = dz.data.tempMaxHist
local tempMaxAvg
local tempMinHist = dz.data.tempMaxHist
local tempMinAvg
-- Temeraturwerte von device holen
if item.isDevice or item.isTimer then
dz.openURL({ url = 'http://192.168.178.23:8080/json.htm?type=graph&sensor=temp&range=day&idx=' .. tempDevice.idx .. '&range=day',
method = "GET",
callback = httpResponses })
return
end
-- Max Temperatur ermitteln
local function getExtremes(rt)
extremes.high = {}
extremes.high.temperature = -256
extremes.low = {}
extremes.low.temperature = 10000
for key in ipairs(rt) do
if tonumber(rt[key].te) > extremes.high.temperature then
extremes.high.temperature = tonumber(rt[key].te)
end
if tonumber(rt[key].te) < extremes.low.temperature then
--logWrite("New min temperature found on " .. convertTime(rt[key].d) .. " ==>> " .. rt[key].te )
extremes.low.temperature = tonumber(rt[key].te)
--extremes.low.tTime = rt[key].d
end
end
return extremes
end
-- Min/Max Temeratur ausgeben
if item.ok and item.isJSON then
extremes = getExtremes(item.json.result)
dz.devices('MaxTempGestern').updateTemperature(extremes.high.temperature)
dz.devices('MinTempGestern').updateTemperature(extremes.low.temperature)
-- Max Temperatur historisieren, durchschnitt der letzten 72h berechnen, ausgeben
tempMaxHist.add(extremes.high.temperature)
tempMaxAvg = tempMaxHist.avg()
dz.devices('TempDurchschnitt72h').updateTemperature(tempMaxAvg)
-- Min. Temperatur historisieren, durchschnitt der letzten 72h berechnen, ausgeben
tempMinHist.add(extremes.low.temperature)
tempMinAvg = tempMinHist.avg()
dz.devices('TempMinDurchschnitt72h').updateTemperature(tempMinAvg)
-- Bei Fehler loggen
else
--dz.log('Keine valide Antwort von domoticz ',dz.LOG_ERROR)
--dz.log(item,dz.LOG_ERROR)
end
end
}
I've tried to read out what is saved in both historical variables but whatever I do I get the error that I am attempting to call a nil value. I assume i am doing something wrong rather than that there are no values inside the variables because the virtual devices are being fed each day with calculated values, but they are wrong.
I've added the logged values of two virtual devices for max temperature and the avg() max temperature for comparison. Can anyone get around it?
Thank for any help,
zavjah