Page 14 of 16
Re: Is it gonna rain within the next X minutes?
Posted: Thursday 16 November 2017 22:23
by quilae
All right, I see the problem. I thought the term "rain device" in the script was just descriptive, but it's not. It needs to be a device of type 'rain" not just a "text" device. So now it's working.
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 26 December 2017 14:31
by Brutus
Does anyone else experience that there rain.tmp file is empty?
The link:
Code: Select all
url='http://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon..''
gives me output in any browser. The rain.tmp file gets refreshed every minute but it's empty.
So the rain prediction gives now the output: -nan(ind)
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 11:13
by DutchHans
Yes, I have the same...
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 11:53
by jvdz
Works fine here scheduled with crontab.
How are you running the script ? Did it ever work and stopped?
Jos
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 12:39
by DutchHans
Hi Jos...
It worked flawlessly for years but suddenly it stopped. I see no reason why. The URL shows in the browser the correct data but the tempfile is not written. I've tried to write it under a different name but its not written.
I have no idea why...
I am running the script as a lua time file, fired every 15 minutes
Regards,Hans
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 12:43
by Brutus
jvdz wrote: ↑Wednesday 27 December 2017 11:53
Works fine here scheduled with crontab.
How are you running the script ? Did it ever work and stopped?
Jos
Hi Jos,
I have implemented this script in my LUA screens time script and runs every minute. But as DutchHans says it has run for years. I did not change anything suddently it stopped working.
I'm running: Windows 7 64 Bits with Domoticz V3.8721
Greetings
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 13:03
by DutchHans
Solved!
The URL is converted from http in https in the browser.
When you change http into https in the script it works again.
Cheers, Hans
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 13:04
by DutchHans
Solved!
The URL is converted from http in https in the browser.
When you change http into https in the script it works again.
Cheers, Hans
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 20:03
by EdwinK
This line?
Code: Select all
-- url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon -- old link
url='https://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 20:15
by DutchHans
The first line is commented (because of the -- at the beginning) that one doesn't matter. The line that matters is:
Code: Select all
url='https://gadgets.buienradar.nl/data/raintext/?lat='..lat..'&lon='..lon
Regards,Hans
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 27 December 2017 20:24
by EdwinK
Okay, then I have the correct one. Knew that the first line was commented, copy/paste and too lazy to remove it.
Re: Is it gonna rain within the next X minutes?
Posted: Thursday 28 December 2017 23:08
by Brutus
DutchHans wrote: ↑Wednesday 27 December 2017 13:04
Solved!
The URL is converted from http in https in the browser.
When you change http into https in the script it works again.
Cheers, Hans
Thnx, This solved it for me to.
Re: Is it gonna rain within the next X minutes?
Posted: Saturday 30 December 2017 19:27
by mvroosmalen
Hi,
after being unable to get info from the regular site, I decide to search for a website that would do the trick again and..

its working again. Still not fully satisfied I made some changes to the original code. If you appreciate the changes, enjoy !!!
I pasted the full code in this message
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.
-- rewriten by mvroosmalen @ gmx net
-- 30-12-2017 v0.6 modified by MvR removed temp file etc. changed website (default was not working for me)
-- Written in LUA by Hans van der Heijden (h4nsie @ gmail.com)
-- 03-03-2017 v0.5 function removed and start and end time included
-- text output included which shows first rain period and duration
-- 14-11-2016 v0.4 changed lat/lon to max 2 decmals after comma
-- 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)
--
-- config ------------------------------------------------------------------------------------------------------
lat='51.11' -- example lat/lon for Tilburg
lon='5.13' -- NOTE: lat and lon should have max 2 decimals after dot to function (requirement Buienradar)
debug=false -- True to log all changes
minuten=10 -- Rain check periode
text_sensor='regeninfo'
IDX_txt_sensor='395' -- IDx text sensor for perminent rain notifications
regen_sensor='Rain expected' -- Rain sensor switch (on/off)
http = require("socket.http")
domoticzurl='192.168.1.xxx:yyy' -- domoticz website
Rain_alert=0.2 -- Alert when maxrain is exceeding .... mm/hour .
-- functions ---------------------------------------------------------------------------------------------------
function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function lines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r?\n", helper)))
return t
end
-- Main code ----------------------------------------------------------------------------------------------------
commandArray = {}
-- check if variable geenregen is present, if not create it to store rain status
if (uservariables['geenregen'] == nil) then
commandArray['OpenURL']=domoticzurl..'/json.htm?type=command¶m=saveuservariable&vname='..UrlEncode('geenregen')..'&vtype=2&vvalue=0'
end
time = os.date("*t")
if ((time.min % minuten)==0) then
----- check REGEN ------
-- url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon
-- use
-- url='http://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon
-- or
-- url='http://br-gpsgadget-new.azurewebsites.net/data/raintext?lat='..lat..'&lon='..lon
-- isn't working sice 2016/08/29: url is changed in:
url='http://br-gpsgadget-new.azurewebsites.net/data/raintext?lat='..lat..'&lon='..lon
body = http.request(url)
if debug then print(url) end
-- if nothing received then exit
if body == nil then
if debug then print ("rain: no data recieved") end
return commandArray
end
row=lines(body)
if debug then print (body) end
-- check only if more the 4 lines of data are captured
if #row>4 then
starttijd=nil
eindtijd=nil
totalrain=0
gevonden=false
rainlines=0
maxrain=0
-- now analyse the received lines, format is like 000|15:30 per line.
for t=1,#row do
if string.find(row[t],'|')==nil then break end
if debug then print('Line:'..row[t]) end
linetime=string.sub(row[t], 5, 9)
if debug then print('Linetime: '..linetime) end
rain=tonumber(string.sub(row[t], 0, 3))
totalrain = totalrain+rain
if gevonden then rainlines=rainlines+1 end
if debug then print('Rain in timerange: '..rain) end
if debug then print('Total rain now: '..totalrain) end
if ((not gevonden) and (rain>0)) then
starttijd=linetime
rainlines=rainlines+1
gevonden=true
if debug then print('Rain starts at: '..starttijd) end
end
if (gevonden and (rain>maxrain)) then maxrain=rain end
if ((gevonden) and (rain==0)) then
eindtijd=linetime
if debug then print('Rain ends at: '..eindtijd) end
gevonden=false
break
end
end
if gevonden then eindtijd=">"..linetime end
-- 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)
if (totalrain>0) then
regen=totalrain/rainlines
regen=Round(10^((regen -109)/32),2)
maxrain=Round(10^((maxrain -109)/32),2)
else
regen=0
end
if debug then print('regen = '..regen) end
if (starttijd==nil) then
--print('Geen regen verwacht over '..minuten)
if debug then print('starttijd is empty: geen regen verwacht') end
if tonumber(uservariables['geenregen'])==0 then
commandArray['UpdateDevice']=IDX_txt_sensor..'|0|'..'geen regen verwacht'
commandArray['Variable:geenregen']="1";
end
starttijd=0
if eindtijd==nil then eindtijd=0 end
else
commandArray['UpdateDevice']=IDX_txt_sensor..'|0|'..regen..'mm/h om '..starttijd..' tot '..eindtijd..' Max=' .. maxrain..'mm/h'
if debug then print('Regen verwachting: '..regen..' mm/h om '..starttijd..' tot '..eindtijd) end
commandArray['Variable:geenregen']="0";
if debug then print('starttijd = '..starttijd) end
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(starttijd,1,2), min=string.sub(starttijd,4,5), sec=os.date('%S')}
difference = os.difftime (linetime2,os.time())
-- When a line entry has a time in the future AND is in the given range, then report the rainfall
if ((difference >= 0) and (difference<=minuten*60)) then
if debug then print('Line in time range found') end
commandArray['Variable:geenregen']="0";
if maxrain > Rain_alert and otherdevices[regen_sensor]=='Off' then
commandArray['SendNotification']='Regen verwacht: '..regen..'mm/h om '..starttijd..' tot '..eindtijd..' Max=' .. maxrain..'mm/h'
end
if maxrain > Rain_alert then commandArray['Rain expected']='On' end
end
if regen == 0 and otherdevices[regen_sensor]=='On' then
if debug then print('No rain expected') end
commandArray['SendNotification']='Geen regen meer verwacht'
if tonumber(uservariables['geenregen'])==0 then
commandArray['UpdateDevice']=IDX_txt_sensor..'|0|'..'geen regen verwacht'
commandArray['Variable:geenregen']="1";
end
end
if regen == 0 then commandArray['Rain expected']='Off' end
end
end
return commandArray
Thanks for the tip EdwinK

Re: Is it gonna rain within the next X minutes?
Posted: Saturday 30 December 2017 22:38
by EdwinK
You can post your code here, instead of adding files.
Just use [ code ] and [/ code ] tags (remove spaces from the tags.
Re: Is it gonna rain within the next X minutes?
Posted: Saturday 20 January 2018 21:08
by Mace
I get bombarded with notifications raging from email thru pushbullet....How can I limit the notifications to 1 medium?
Re: Is it gonna rain within the next X minutes?
Posted: Monday 22 January 2018 8:06
by mvroosmalen
Change the Rain_alert=0.2 to a higher value.
Mark
Re: Is it gonna rain within the next X minutes?
Posted: Monday 22 January 2018 22:09
by Mace
He Mark. I'd like to get notifications only thru one channel. Now it's everything (mail, pushbullet, ...). So it's not the frequency.
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 23 January 2018 7:51
by mvroosmalen
He mace,
In that case change then commandArray['SendNotification']=....... to code to only send to for example pushbullet or change settings.
s6
Mark
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 24 January 2018 12:33
by poudenes
Hi All,
no matter what i do i get a error
Code: Select all
2018-01-24 12:31:00.305 LUA: http://gadgets.buienradar.nl/data/raintext/?lat=52.06&lon=4.39
2018-01-24 12:31:00.420 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_raintext.lua: /home/pi/domoticz/scripts/lua/script_time_raintext.lua:14: attempt to index global 'file' (a nil value)
How can i solve this?
output of the http link:
Code: Select all
000|12:30
000|12:35
000|12:40
000|12:45
000|12:50
000|12:55
000|13:00
000|13:05
000|13:10
000|13:15
000|13:20
000|13:25
000|13:30
000|13:35
000|13:40
000|13:45
000|13:50
000|13:55
000|14:00
000|14:05
000|14:10
000|14:15
000|14:20
000|14:25
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 28 January 2018 9:42
by Mace
mvroosmalen wrote: ↑Tuesday 23 January 2018 7:51
He mace,
In that case change then commandArray['SendNotification']=....... to code to only send to for example pushbullet or change settings.
s6
Mark
Thanks Mark, I however have no clue on how to doe that...
