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.

Moderator: leecollings

poudenes
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?

Post 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.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

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

Post 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?
User avatar
jvdz
Posts: 2189
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?

Post by jvdz »

How are you running this? ( What command did you run?)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Dropshot
Posts: 44
Joined: Tuesday 20 December 2016 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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?
krizzz
Posts: 200
Joined: Wednesday 20 November 2013 20:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

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

Post by krizzz »

jvdz wrote:How are you running this? ( What command did you run?)

Jos
./script_time_rain.lua
User avatar
jvdz
Posts: 2189
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?

Post by jvdz »

try this command:
lua script_time_rain.lua

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
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?

Post by EdwinK »

Rain Expected:
Rain Expected:
Screen Shot 2017-04-25 at 21.23.34.png (24.08 KiB) Viewed 2287 times
Guess something is wrong :, because it's really raining outside.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
BarryT
Posts: 358
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

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

Post 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?
Raspberry / ESP Boards / Relais / Milight / Hue / OTGW / P1 / Xiaomi / RFXCom / RFLink / ZWave / Conbee II / Z2M / MQTT / A lot of scripts and many more..
Software: Linux, Android and Windows
BarryT
Posts: 358
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

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

Post 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.
Raspberry / ESP Boards / Relais / Milight / Hue / OTGW / P1 / Xiaomi / RFXCom / RFLink / ZWave / Conbee II / Z2M / MQTT / A lot of scripts and many more..
Software: Linux, Android and Windows
BarryT
Posts: 358
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

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

Post 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?
Raspberry / ESP Boards / Relais / Milight / Hue / OTGW / P1 / Xiaomi / RFXCom / RFLink / ZWave / Conbee II / Z2M / MQTT / A lot of scripts and many more..
Software: Linux, Android and Windows
Dropshot
Posts: 44
Joined: Tuesday 20 December 2016 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Dropshot »

Thanks, I hadn't chmod the file. Now it works!
User avatar
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?

Post 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.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

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

Post 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.
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
User avatar
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?

Post 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.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
poudenes
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?

Post 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.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
jvdz
Posts: 2189
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?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
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?

Post 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 2154 times
Last edited by EdwinK on Sunday 30 April 2017 17:55, edited 1 time in total.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
poudenes
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?

Post 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.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
jvdz
Posts: 2189
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?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
poudenes
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?

Post 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)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest