Is it gonna rain within the next X minutes?
Moderator: leecollings
-
- Posts: 10
- Joined: Tuesday 07 November 2017 21:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is it gonna rain within the next X minutes?
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.
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Is it gonna rain within the next X minutes?
Does anyone else experience that there rain.tmp file is empty?
The link:
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)
The link:
Code: Select all
url='http://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon..''
So the rain prediction gives now the output: -nan(ind)
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Is it gonna rain within the next X minutes?
Yes, I have the same...
- jvdz
- Posts: 2266
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Is it gonna rain within the next X minutes?
Works fine here scheduled with crontab.
How are you running the script ? Did it ever work and stopped?
Jos
How are you running the script ? Did it ever work and stopped?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Is it gonna rain within the next X minutes?
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
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
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Is it gonna rain within the next X minutes?
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
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Is it gonna rain within the next X minutes?
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
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
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Is it gonna rain within the next X minutes?
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
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
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
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
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: Is it gonna rain within the next X minutes?
The first line is commented (because of the -- at the beginning) that one doesn't matter. The line that matters is:
Regards,Hans
Code: Select all
url='https://gadgets.buienradar.nl/data/raintext/?lat='..lat..'&lon='..lon
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
Okay, then I have the correct one. Knew that the first line was commented, copy/paste and too lazy to remove it.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- Brutus
- Posts: 249
- Joined: Friday 26 September 2014 9:33
- Target OS: Windows
- Domoticz version:
- Location: Netherlands
- Contact:
Re: Is it gonna rain within the next X minutes?
Thnx, This solved it for me to.
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
-
- Posts: 23
- Joined: Saturday 03 December 2016 16:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is it gonna rain within the next X minutes?
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
Thanks for the tip EdwinK 
after being unable to get info from the regular site, I decide to search for a website that would do the trick again and..

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

Last edited by mvroosmalen on Sunday 31 December 2017 15:05, edited 6 times in total.
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
You can post your code here, instead of adding files.
Just use [ code ] and [/ code ] tags (remove spaces from the tags.
Just use [ code ] and [/ code ] tags (remove spaces from the tags.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
I get bombarded with notifications raging from email thru pushbullet....How can I limit the notifications to 1 medium?
-
- Posts: 23
- Joined: Saturday 03 December 2016 16:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is it gonna rain within the next X minutes?
Change the Rain_alert=0.2 to a higher value.
Mark
Mark
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
He Mark. I'd like to get notifications only thru one channel. Now it's everything (mail, pushbullet, ...). So it's not the frequency.
-
- Posts: 23
- Joined: Saturday 03 December 2016 16:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Is it gonna rain within the next X minutes?
He mace,
In that case change then commandArray['SendNotification']=....... to code to only send to for example pushbullet or change settings.
s6
Mark
In that case change then commandArray['SendNotification']=....... to code to only send to for example pushbullet or change settings.
s6
Mark
-
- Posts: 667
- Joined: Wednesday 08 March 2017 9:42
- Target OS: Linux
- Domoticz version: 3.8993
- Location: Amsterdam
- Contact:
Re: Is it gonna rain within the next X minutes?
Hi All,
no matter what i do i get a error
How can i solve this?
output of the http link:
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)
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
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
-
- Posts: 65
- Joined: Monday 21 August 2017 19:52
- Target OS: Windows
- Domoticz version: 3.8153
- Location: Rhoon
- Contact:
Re: Is it gonna rain within the next X minutes?
Thanks Mark, I however have no clue on how to doe that...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

Who is online
Users browsing this forum: No registered users and 1 guest