jvdz wrote: Thursday 04 March 2021 10:41
Probably the same issue as I solved here:
viewtopic.php?p=257405#p257405
Would have to see the script you use the give an exact solution.
Jos
It still gives me an error, i thought it was solved, but there is rain coming.
Output log
Code: Select all
2021-03-04 11:16:00.548 Error: EventSystem: in RainNieuw: [string "---------------------------------------------..."]:66: attempt to perform arithmetic on a nil value (global 'rain')
Line 66 = totalrain = totalrain+rain
Output buienradar:
Code: Select all
92,2678801510292|11:15
92,2678801510292|11:20
111,53379987352399|11:25
112,64618727381878|11:30
112,64618727381878|11:35
112,64618727381878|11:40
112,64618727381878|11:45
116,37436548410477|11:50
117,16872016330579|11:55
116,37436548410477|12:00
114,6349202897818|12:05
114,6349202897818|12:10
112,64618727381878|12:15
111,53379987352399|12:20
111,53379987352399|12:25
112,64618727381878|12:30
112,64618727381878|12:35
114,6349202897818|12:40
116,37436548410477|12:45
116,37436548410477|12:50
112,64618727381878|12:55
112,64618727381878|13:00
111,53379987352399|13:05
111,53379987352399|13:10
Code i use
Code: Select all
----------------------------------------------------------------------------------------------------------------
-- IsItGonnaRain( int minutesinfuture)
-- returns: int avarage rainfall for the next minutesinfuture
--
-- Function to get rain prediction from Buienradar.nl (dutch)
--
-- http://gratisweerdata.buienradar.nl/#Buienradar You may use their free service for non-commercial purposes.
--
-- Written in LUA by Hans van der Heijden (h4nsie @ gmail.com)
-- Spring 2015
-- 04-03-2020 v0.5 Code aangepast voor nieuwe buienradar uitput en twee scripts samengevoegd
-- 02-05-2018 v0.4 changed from curl to wget and added time-out.
-- 28-03-2015 v0.3 bug: quotes around url added.
-- 27-03-2015 v0.2 return value is now average for next time
-- 26-03-2015 v0.1 Initial release
-- todo: some error checking on http and file handling (tmp file)
----------------------------------------------------------------------------------------------------------------
local RainTextIDX = 3962 -- your domoticz virtual TEXT device (add virtual text device first, if you didnt do this allready and use its idx)
local RegenkleurIDX = 9450
function IsItGonnaRain( minutesinfuture )
-- config ---------------------------------------------------------
lat='50.82' -- example lat/lon for Maastricht
lon='5.72'
-- lat='51.51' -- example lat/lon for Waar het regent
-- lon='4.39'
debug = true
tempfilename = '/home/pi/domoticz/tmp/rainn.tmp' -- can be anywhere writeable
-- /config ---------------------------------------------------------
url='https://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon
if debug then print(url) end
read = os.execute('wget -m 10 -O '..tempfilename..' "'..url..'"')
file = io.open(tempfilename, "r")
totalrain=0
rainlines=0
-- now analyse the received lines, format is like 000|15:30 per line.
while true do
line = file:read("*line")
if not line then break end
rain,linetime = line:match("(%d+).-|(.+)%s?")
rain = tonumber(rain) or 0
linetime = linetime or "00:00"
linetime = linetime:gsub("[\r\n]","")
if debug then print('NEWIGR: Rain in timerange: '..rain .. ' linetime:'..linetime..' Line:' ..line ) end
-- Linetime2 holds the full date calculated from the time on a line
linetime2 = os.time{year=os.date('%Y'), month=os.date('%m'), day=os.date('%d'), hour=string.sub(linetime,1,2), min=string.sub(linetime,4,5), sec=os.date('%S')}
difference = os.difftime (linetime2,os.time())
if debug then print (difference) end
-- When a line entry has a time in the future AND is in the given range, then totalize the rainfall
if ((difference > 0) and (difference<=minutesinfuture*60)) then
if debug then print('Line in time range found') end
rain=tonumber(string.sub(tostring(line), 0, 3))
totalrain = totalrain+rain
rainlines=rainlines+1
if debug then print('NEWIGR:Rain in timerange: '..rain) end
if debug then print('NEWIGR:Total rain now: '..totalrain) end
end
end
file:close()
-- Returned value is average rain fall for next time
-- 0 is no rain, 255 is very heavy rain
-- When needed, mm/h is calculated by 10^((value -109)/32) (example: 77 = 0.1 mm/hour)
averagerain=totalrain/rainlines
return(averagerain)
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
edit:
Now it works maybe for a few minutes. Didnt change anything:
Maybe it has something to do with the first lines from the previous output.
Code: Select all
92,2678801510292|11:15
92,2678801510292|11:20
output domoticz log:
Code: Select all
2021-03-04 11:18:00.557 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:13:10 Line:109|13:10
2021-03-04 11:18:00.557 Status: LUA: 6720.0
2021-03-04 11:18:00.557 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:13:15 Line:109|13:15
2021-03-04 11:18:00.557 Status: LUA: 7020.0
2021-03-04 11:18:00.557 Status: LUA: Regen verwacht: 1.0 mm binnen 15 minuten.
2021-03-04 11:18:01.097 (Domoticz) Temp (Unknown)
2021-03-04 11:18:01.901 MQTT: Topic: domoticz/in, Message: {"idx":7344,"nvalue":0,"svalue":"0;282528.4","Battery":88,"RSSI":7}
2021-03-04 11:18:01.986 Status: LUA: https://gadgets.buienradar.nl/data/raintext?lat=50.82&lon=5.72
2021-03-04 11:18:02.141 Status: LUA: NEWIGR: Rain in timerange: 104 linetime:11:20 Line:104,04313728045622|11:20
2021-03-04 11:18:02.141 Status: LUA: 120.0
2021-03-04 11:18:02.141 Status: LUA: Line in time range found
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Rain in timerange: 104
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Total rain now: 104
2021-03-04 11:18:02.141 Status: LUA: NEWIGR: Rain in timerange: 111 linetime:11:25 Line:111,53379987352399|11:25
2021-03-04 11:18:02.141 Status: LUA: 420.0
2021-03-04 11:18:02.141 Status: LUA: Line in time range found
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Rain in timerange: 111
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Total rain now: 215
2021-03-04 11:18:02.141 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:11:30 Line:112,64618727381878|11:30
2021-03-04 11:18:02.141 Status: LUA: 720.0
2021-03-04 11:18:02.141 Status: LUA: Line in time range found
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Rain in timerange: 112
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Total rain now: 327
2021-03-04 11:18:02.141 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:11:35 Line:112,64618727381878|11:35
2021-03-04 11:18:02.141 Status: LUA: 1020.0
2021-03-04 11:18:02.141 Status: LUA: Line in time range found
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Rain in timerange: 112
2021-03-04 11:18:02.141 Status: LUA: NEWIGR:Total rain now: 439
2021-03-04 11:18:02.141 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:11:40 Line:112,64618727381878|11:40
2021-03-04 11:18:02.141 Status: LUA: 1320.0
2021-03-04 11:18:02.142 Status: LUA: Line in time range found
2021-03-04 11:18:02.142 Status: LUA: NEWIGR:Rain in timerange: 112
2021-03-04 11:18:02.142 Status: LUA: NEWIGR:Total rain now: 551
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:11:45 Line:112,64618727381878|11:45
2021-03-04 11:18:02.142 Status: LUA: 1620.0
2021-03-04 11:18:02.142 Status: LUA: Line in time range found
2021-03-04 11:18:02.142 Status: LUA: NEWIGR:Rain in timerange: 112
2021-03-04 11:18:02.142 Status: LUA: NEWIGR:Total rain now: 663
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:11:50 Line:114,6349202897818|11:50
2021-03-04 11:18:02.142 Status: LUA: 1920.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 116 linetime:11:55 Line:116,37436548410477|11:55
2021-03-04 11:18:02.142 Status: LUA: 2220.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 116 linetime:12:00 Line:116,37436548410477|12:00
2021-03-04 11:18:02.142 Status: LUA: 2520.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:12:05 Line:114,6349202897818|12:05
2021-03-04 11:18:02.142 Status: LUA: 2820.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:12:10 Line:112,64618727381878|12:10
2021-03-04 11:18:02.142 Status: LUA: 3120.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:12:15 Line:109|12:15
2021-03-04 11:18:02.142 Status: LUA: 3420.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:12:20 Line:109|12:20
2021-03-04 11:18:02.142 Status: LUA: 3720.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:12:25 Line:109|12:25
2021-03-04 11:18:02.142 Status: LUA: 4020.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 105 linetime:12:30 Line:105,8988795837422|12:30
2021-03-04 11:18:02.142 Status: LUA: 4320.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 111 linetime:12:35 Line:111,53379987352399|12:35
2021-03-04 11:18:02.142 Status: LUA: 4620.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:12:40 Line:112,64618727381878|12:40
2021-03-04 11:18:02.142 Status: LUA: 4920.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:12:45 Line:114,6349202897818|12:45
2021-03-04 11:18:02.142 Status: LUA: 5220.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:12:50 Line:114,6349202897818|12:50
2021-03-04 11:18:02.142 Status: LUA: 5520.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:12:55 Line:114,6349202897818|12:55
2021-03-04 11:18:02.142 Status: LUA: 5820.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 114 linetime:13:00 Line:114,6349202897818|13:00
2021-03-04 11:18:02.142 Status: LUA: 6120.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 112 linetime:13:05 Line:112,64618727381878|13:05
2021-03-04 11:18:02.142 Status: LUA: 6420.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:13:10 Line:109|13:10
2021-03-04 11:18:02.142 Status: LUA: 6720.0
2021-03-04 11:18:02.142 Status: LUA: NEWIGR: Rain in timerange: 109 linetime:13:15 Line:109|13:15
2021-03-04 11:18:02.142 Status: LUA: 7020.0
2021-03-04 11:18:02.158 Status: EventSystem: Script event triggered: RainNieuw
2021-03-04 11:18:02.192 Status: dzVents: Info: Handling httpResponse-events for: "MaxTemp_7257"
2021-03-04 11:18:02.194 Status: dzVents: Info: Handling httpResponse-events for: "minTemp_7257"
2021-03-04 11:18:02.195 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-03-04 11:18:03.775 (Led Gang Boven) Heartbeating...
2021-03-04 11:18:03.779 (Led Gang Boven) MqttClient::Ping
2021-03-04 11:18:03.779 (Led Douche) Heartbeating...
2021-03-04 11:18:03.779 (Led Douche) MqttClient::Ping
2021-03-04 11:18:03.779 (Led Keuken) Heartbeating...
2021-03-04 11:18:03.779 (Led Keuken) MqttClient::Ping
2021-03-04 11:18:03.780 (Led trappenkast) Heartbeating...
2021-03-04 11:18:03.780 (Led trappenkast) MqttClient::Ping
2021-03-04 11:18:03.780 (Led Keukenkast) Heartbeating...
2021-03-04 11:18:03.780 (Led Keukenkast) MqttClient::Ping
output buienradar
Code: Select all
104,04313728045622|11:20
111,53379987352399|11:25
112,64618727381878|11:30
112,64618727381878|11:35
112,64618727381878|11:40
112,64618727381878|11:45
114,6349202897818|11:50
116,37436548410477|11:55
116,37436548410477|12:00
114,6349202897818|12:05
112,64618727381878|12:10
109|12:15
109|12:20
109|12:25
105,8988795837422|12:30
111,53379987352399|12:35
112,64618727381878|12:40
114,6349202897818|12:45
114,6349202897818|12:50
114,6349202897818|12:55
114,6349202897818|13:00
112,64618727381878|13:05
109|13:10
109|13:15
edit2: is it not posible to delete everything behind the comma , as you mentioned in your other post.
Something to do with

:
Code: Select all
rain,linetime = line:match("(%d+).-|(.+)%s?")
