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

Post Reply
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

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

Post by Egregius »

Didn't you use shell for all of this? :o
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.
schulpr
Posts: 137
Joined: Thursday 01 January 2015 9:10
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

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

Post 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
User avatar
bizziebis
Posts: 182
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8805
Location: The Netherlands
Contact:

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

Post 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.
Hansbit
Posts: 36
Joined: Monday 17 February 2014 15:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Hansbit »

Buienradar.nl changed their url!

So change your URL= line to:
url='http://gadgets.buienradar.nl/data/raint ... lon='..lon
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 »

Hansbit wrote:Buienradar.nl changed their url!

So change your URL= line to:
url='http://gadgets.buienradar.nl/data/raint ... lon='..lon
Great!
I was wondering why it keeps saying a nan value.. :-)

Thanks Hans!
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
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

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

Post 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.
User avatar
Bartb
Posts: 17
Joined: Monday 29 August 2016 22:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

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

Post 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?
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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
User avatar
Bartb
Posts: 17
Joined: Monday 29 August 2016 22:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

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

Post 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.
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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 ;)
User avatar
Bartb
Posts: 17
Joined: Monday 29 August 2016 22:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

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

Post 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.
User avatar
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?

Post by Brutus »

Hansbit wrote:Buienradar.nl changed their url!

So change your URL= line to:
url='http://gadgets.buienradar.nl/data/raint ... lon='..lon
Thnx for this. I was also wondering why my screen script with buienradar wasn't working anymore.

Greetings Brutus.
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
TinusExcentricus
Posts: 16
Joined: Friday 16 October 2015 16:06
Target OS: Linux
Domoticz version: 2023.1
Location: The Netherlands
Contact:

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

Post 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
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 »

Have you read the post above your post? There is a clue in there! ;)
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
TinusExcentricus
Posts: 16
Joined: Friday 16 October 2015 16:06
Target OS: Linux
Domoticz version: 2023.1
Location: The Netherlands
Contact:

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

Post 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.
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 »

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?
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
marmachine
Posts: 128
Joined: Saturday 26 March 2016 10:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

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

Post 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.
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 »

Good Job marmachine..
How did you do that splitting up ?
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
Post Reply

Who is online

Users browsing this forum: Eugene, heiko and 1 guest