DzVents How can I reset History.size?
Posted: Friday 01 April 2022 14:52
I built a script to calculate the average of 60 readings from my SEM228T Pyranometer every 10 minutes. I have the script working to the extent that the 10 minute average is calculated every 10 seconds. However, that is a moving average. What I want is just write the average of the last 10 minutes to a General Custom Sensor once every 10 minutes and then calculate the average of the next 10 minutes and so on. What I have is the following:
This is the output:
The History entries just stays at 59 in the log. Attempts to reset it to 0 after calculating the average of the 60 measurements have so far failed. Well did I find this: https://www.domoticz.com/wiki/DzVents:_ ... %20Returns I tried to use it.
But I don't seem to understand how to use it. I get folowing error message:
when uncommenting reset()
or this when uncommenting the two rules above reset()
Pls. point me in the right direction.
Code: Select all
return
{
on = {
devices = {'Test Total solar radiation'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'SEM228T 10 min',
},
data =
{
SEM228THistory = { history = true, maxMinutes = 10},
},
execute = function(domoticz, sensor)
-- add new data
domoticz.data.SEM228THistory.add(sensor.radiation)
-- average
local RadAverage = domoticz.data.SEM228THistory.avg()
domoticz.log('average radiation ' .. RadAverage, domoticz.LOG_INFO)
-- maximum value in the past 10 minutes:
local RadMax = domoticz.data.SEM228THistory.maxSince('00:10:00')
domoticz.log('max radiation ' .. RadMax, domoticz.LOG_INFO)
-- minimum value in the past 10 minutes:
local RadMin = domoticz.data.SEM228THistory.minSince('00:10:00')
domoticz.log('min radiation ' .. RadMin, domoticz.LOG_INFO)
domoticz.log('SEM228THistory entries = ' .. domoticz.data.SEM228THistory.size, domoticz.LOG_DEBUG)
if (domoticz.data.SEM228THistory.size > 59) then
RoundAverage = domoticz.utils.round( (RadAverage),0)
domoticz.devices('SEM228T 10 min Av.').updateCustomSensor(RoundAverage)
domoticz.devices('SEM228T 10 min Min.').updateCustomSensor(RadMin)
domoticz.devices('SEM228T 10 min Max.').updateCustomSensor(RadMax)
--domoticz.log('Not enough data points yet to produce something useful', domoticz.LOG_DEBUG)
--domoticz.log(domoticz.data.SEM228THistory.size .. ' entries for ' .. SEM228THistory .. ' in History', domoticz.LOG_DEBUG)
--reset()
end
end
}Code: Select all
2022-04-01 14:57:17.683 Status: dzVents: Info: SEM228T 10 min: ------ Start external script: SEM228T10M.lua: Device: "Test Total solar radiation (Test Total solar radiation)", Index: 610
2022-04-01 14:57:17.703 Status: dzVents: Info: SEM228T 10 min: average radiation 672.52542372881
2022-04-01 14:57:17.703 Status: dzVents: Info: SEM228T 10 min: max radiation 733
2022-04-01 14:57:17.703 Status: dzVents: Info: SEM228T 10 min: min radiation 368
2022-04-01 14:57:17.703 Status: dzVents: Debug: SEM228T 10 min: SEM228THistory entries = 59
2022-04-01 14:57:17.708 Status: dzVents: Info: SEM228T 10 min: ------ Finished SEM228T10M.lua
But I don't seem to understand how to use it. I get folowing error message:
Code: Select all
2022-04-01 14:47:17.736 Error: dzVents: Error: (3.1.7) SEM228T 10 min: An error occurred when calling event handler SEM228T10M
2022-04-01 14:47:17.736 Error: dzVents: Error: (3.1.7) SEM228T 10 min: /home/pi/domoticz/scripts/dzVents/scripts/SEM228T10M.lua:50: attempt to call a nil value (global 'reset')or this when uncommenting the two rules above reset()
Code: Select all
2022-04-01 14:51:07.370 Error: dzVents: Error: (3.1.7) SEM228T 10 min: An error occurred when calling event handler SEM228T10M
2022-04-01 14:51:07.370 Error: dzVents: Error: (3.1.7) SEM228T 10 min: /home/pi/domoticz/scripts/dzVents/scripts/SEM228T10M.lua:48: attempt to concatenate a nil value (global 'SEM228THistory')