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

Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
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 »

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

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?
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
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

i use all:
ScreenShot010.jpg
ScreenShot010.jpg (41.78 KiB) Viewed 4501 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
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 »

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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

Sorry for my not smart question only scripts is not my thing i believe..

changed to time
Works every minute..

Thanks guys!!!
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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
ScreenShot015.jpg (153.21 KiB) Viewed 4468 times
Raining here: als bakken uit de lucht
Only no switch that says Rain expacted
ScreenShot016.jpg
ScreenShot016.jpg (64.5 KiB) Viewed 4468 times
Then i hope the data is correct:
ScreenShot017.jpg
ScreenShot017.jpg (58.29 KiB) Viewed 4468 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

mmm

Now there is a switch:
ScreenShot018.jpg
ScreenShot018.jpg (98.48 KiB) Viewed 4461 times
Very late...
But there he switched on...

Is there some setting that he can switch faster?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
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 »

(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)
(image from my install, with Dashticz)
Screen Shot 2017-07-29 at 19.54.35.png (27.33 KiB) Viewed 4165 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.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

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

Post 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.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

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

Post by ropske »

For example, you can use:
https://br-gpsgadget-new.azurewebsites. ... 2&lon=3.16

just fill in your latitude and longitude
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post 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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
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 »

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

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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post 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 :lol: 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

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

Post 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 :lol: 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 :lol:
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

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

Post by ropske »

Show me sincze :p
JaapKoppejan
Posts: 6
Joined: Monday 08 February 2016 10:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11590
Contact:

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

Post 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?
Bishop
Posts: 22
Joined: Sunday 11 June 2017 14:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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&param=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&param=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..?
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 »

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

Who is online

Users browsing this forum: No registered users and 1 guest