Page 9 of 16

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

Posted: Saturday 22 April 2017 11:18
by poudenes
Thanks. If 60 and 120 min works.. then its better then nothing for now :)
Ill follow this topic and see if the script will be updated !!
Siewert308SW wrote:@poudenes
It's a Lua script.
But forget about the script i amended.
After a closer look it aint working as i intended.
The 60 and 120min forecast are printed but are presenting the 30min prediction.
Need a closer look.

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

Posted: Saturday 22 April 2017 22:19
by krizzz
After copying the script from the wikipedia https://www.domoticz.com/wiki/Is_it_gonna_rain the script gives an error

Code: Select all

./script_time_rain.lua: line 1: ----------------------------------------------------------------------------------------------------------------: command not found
./script_time_rain.lua: line 2: syntax error near unexpected token `('
./script_time_rain.lua: line 2: `-- IsItGonnaRain( int minutesinfuture)'
Anyone having an idea?

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

Posted: Saturday 22 April 2017 23:13
by jvdz
How are you running this? ( What command did you run?)

Jos

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

Posted: Sunday 23 April 2017 17:08
by Dropshot
Hi, I would like to make use of this script, only I dont know whether I'm doing it correct. I get this in my log:

Code: Select all

2017-04-23 17:00:00.403 LUA: Regen verwacht: 0 mm binnen 15 minuten.
So the script seems to be working, yet my device (Rain expected) isn't updated. It still says 'Hello World'.. How can I get this working?

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

Posted: Monday 24 April 2017 22:32
by krizzz
jvdz wrote:How are you running this? ( What command did you run?)

Jos
./script_time_rain.lua

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

Posted: Monday 24 April 2017 23:04
by jvdz
try this command:
lua script_time_rain.lua

Jos

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

Posted: Tuesday 25 April 2017 21:26
by EdwinK
Rain Expected:
Rain Expected:
Screen Shot 2017-04-25 at 21.23.34.png (24.08 KiB) Viewed 2290 times
Guess something is wrong :, because it's really raining outside.

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

Posted: Friday 28 April 2017 9:48
by BarryT
EdKo66 wrote:Screen Shot 2017-04-25 at 21.23.34.pngGuess something is wrong :, because it's really raining outside.
I think its because it is an "rain radar" so it doesnt show the rainfall at the moment, but only in future, like IS it gonna rain in 30 minutes, and if yes how much..
lat & lon correct?
What does the log says?

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

Posted: Friday 28 April 2017 9:58
by BarryT

Code: Select all

commandArray = {}
   minuten=30
btw, here can you change the "radar" time..
now it is giving a warning for the rain in 30 minutes, but you can change this to your needs.

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

Posted: Friday 28 April 2017 10:14
by BarryT
Dropshot wrote:Hi, I would like to make use of this script, only I dont know whether I'm doing it correct. I get this in my log:

Code: Select all

2017-04-23 17:00:00.403 LUA: Regen verwacht: 0 mm binnen 15 minuten.
So the script seems to be working, yet my device (Rain expected) isn't updated. It still says 'Hello World'.. How can I get this working?
did you chmod the txt file? did you have the correct text idx?

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

Posted: Friday 28 April 2017 16:36
by Dropshot
Thanks, I hadn't chmod the file. Now it works!

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

Posted: Friday 28 April 2017 19:14
by EdwinK
BarryT wrote:
EdKo66 wrote:Screen Shot 2017-04-25 at 21.23.34.pngGuess something is wrong :, because it's really raining outside.
I think its because it is an "rain radar" so it doesnt show the rainfall at the moment, but only in future, like IS it gonna rain in 30 minutes, and if yes how much..
lat & lon correct?
What does the log says?

Lat&lon are correct. Have accidentely deleted the logs, so can't tell.

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

Posted: Friday 28 April 2017 21:35
by Siewert308SW
EdKo66 wrote:Screen Shot 2017-04-25 at 21.23.34.pngGuess something is wrong :, because it's really raining outside.
Which script are you using, could pass it here?
In order to see how you set it up.
Because i have the feeling that you have setup the rainfall below 60 while the round number is setup to 1 decimal or less behind the comma.
Meaning the script says "0.003mm rain expected" but your widget gets updated to 0 decimal behind the comma.

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

Posted: Saturday 29 April 2017 19:24
by EdwinK
Siewert308SW wrote:
EdKo66 wrote:Screen Shot 2017-04-25 at 21.23.34.pngGuess something is wrong :, because it's really raining outside.
Which script are you using, could pass it here?
In order to see how you set it up.
Because i have the feeling that you have setup the rainfall below 60 while the round number is setup to 1 decimal or less behind the comma.
Meaning the script says "0.003mm rain expected" but your widget gets updated to 0 decimal behind the comma.
This is the script I'm using

Code: Select all

local RainTextIDX = 113   -- your domoticz text device
debug = false -- enable or disable debug output
tempfilename = '../var/packages/domoticz/scripts/lua/tmp/Rain.tmp' -- be sure this is in the correct map, and give it chmod 0666
totalrain = 0
rainlines = 0

function IsItGonnaRain( minutesinfuture )
   url='http://gpsgadget.buienradar.nl/data/raintext/?lat=51.86&lon=4.41' -- this is important!! change the lat and lon to your needs!!
   if debug then print(url) end
read = os.execute('curl --connect-timeout 5 -s -o '..tempfilename..' "'..url..'"')   file = io.open(tempfilename, "r")

   while true do 
      line = file:read("*line")
      if not line then break end
      if debug then print('Line:'..line) end
      linetime=string.sub(tostring(line), 5, 9)
      if debug then print('Linetime: '..linetime) end

      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 ((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('Rain in timerange: '..rain) end
         if debug then print('Total rain now: '..totalrain) end
      end

   end
   file:close()
   
   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

commandArray = {}
   minuten=15
   RainPrediction = IsItGonnaRain(minuten)
   RainmmHour=10^((RainPrediction-109)/32)

   if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=('('..round(RainmmHour, 1)..' mm) regen verwacht!')
   else 
      verw = 2
      RainPredictionText=('Voorlopig blijft het droog!')
   end
   
   commandArray[2] = {['UpdateDevice'] = RainTextIDX .. '|0|' .. tostring(RainPredictionText)}

return commandArray
At the moment the script is spewing out errors '2017-04-29 19:20:01.901 Error: EventSystem: in Regen Verwacht: [string "local RainTextIDX = 113 -- your domoticz te..."]:13: attempt to index global 'file' (a nil value)', so I stopped it for now.

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

Posted: Saturday 29 April 2017 20:22
by poudenes
Used your script and work great here. Now figure out to change the interval. Want change it so every 10min it will check at buienrader for rain. Now i see lot of loggings:

2017-04-29 20:22:00.297 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.410 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.520 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.674 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.793 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.906 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:01.017 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:12.113 EventSystem: Script event triggered: REGEN 17.04.29

EdKo66 wrote:
Siewert308SW wrote:
EdKo66 wrote:Screen Shot 2017-04-25 at 21.23.34.pngGuess something is wrong :, because it's really raining outside.
Which script are you using, could pass it here?
In order to see how you set it up.
Because i have the feeling that you have setup the rainfall below 60 while the round number is setup to 1 decimal or less behind the comma.
Meaning the script says "0.003mm rain expected" but your widget gets updated to 0 decimal behind the comma.
This is the script I'm using

Code: Select all

local RainTextIDX = 113   -- your domoticz text device
debug = false -- enable or disable debug output
tempfilename = '../var/packages/domoticz/scripts/lua/tmp/Rain.tmp' -- be sure this is in the correct map, and give it chmod 0666
totalrain = 0
rainlines = 0

function IsItGonnaRain( minutesinfuture )
   url='http://gpsgadget.buienradar.nl/data/raintext/?lat=51.86&lon=4.41' -- this is important!! change the lat and lon to your needs!!
   if debug then print(url) end
read = os.execute('curl --connect-timeout 5 -s -o '..tempfilename..' "'..url..'"')   file = io.open(tempfilename, "r")

   while true do 
      line = file:read("*line")
      if not line then break end
      if debug then print('Line:'..line) end
      linetime=string.sub(tostring(line), 5, 9)
      if debug then print('Linetime: '..linetime) end

      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 ((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('Rain in timerange: '..rain) end
         if debug then print('Total rain now: '..totalrain) end
      end

   end
   file:close()
   
   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

commandArray = {}
   minuten=15
   RainPrediction = IsItGonnaRain(minuten)
   RainmmHour=10^((RainPrediction-109)/32)

   if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=('('..round(RainmmHour, 1)..' mm) regen verwacht!')
   else 
      verw = 2
      RainPredictionText=('Voorlopig blijft het droog!')
   end
   
   commandArray[2] = {['UpdateDevice'] = RainTextIDX .. '|0|' .. tostring(RainPredictionText)}

return commandArray
At the moment the script is spewing out errors '2017-04-29 19:20:01.901 Error: EventSystem: in Regen Verwacht: [string "local RainTextIDX = 113 -- your domoticz te..."]:13: attempt to index global 'file' (a nil value)', so I stopped it for now.

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

Posted: Saturday 29 April 2017 20:24
by jvdz
Looks line you have line 11 at the end of line 10... change that to:

Code: Select all

local RainTextIDX = 113   -- your domoticz text device
debug = false -- enable or disable debug output
tempfilename = '../var/packages/domoticz/scripts/lua/tmp/Rain.tmp' -- be sure this is in the correct map, and give it chmod 0666
totalrain = 0
rainlines = 0

function IsItGonnaRain( minutesinfuture )
   url='http://gpsgadget.buienradar.nl/data/raintext/?lat=51.86&lon=4.41' -- this is important!! change the lat and lon to your needs!!
   if debug then print(url) end
   read = os.execute('curl --connect-timeout 5 -s -o '..tempfilename..' "'..url..'"')   
   file = io.open(tempfilename, "r")

   while true do 
      line = file:read("*line")
      if not line then break end
      if debug then print('Line:'..line) end
Jos

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

Posted: Saturday 29 April 2017 21:25
by EdwinK
Thanks. :) Guess I did make some error :)

But still there is this error:

Code: Select all

2017-04-29 21:28:00.219 Error: EventSystem: in Regen Verwacht: [string "local RainTextIDX = '113' -- your domoticz ..."]:17: 'end' expected (to close 'while' at line 13) near
Screen Shot 2017-04-30 at 17.54.09.png
Screen Shot 2017-04-30 at 17.54.09.png (17.69 KiB) Viewed 2157 times

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

Posted: Sunday 30 April 2017 17:19
by poudenes
2017-04-29 20:22:00.297 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.410 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.520 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.674 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.793 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:00.906 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:01.017 EventSystem: Script event triggered: REGEN 17.04.29
2017-04-29 20:22:12.113 EventSystem: Script event triggered: REGEN 17.04.29

Can someone help me with this... the script repeats many times... lots of lines like this for triggering Buitenrader to check if its gonna rain.

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

Posted: Sunday 30 April 2017 19:27
by jvdz
Is this triggered by the Event system? Internal or External files?
Internal -> Check the setting that it is Time in stead of All or Device.
External -> WHat is the script name ? something like script_time_xxx.lua?

jos

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

Posted: Sunday 30 April 2017 22:22
by poudenes
I have it into Domoticz itself. with a name : regen30 17.04.29 as name (Scene year/month/day of creation or modification)