Page 6 of 16
Re: Is it gonna rain within the next X minutes?
Posted: Friday 02 September 2016 9:15
by marmachine
renerene wrote:marmachine wrote:I think that the problem is that you are NOT using the CURL from my script
Yes, you are right. The 'Lo' option in the Curl command did the trick. Everything working now, thank you!
I still can not see the rain.tmp file in the file system. And now I understand why: because it is placed on a ramdrive and my MobaXterm shows the SC-card content
[edit]: not sure about this last one; rain.tmp is now showing in MobaXterm with ramdrive. Maybe becase of re-connction or my mistake (looking in the wrong folder)
Good for you!
Now in case anyone wonders... the tmp file could go anywhere, just make sure that you have permissions set on the file and that full file path (directory) exists!
The situation regarding the CURL issue is related to the option in CURL, i struggled the same issue and with some help i found out that buienradar is redirecting. Adding the "L" option to the CURL request allows to follow the redirect instead of catching the result of the original URL. (This isn't in the original script)
So basically, you can copy my version and use that.
You only need to set the parameters at the top of the file and check the filepath on your system for the tmp file
Cheers
Re: Is it gonna rain within the next X minutes?
Posted: Friday 02 September 2016 12:34
by Egregius
Didn't you use shell for all of this?
How did you check permissions, ownership etc?
The -Lo option is just to follow the 301 redirect, if you use the new url you didn't needed that.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 04 September 2016 8:38
by schulpr
Hi,
For some reason I don't understand the script is running 6 a 7 times in each of the five minutes it should run once. Any ideas how this can happen or better, be prevented?
Regards, Rob
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 04 September 2016 9:11
by bizziebis
Did you save the script as a Device script instead of a Time script?
Time scripts will fire each minute once. Device scripts will fire each device change. So it easilly can be 6/7 times a minute.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 04 September 2016 10:19
by Hansbit
Buienradar.nl changed their url!
So change your URL= line to:
url='
http://gadgets.buienradar.nl/data/raint ... lon='..lon
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 04 September 2016 15:35
by BarryT
Great!
I was wondering why it keeps saying a nan value..
Thanks Hans!
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 8:50
by marmachine
Folks,
You are right, Buienradar.nl has changed their url!For their response that is!
Their documentation still points to the original url, so i've decided to stick with that! (so what if they will redirect somewhere else tomorrow?)
Look up their documentation
here
The key thing is that i added the "L" option to the CURL in order to follow the redirect (in case there is one).
Follow facts instead of other lost creatures
Cheers
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 9:00
by Egregius
I think they just forgot to alter the link to the text data.
All the iframes under that are pointing to gadgets.buienradar.
Anyway, a http 301 response means 'Moved Permanently'. So they 'normally' aren't changing it back to gps.buienradar.
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 10:08
by Bartb
Lua script "IsItGonnaRain" (30-08-2016 v1.2) works nicely for me. Now, the script 'fills' a text-switch with the text like for example "Geen regen verwacht binnen komende 5 minuten"
What I would prefer is to create an additional ON/OFF switch that simply switches ON when rain is expected (like in the next 5 minutes) and switched off when no rain is expected (in the next 5 minutes, or whatever timeframe is configered).
I tried to configure that by creating a ON/OFF virtual switch in Domoticz and simply putting the idx number of the ON/OFF virtual switch in the config ([idxRegenmmUur]), as well as giving the [rainswitchname] the same name as the virtual switch in domoticz.
To be honest I do not think this will work as it will now fill the ON/OFF switch with text but as it had not rained since I'm not sure what will really happen...
Can anyone suggest a right / better way to achieve this?
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 10:19
by marmachine
Bartb wrote:Lua script "IsItGonnaRain" (30-08-2016 v1.2) works nicely for me. Now, the script 'fills' a text-switch with the text like for example "Geen regen verwacht binnen komende 5 minuten"
What I would prefer is to create an additional ON/OFF switch that simply switches ON when rain is expected (like in the next 5 minutes) and switched off when no rain is expected (in the next 5 minutes, or whatever timeframe is configered).
I tried to configure that by creating a ON/OFF virtual switch in Domoticz and simply putting the idx number of the ON/OFF virtual switch in the config ([idxRegenmmUur]), as well as giving the [rainswitchname] the same name as the virtual switch in domoticz.
To be honest I do not think this will work as it will now fill the ON/OFF switch with text but as it had not rained since I'm not sure what will really happen...
Can anyone suggest a right / better way to achieve this?
on lines 54 - 55 i do the trick... my switch is named "Regen verwacht" and switches on above value of switchthreshold (70) as set on line 53
Code: Select all
-- Rain switch (ON when rain above threshold, else OFF)
local rainswitchname = "Regen verwacht" -- (str) name for switch to toggle
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 10:56
by Bartb
Ok.
I have that as well as an extra switch, but as I mentioned I also set the idx number "idxRegenmmUur" value to the same on/off switch, which I guess cannot be correct.
I will now change that back to the text switch, hoping that both switches will now work; One switching On/Off when it Rains/Dry, and the other always showing a text like eq. "Geen regen verwacht binnen komende 5 minuten".
Now... let it rain...
thanks.
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 12:39
by marmachine
Bartb wrote:Ok.
I have that as well as an extra switch, but as I mentioned I also set the idx number "idxRegenmmUur" value to the same on/off switch, which I guess cannot be correct.
I will now change that back to the text switch, hoping that both switches will now work; One switching On/Off when it Rains/Dry, and the other always showing a text like eq. "Geen regen verwacht binnen komende 5 minuten".
Now... let it rain...
thanks.
Well there's an inconsistancy there... to target the virtual devices; for 'switch' i used it's NAME and for the 'text' i have used IDX...
Ofcourse these can and should
not relate to the same virtual device since one toggles ON/OFF and the other display's text.
However, i think you figured that one out already
Re: Is it gonna rain within the next X minutes?
Posted: Monday 05 September 2016 13:27
by Bartb
Yep, I did. thanks.
Also looked into the coding myself a bit more and indeed only conclusion is that a switch can be addressed by idx or name.
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 September 2016 23:14
by Brutus
Thnx for this. I was also wondering why my screen script with buienradar wasn't working anymore.
Greetings Brutus.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 11 September 2016 8:26
by TinusExcentricus
My script doesn't seem to work anymore. I'm not aware of any changes I've made. Things go wrong because variable
rain seems to have a value of
-nan.
Any clues anyone?
Cheers, Tinus
Code: Select all
2016-09-11 08:20:00.297 LUA: interval_min: 1
2016-09-11 08:20:00.297 LUA: minutes: 5
2016-09-11 08:20:00.297 LUA: threshold: 0.2
2016-09-11 08:20:00.297 LUA: rain: -nan
2016-09-11 08:20:00.297 LUA: rainavg: -nan
2016-09-11 08:20:00.297 Error: EventSystem: ../domoticz/scripts/lua/script_time_rain.lua:88: attempt to concatenate global 'rainmmh' (a nil value)
Code: Select all
function IsItGonnaRain( minutesinfuture )
-- config ---------------------------------------------------------
lat='52.0842083' -- lat/lon of your location
lon='5.0474724'
-- http://gps.buienradar.nl/getrr.php?lat=52.0842083&lon=5.0474724
debug=false
tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable
-- /config ---------------------------------------------------------
url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon
if debug then print(url) end
read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
file = io.open(tempfilename, "r")
totalrain=0
rainlines=0
-- now analyse the received lines, format is like 000|15:30 per line.
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 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(linetime,1,2), min=string.sub(linetime,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 totalize the rainfall
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()
-- 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)
averagerain=totalrain/rainlines
return(averagerain)
end
-- function to round mm/h output
function round(num, idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
-- RAIN ACTION SCRIPT
commandArray = {}
-- time variables
interval_min = 5
time = os.date("*t")
if ((time.min % interval_min)==0) then
----- rain variables ------
minutes=5 -- minimum value=5
threshold=0.20
----- rain calculations ------
rain = IsItGonnaRain(minutes)
rainavg = 10^((rain-109)/32)
rainmmh = round(rainavg, 2)
print('interval_min: '..interval_min)
print('minutes: '..minutes)
print('threshold: '..threshold)
print('rain: '..rain)
print('rainavg: '..rainavg)
print('rainmmh: '..rainmmh)
----- rain actions ------
if rainmmh > threshold then
-- if (otherdevices['Luifel Patio'] ~= 'Open') then
print(rainmmh..' mm/h rain expected in '..minutes..' minutes → switch canopy off!')
commandArray['Luifel Patio']='Off'
-- else
-- print(rainmmh..' mm/h rain expected in '..minutes..' minutes, canopy is already off → all clear and dry!')
--end
else
print(rainmmh..' mm/h rain expected in '..minutes..' minute(s).')
end
end
return commandArray
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 11 September 2016 8:37
by jvdz
Have you read the post above your post? There is a clue in there!
Jos
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 11 September 2016 9:06
by TinusExcentricus
Ah, so sorry Jos! Thanks for your swift reply.
I checked the old url from my script by copying into my webbrowser, but didn't notice it was automatically redirected/rewritten there to a new subdomain. Working perfectly again.
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 27 September 2016 9:24
by BarryT
2016-09-27 09:18:10.161 Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_time_rain.lua has been running for more than 10 seconds
2016-09-27 09:19:10.271 Error: EventSystem: Warning!, lua script /home/pi/domoticz/scripts/lua/script_time_rain.lua has been running for more than 10 seconds
And it will keep giving the error messages..
I have changed the url..
Is it possible to change the timeout of the (lua) scripts?
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 27 September 2016 14:01
by marmachine
Hi Barry,
That same issue has happened to me when i tried expanding my scripts with more logic and actions.
Unfortunately time is limited for each triggered script, otherwise it might not have finnished before it's triggered again huh...
Maybe you can try to split things up... like getting data and doing something with the data in two seperate scripts.
Like for weatherdata and the (buienradar) raindata i save to a file and update those files every 5 minutes during the day, in another script i update devices and stuff by simply reading and processing the data from that local file. Anyway, that is my workaround in theory.
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 27 September 2016 16:30
by BarryT
Good Job marmachine..
How did you do that splitting up ?