Page 12 of 16
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 18:49
by Derik
Dear all. I use the sript from the wiki. [ is this the latest version ? ]
Use the build in Lua script in blockley..
Works fine.
Only 1 thing the script is running every second:
Code: Select all
2017-06-07 18:48:10 Voorlopig blijft het droog!
2017-06-07 18:48:10 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:08 Voorlopig blijft het droog!
2017-06-07 18:48:07 Voorlopig blijft het droog!
2017-06-07 18:48:06 Voorlopig blijft het droog!
2017-06-07 18:48:05 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:01 Voorlopig blijft het droog!
2017-06-07 18:47:58 Voorlopig blijft het droog!
2017-06-07 18:47:57 Voorlopig blijft het droog!
2017-06-07 18:47:56 Voorlopig blijft het droog!
2017-06-07 18:47:56 Voorlopig blijft het droog!
Or more..
Is there a solution for..
Looks not the best option for my Domoticz system..
Is there perhaps a sleep @ the end possible?
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 19:04
by jvdz
So you used the build in editor and probably have selected to act on each event instead of just time events ( every minute)?
It is the dropdown box underneath the Lua selection box.
Jos
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 19:23
by BarryT
Derik wrote:Dear all. I use the sript from the wiki. [ is this the latest version ? ]
Use the build in Lua script in blockley..
Works fine.
Only 1 thing the script is running every second:
Code: Select all
2017-06-07 18:48:10 Voorlopig blijft het droog!
2017-06-07 18:48:10 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:09 Voorlopig blijft het droog!
2017-06-07 18:48:08 Voorlopig blijft het droog!
2017-06-07 18:48:07 Voorlopig blijft het droog!
2017-06-07 18:48:06 Voorlopig blijft het droog!
2017-06-07 18:48:05 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:03 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:02 Voorlopig blijft het droog!
2017-06-07 18:48:01 Voorlopig blijft het droog!
2017-06-07 18:47:58 Voorlopig blijft het droog!
2017-06-07 18:47:57 Voorlopig blijft het droog!
2017-06-07 18:47:56 Voorlopig blijft het droog!
2017-06-07 18:47:56 Voorlopig blijft het droog!
Or more..
Is there a solution for..
Looks not the best option for my Domoticz system..
Is there perhaps a sleep @ the end possible?
Did u use lua as time or device?
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 19:38
by Derik
i use all:
- ScreenShot010.jpg (41.78 KiB) Viewed 4504 times
I do not understand the different s between all this option...
Perhaps someone can ex plane the dombo here
Only the inline lua option looks great because Domoticz save this in the Db, easy for my daily backup
edit:
And what settings do i need for the other script?
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 20:03
by jvdz
Pretty strait forward:
All simply means the script will run on each event.( all below)
Device will be triggered when an Device is updated
Time events will run each minute on the minute
Variable event is triggered when a variable is change.
So, did you change it to Time?
Jos
Re: Is it gonna rain within the next X minutes?
Posted: Wednesday 07 June 2017 20:09
by Derik
Sorry for my not smart question only scripts is not my thing i believe..
changed to time
Works every minute..
Thanks guys!!!
Re: Is it gonna rain within the next X minutes?
Posted: Friday 09 June 2017 10:00
by Derik
mmmm 1 script working ok.The text is changing...
Only the other script the dummy switch is not changing..
Did change the decimals...
set it to time
- ScreenShot015.jpg (153.21 KiB) Viewed 4471 times
Raining here: als bakken uit de lucht
Only no switch that says Rain expacted
- ScreenShot016.jpg (64.5 KiB) Viewed 4471 times
Then i hope the data is correct:
- ScreenShot017.jpg (58.29 KiB) Viewed 4471 times
Now it is raining like ...
Ho do i read the data.
What are the time's where the script is talking about?
It is gonna rain for how long is this warning?
Re: Is it gonna rain within the next X minutes?
Posted: Friday 09 June 2017 10:40
by Derik
mmm
Now there is a switch:
- ScreenShot018.jpg (98.48 KiB) Viewed 4464 times
Very late...
But there he switched on...
Is there some setting that he can switch faster?
Re: Is it gonna rain within the next X minutes?
Posted: Saturday 29 July 2017 20:06
by EdwinK
(I believe the script I use is from this topic)
When it is going to rain it shows the following image
- (image from my install, with Dashticz)
- Screen Shot 2017-07-29 at 19.54.35.png (27.33 KiB) Viewed 4168 times
Now this is clear, it's goingt to be WET!, but what is that number 152 meaning (depending on rain), and often the numbers in the brackets are somewhat like (0.00009), so it doesn't mean very much to me. Is it possible to change this a bit. Such as 'severe rain' to 'very light rain' or such or at least a round figure.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 9:37
by ropske
I dont know where they grab the data from, but i think it is from buienradar. If so, the number 152 will probably be the result of the buienrader widget, please read below to have some more information (its in dutch):
Neerslagdata op basis van coördinaten
Op basis van de door u gewenste coördinaten (latitude en longitude) kunt u de neerslag tot twee uur vooruit ophalen in tekstvorm. De data wordt iedere 5 minuten geüpdatet. Op deze pagina kunt u de neerslag in tekst vinden. De waarde 0 geeft geen neerslag aan (droog), de waarde 255 geeft zware neerslag aan. Gebruik de volgende formule voor het omrekenen naar de neerslagintensiteit in de eenheid millimeter per uur (mm/u):
Neerslagintensiteit = 10^((waarde-109)/32)
Ter controle: een waarde van 77 is gelijk aan een neerslagintensiteit van 0,1 mm/u.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 9:38
by ropske
For example, you can use:
https://br-gpsgadget-new.azurewebsites. ... 2&lon=3.16
just fill in your latitude and longitude
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 9:57
by Derik
Dear scriptwriter...? ,,,
In this script is a write to log option.
I heard from gizmocuz that this script is write something to my log every 4-5 seconds!!!
Is this correct?
Is it possible to remove this part?
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 10:04
by EdwinK
ropske wrote:I dont know where they grab the data from, but i think it is from buienradar. If so, the number 152 will probably be the result of the buienrader widget, please read below to have some more information (its in dutch):
Neerslagdata op basis van coördinaten
Op basis van de door u gewenste coördinaten (latitude en longitude) kunt u de neerslag tot twee uur vooruit ophalen in tekstvorm. De data wordt iedere 5 minuten geüpdatet. Op deze pagina kunt u de neerslag in tekst vinden. De waarde 0 geeft geen neerslag aan (droog), de waarde 255 geeft zware neerslag aan. Gebruik de volgende formule voor het omrekenen naar de neerslagintensiteit in de eenheid millimeter per uur (mm/u):
Neerslagintensiteit = 10^((waarde-109)/32)
Ter controle: een waarde van 77 is gelijk aan een neerslagintensiteit van 0,1 mm/u.
Thanks. Yes, the data comes from buienradar. Will read the link.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 10:09
by jvdz
EdKo66 wrote:
Now this is clear, it's goingt to be WET!, but what is that number 152 meaning (depending on rain), and often the numbers in the brackets are somewhat like (0.00009), so it doesn't mean very much to me. Is it possible to change this a bit. Such as 'severe rain' to 'very light rain' or such or at least a round figure.
This is described in the initial post of this thread.
Derik wrote:Dear scriptwriter...? ,,,
In this script is a write to log option.
I heard from gizmocuz that this script is write something to my log every 4-5 seconds!!!
Is this correct?
Is it possible to remove this part?
Huh? Have you looked at the script at all? It retrieved the JSON info from Buienradar which is written to a file when ran and only make domoticz log entries when debug is set.
I am running a similar LUA script based on this code that is ran by CRONTAB as I don't want any script ran by the Domoticz event system that could potentially hold it up for few seconds.
Jos
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 11:34
by sincze
jvdz wrote:
I am running a similar LUA script based on this code that is ran by CRONTAB as I don't want any script ran by the Domoticz event system that could potentially hold it up for few seconds.
Jos
I totally agree with you on "I don't want any script ran by the Domoticz event system that could potentially hold it up for few seconds." It caused serious issues with other events.
I moved away from the internal event handling and rewrote this 'Buienradar' in php
with the usage of Pass2PHP described on the forum as well. Have to say it works pretty nice. It has been raining quite a lot these days and the screens moved to a safe position thanks to this idea. And the Buienradar API ofcourse.
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 30 July 2017 12:03
by ropske
sincze wrote:jvdz wrote:
I am running a similar LUA script based on this code that is ran by CRONTAB as I don't want any script ran by the Domoticz event system that could potentially hold it up for few seconds.
Jos
I totally agree with you on "I don't want any script ran by the Domoticz event system that could potentially hold it up for few seconds." It caused serious issues with other events.
I moved away from the internal event handling and rewrote this 'Buienradar' in php
with the usage of Pass2PHP described on the forum as well. Have to say it works pretty nice. It has been raining quite a lot these days and the screens moved to a safe position thanks to this idea. And the Buienradar API ofcourse.
In PHP? Hmm, sounds familiar
Re: Is it gonna rain within the next X minutes?
Posted: Tuesday 08 August 2017 18:17
by ropske
Show me sincze :p
Re: Is it gonna rain within the next X minutes?
Posted: Thursday 31 August 2017 15:55
by JaapKoppejan
I wonder if the result in mm/hour is correctly calculated now in the script. The reason for my doubt is the non-linear relation between the variable ' Rain' (as the result of the function ' IsItGonnaRain') and the conversion to mm/hour in the formula [mm/h] = 10^(([rain]-109)/32).
Because of this non-linearity, there is a difference in result if we first take the average of the 'rainlines' in the function ' IsItGonnaRain' and then do the conversion to mm/h (as it is now implemented), or (alternatively) first convert a rainline to mm/h and then take the average.
Personally I would expect that the latter approach would provide more accurate results. Is there any documentation available on the buienradar gadget that provides background information?
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 03 September 2017 14:39
by Bishop
jvdz wrote: ↑Saturday 13 May 2017 17:10
HansieNL wrote:
Interesting... are you willing to share your script?
Of course: This is the script I have and it feed both a Rain and a percentage device. In case you don't want the percentage chance of rain device you need to remove the code at the bottom of the lua which tries to update that.
The filename and crontab task are listed in the source.
Just update the information in the top part and check if you want both devices to be fed with information.
Jos
Code: Select all
-------------------------------------------------------------------
--- Get rain info from buienradar for the next xx minutes
---
--- Crontab task: */5 * * * * sudo lua /home/pi/domoticz/scripts/buienradar_rainprediction.lua >> /var/tmp/BRP.log
-- config ---------------------------------------------------------
lat='5?.??'
lon='4.??'
-- use information for the next xx minutes
minutesinfuture=15
-- Domoticz server url
domoticzurl="http://192.168.0.??:8080"
-- rain device
DEVIDX=???
-- General Percentage device
PDEVIDX=???
-- set to true or false
debug=true
-- set to the appropriate tmp path
tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable
-- config ---------------------------------------------------------
-- http://gadgets.buienradar.nl/data/raintext?lat=5?.??&lon=4.??
--
-- url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon -- old link
url='http://gadgets.buienradar.nl/data/raintext?lat='..lat..'&lon='..lon
if debug then print(url) end
read = os.execute('curl -Lo '..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
linetime=string.sub(tostring(line), 5, 9)
-- 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 >= 20) and (difference<=minutesinfuture*60)) then
rain=tonumber(string.sub(tostring(line), 0, 3))
totalrain = totalrain+rain
rainlines=rainlines+1
if debug then print('Rain in timerange: '..rain .. ' Total rain now: '..totalrain .. ' difference:' .. difference .. ' Line:' ..line ) 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) (example: 77 = 0.1 mm/hour)
if rainlines == 0 then
averagerain=0
else
averagerain=math.ceil(totalrain/rainlines)
end
function round(num, idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
-- Calculate the mm/h
calcmmh = round(10^((averagerain -109)/32),2)
if debug then print(os.date() .. " averagerain:" .. averagerain .. " calcmmh:" .. calcmmh) end
-- Update Domotics Devices
url=domoticzurl..'/json.htm?type=command¶m=udevice&idx=' .. DEVIDX .. '&nvalue=0&svalue=' .. calcmmh .. ';' .. calcmmh
if debug then print(url) end
read = os.execute('curl -s "'..url..'"')
if debug then print(read) end
-- Update percentage regenkans Domotics Device ---------------
result = round(averagerain*0.392156862745098,2)
url=domoticzurl..'/json.htm?type=command¶m=udevice&idx=' .. PDEVIDX .. '&nvalue=0&svalue=' .. result
if debug then print(url) end
read = os.execute('curl -s "'..url..'"')
if debug then print(read) end
if debug then print('==> Rain chance: '..result .. '%') end
-- end update percentage device -------------------------------------
if debug then print('------------------------------------------------------------------------------------------------------------------------------------------') end
Hey
I've been using your script for a while now. Works perfectly.
It's currently running as a cronjob. I would like to have it added to the Domoticz Event system as a dzVents script. The main reason for this is that in that case the Domoticz automatic backup and my manual backup of the database file will include these scripts. And, as I understand, dzVents is more resource-friendly. Is this possible or..?
Re: Is it gonna rain within the next X minutes?
Posted: Sunday 03 September 2017 20:31
by jvdz
I wouldn't do it as the event system is single threaded, although I am not sure how Dzvents is implemented, but it could make other tasks less responsive when at the same time the Rain information is being picked-up.
Not sure I understand the Domoticz automatic backup argument as I though that only takes care of the domoticz.db, the actual data for Domoticz?
Jos