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
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.
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?
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
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.
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?
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
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".
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.
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
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
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.
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
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.