i made a little script which checks a barometer drop or rise thus predicting the chance of a storm or hard wind.
i however got a couple of problems
every hour i record the value in a historical record but the initial value does not seem to be set to 0(thus causing problems)
also dz.utils.round(dz.data.pressure.get(12).data,1) does not seem to work (nil error but initial should be 0)
how can i initialize a local value to 0 when the value in the historical record is nill and causing an error
here is the script
Code: Select all
return {
on = { timer = { 'Every minute'}},
data = {
pressure = { history = true, maxItems = 12, initial = 0 }
},
execute = function(dz, trigger)
local myNotificationTable = {dz.NSS_Telegram}
local sensor = dz.devices('Barometer')
if dz.data.pressure.getOldest() == nil then -- Check if history is already filled (initial does not work with history persistent data
dz.data.pressure.add(10)
end
local twelvehourpressure = dz.utils.round(dz.data.pressure.getOldest().data,1)
local threehourpressure = dz.utils.round(dz.data.pressure.get(3).data,1)
local currentpressure = dz.utils.round(sensor.barometer,1)
local threehourdelta = 0
local twelvehourdelta = 0
local threehourdelta = threehourpressure - currentpressure
local twelvehourdelta = twelvehourpressure - currentpressure
-- severe storm warning barometer drop
if ((twelvehourdelta >= 8 or threehourdelta >= 0) and currentpressure < 1011) then
local notifyString = "Sterke luchtdruk daling".."\r\n".."luchtdruk is "..currentpressure.."hPa".."\r\n".."Kans op zware storm"
dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable )
end
-- storm warning barometer rise
if threehourdelta <= -3 then
local notifyString = "Sterke luchtdruk daling".."\r\n".."luchtdruk is "..currentpressure.."hPa".."\r\n".."Kans op harde wind"
dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable )
end
-- add new data
dz.data.pressure.add(sensor.barometer)
end
}