Is it gonna rain within the next X minutes?

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
User avatar
jvdz
Posts: 1338
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by jvdz » Thursday 16 November 2017 22:40

The content is described in the WiKi: https://www.domoticz.com/wiki/Domoticz_ ... L%27s#Rain

Jos

quilae
Posts: 8
Joined: Tuesday 07 November 2017 22:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by quilae » Thursday 16 November 2017 22:50

Thanks for your quick reply. In the meantime I figured out myself it has to do with this line:

Code: Select all

url=domoticzurl..'/json.htm?type=command&param=udevice&idx=' .. DEVIDX .. '&nvalue=0&svalue=' .. calcmmh .. ';' .. calcmmh
I did take a look at your wiki reference but I don't understand what the RAINCOUNTER value as shown on the wiki is supposed to mean.

quilae
Posts: 8
Joined: Tuesday 07 November 2017 22:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by quilae » Thursday 16 November 2017 23:23

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.

User avatar
Brutus
Posts: 306
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by Brutus » Tuesday 26 December 2017 15:31

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)
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

DutchHans
Posts: 312
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by DutchHans » Wednesday 27 December 2017 12:13

Yes, I have the same...

User avatar
jvdz
Posts: 1338
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by jvdz » Wednesday 27 December 2017 12:53

Works fine here scheduled with crontab.
How are you running the script ? Did it ever work and stopped?

Jos

DutchHans
Posts: 312
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by DutchHans » Wednesday 27 December 2017 13:39

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

User avatar
Brutus
Posts: 306
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by Brutus » Wednesday 27 December 2017 13:43

jvdz wrote:
Wednesday 27 December 2017 12: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
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

DutchHans
Posts: 312
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by DutchHans » Wednesday 27 December 2017 14:03

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

DutchHans
Posts: 312
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by DutchHans » Wednesday 27 December 2017 14: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

User avatar
EdwinK
Posts: 1201
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Is it gonna rain within the next X minutes?

Post by EdwinK » Wednesday 27 December 2017 21:03

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 | RFxcom | Dashticz V2 |

DutchHans
Posts: 312
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Is it gonna rain within the next X minutes?

Post by DutchHans » Wednesday 27 December 2017 21:15

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

User avatar
EdwinK
Posts: 1201
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Is it gonna rain within the next X minutes?

Post by EdwinK » Wednesday 27 December 2017 21:24

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 | RFxcom | Dashticz V2 |

User avatar
Brutus
Posts: 306
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: Is it gonna rain within the next X minutes?

Post by Brutus » Friday 29 December 2017 0:08

DutchHans wrote:
Wednesday 27 December 2017 14: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.
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

mvroosmalen
Posts: 19
Joined: Saturday 03 December 2016 17:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mvroosmalen » Saturday 30 December 2017 20:27

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&param=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 :-)
Last edited by mvroosmalen on Sunday 31 December 2017 16:05, edited 6 times in total.

User avatar
EdwinK
Posts: 1201
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Is it gonna rain within the next X minutes?

Post by EdwinK » Saturday 30 December 2017 23:38

You can post your code here, instead of adding files.

Just use [ code ] and [/ code ] tags (remove spaces from the tags.
Running latest BETA on a Pi-3 | Toon Thermostat | RFxcom | Dashticz V2 |

Mace
Posts: 77
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?

Post by Mace » Saturday 20 January 2018 22:08

I get bombarded with notifications raging from email thru pushbullet....How can I limit the notifications to 1 medium?

mvroosmalen
Posts: 19
Joined: Saturday 03 December 2016 17:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mvroosmalen » Monday 22 January 2018 9:06

Change the Rain_alert=0.2 to a higher value.
Mark

Mace
Posts: 77
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?

Post by Mace » Monday 22 January 2018 23:09

He Mark. I'd like to get notifications only thru one channel. Now it's everything (mail, pushbullet, ...). So it's not the frequency.

mvroosmalen
Posts: 19
Joined: Saturday 03 December 2016 17:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Is it gonna rain within the next X minutes?

Post by mvroosmalen » Tuesday 23 January 2018 8:51

He mace,
In that case change then commandArray['SendNotification']=....... to code to only send to for example pushbullet or change settings.

s6

Mark

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests