Having a look to the day temperature graph, i can see the max and min are already calculated/extracted
So maybe is possible to extract them from database...
Thanx in advance
Fabrizio
Moderator: leecollings
This could be a way to do it.acaonweb wrote: Sunday 05 May 2019 10:03 Hi, there is a way to extract max and min temperature in a day using dzevents in native way i mean using data are stored by domoticz?
Code: Select all
local scriptVar = "minMaxTemp"
return {
on = {
timer = { "every 12 minutes" },
httpResponses = { scriptVar .. "*" }
},
logging = {
level = domoticz.LOG_ERROR,
marker = scriptVar,
},
execute = function(dz, item)
-- ****************************** Your settings below this line ***************************************************
temperatureDevice = dz.devices(xxxx) -- Replace with ID of temperatureDevice you want to track
minMax = dz.devices(yyyy) -- Create as virtual text sensor
-- ****************************** No changes required below this line *********************************************
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local function getGraphData(id)
local url = dz.settings['Domoticz url'] .. "/json.htm?type=graph&sensor=temp&range=month&idx=" .. id
dz.openURL({ url = url,
method = "GET",
callback = scriptVar .. "_" .. id})
end
local function getMinMax(rt)
for idx, v in ipairs(rt) do
if rt[idx].d == dz.time.rawDate then
return dz.utils.round(rt[idx].tm,1) , dz.utils.round( rt[idx].te,1 ) -- min, max
end
end
end
local function formatText(min,max)
return ( os.date("%A ") .. dz.time.day .. " " .. os.date("%B ") .. " " .. dz.time.year .. "\n" ..
"min. temp: " .. min .. " °C\n" ..
"max. temp: " .. max .. " °C") -- full-Dayname day full-Monthname yyyy
end
if not item.isHTTPResponse then
getGraphData(temperatureDevice.idx)
elseif item.ok then -- statusCode == 2xx
minMax.updateText(formatText(getMinMax(item.json.result)))
else
logWrite("Could not get (good) data from domoticz. Error (" .. (item.statusCode or 999) .. ")" ,dz.LOG_ERROR)
logWrite(item.data)
end
end
}
Users browsing this forum: No registered users and 1 guest