16.01.2025, 21:56
(This post was last modified: 16.01.2025, 22:04 by jerryhenke.)
(16.01.2025, 17:08)Erwin van der Zwart Wrote: For the outdoor temp combined with a curve i usually use a 3 days average, this can simply be done by attaching a trend to your measurement object and use this small script.
Code:require('trends')
dateslastthreedays = {}
dateslastthreedays['start'] = os.date('*t', os.time() - (86400 * 4))
dateslastthreedays['end'] = os.date('*t', os.time() - (86400 * 1))
threedaysaverage = trends.fetchone('OUTDOOR TEMP', dateslastthreedays)
The only trend I have right now is outdoor temperature with a 5-min resolution.
I tried your script and can't really make it work.
I get incorrect values. I would rather like to use a span of the last 9 hours average temperature or so, not from four days agou until yesterday which i read your script.
I tried change 86400 * 4 to 86400 * 1 and the "end" to 86400 * 0, but that gives 0 as temperature.
Any good suggestions?
Quote:require('trends')
-- Define time range for the timespan
local lastninehours = {}
lastninehours['start'] = os.date('*t', os.time() - (3600 * 9)) -- 9 hours back
lastninehours['end'] = os.date('*t', os.time()) -- Current time
-- Fetch the average temperature for the timespan
local ninehoursaverage = trends.fetchone('Utetemp', lastninehours)
-- Fetch the current temperature from KNX address 0/3/0
local currenttemperature = grp.getvalue('0/3/0') -- Assumes grp.getvalue function is used
if ninehoursaverage and currenttemperature then
-- Calculate the highest value between the average temperature and the current temperature
local highesttemperature = math.max(ninehoursaverage, currenttemperature)
-- Send the highest value to KNX address 5/5/20
grp.write('5/5/20', highesttemperature)
-- Log both the average temperature and the temperature sent
log("Average temperature for the last 9 hours: " .. tostring(ninehoursaverage))
log("Temperature sent to 5/5/20: " .. tostring(highesttemperature))
else
log("Could not fetch the average temperature or the current temperature.")
end