buienradar lua script
Moderator: leecollings
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
I have no idea what those 2 values exactly do as I am using my own LUA scripts for both the Rain prediction (posted somewhere in this thread) and a separate script for the weather predictions, where I filter out the information I need and put that in Domoticz for processing.
This is running for a couple of years already, when this integrated hardware wasn't there yet.
I have separate scripts as they point to different Buienradar websites and the rain prediction runs every 5 minutes and the weather forecast runs every 10 minutes.
Jos
This is running for a couple of years already, when this integrated hardware wasn't there yet.
I have separate scripts as they point to different Buienradar websites and the rain prediction runs every 5 minutes and the weather forecast runs every 10 minutes.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 40
- Joined: Wednesday 10 June 2020 9:20
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: buienradar lua script
okay, i will take a look.
I thought it should be simple, but the wind-sensor gives an output like: 225.00;SW;79;114;15.2;15.2
So i guess the windage (in this example it was 11.4 m/s) is given as : 114.
So its not very simple i guess : )
But always nice to learn, the rain LUA word perfectly!
What i do see:
You can go to 'notifications' on the sensor. there its possible to get an notification (for example en e-mail) when the windage is above X m/s.
Thats a start
What i shall try:
Als 'notification' type i choose: HTTP
And the als HTTP i give the command for the screen; hopefully it works
Will test it now
EDIT:
Via http it doesn't work within the notification setting.
I see i am not the only one : (https://www.domoticz.com/forum/viewtopic.php?t=6828 )
On a rainy day with lots of time i will try to test other options, if anyone has an working 'windage' script thats always welcome
I thought it should be simple, but the wind-sensor gives an output like: 225.00;SW;79;114;15.2;15.2
So i guess the windage (in this example it was 11.4 m/s) is given as : 114.
So its not very simple i guess : )
But always nice to learn, the rain LUA word perfectly!
What i do see:
You can go to 'notifications' on the sensor. there its possible to get an notification (for example en e-mail) when the windage is above X m/s.
Thats a start
What i shall try:
Als 'notification' type i choose: HTTP
And the als HTTP i give the command for the screen; hopefully it works
Will test it now
EDIT:
Via http it doesn't work within the notification setting.
I see i am not the only one : (https://www.domoticz.com/forum/viewtopic.php?t=6828 )
On a rainy day with lots of time i will try to test other options, if anyone has an working 'windage' script thats always welcome
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
I gave the formula already for that a few posts ago!
jvdz wrote: ↑Monday 29 June 2020 10:03 As you can see, there is also a Wind sensor there and you can use that data to retrieve the windspeed and windgustspeed :Code: Select all
sDirectionDegrees, sDirection, sSpeed, sGust, sTemperature, sFeel = otherdevices_svalues['Wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
So you can very simply test on either the variable sSpeed or sGust depending which value you find important.
Something like this to get you started?:
Code: Select all
commandArray = {}
-- only check windspeed when Wind info is updated
if devicechanged['Wind'] then
sDirectionDegrees, sDirection, sSpeed, sGust, sTemperature, sFeel = otherdevices_svalues['Wind']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
-- check whether the sunscreen is "out"
if (otherdevices['Sunscreen'] == 'Open') then
-- send warning when speed is over 60km
if sSpeed < 60 then
print('Windsnelheid hoger dan 60 km en Sunscreen is open.')
end
end
end
return commandArray
Last edited by jvdz on Monday 29 June 2020 14:47, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 40
- Joined: Wednesday 10 June 2020 9:20
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: buienradar lua script
Oepsie...thanks!
I will try to make it work !
-
- Posts: 40
- Joined: Wednesday 10 June 2020 9:20
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: buienradar lua script
Managed by doing this: https://www.domoticz.com/forum/viewtopic.php?t=28163
A blockly with:
IF > WIND > 10 AND Sunscreen = Open
Do: Close Sunscreen
Now looking for the best setting; i don't know if it takes the peak ('windvlaag') or the everage windspeed (snelheid in m/s)
Edit:
It looks like its taking the peaks, thats fine.
There are peaks with 15m/sec here wright now, and when i play with the parameters i can see the screens doesn't even goes out because of the wind.
Perfect
A blockly with:
IF > WIND > 10 AND Sunscreen = Open
Do: Close Sunscreen
Now looking for the best setting; i don't know if it takes the peak ('windvlaag') or the everage windspeed (snelheid in m/s)
Edit:
It looks like its taking the peaks, thats fine.
There are peaks with 15m/sec here wright now, and when i play with the parameters i can see the screens doesn't even goes out because of the wind.
Perfect
-
- Posts: 82
- Joined: Tuesday 04 February 2020 11:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: buienradar lua script
Anybody else having issues with the LUA script recently?
Seems like the output from buienradar has changed.
Seems like the output from buienradar has changed.
Code: Select all
077|17:15
077|17:20
86,6329598612474|17:25
86,6329598612474|17:30
077|17:35
077|17:40
86,6329598612474|17:45
86,6329598612474|17:50
92,2678801510292|17:55
99,3670401387526|18:00
112,64618727381878|18:05
112,64618727381878|18:10
105,8988795837422|18:15
111,53379987352399|18:20
112,64618727381878|18:25
105,8988795837422|18:30
118,6329598612474|18:35
123,30905700295102|18:40
129,590485647558|18:45
131,3670401387526|18:50
131,3670401387526|18:55
118,6329598612474|19:00
112,64618727381878|19:05
105,8988795837422|19:10
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
yep... I changed my version to this to t=get the rain and time variables filled now :
Jos
Code: Select all
while true do
line = file:read("*line")
if not line then break end
rain,linetime = line:match("(%d+).-|(.+)%s?")
rain = tonumber(rain) or 0
linetime = linetime or "00:00"
linetime = linetime:gsub("[\r\n]","")
if debug then print('Rain in timerange: '..rain .. ' linetime:'..linetime..' Line:' ..line ) end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 82
- Joined: Tuesday 04 February 2020 11:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: buienradar lua script
Hi Jos,jvdz wrote: ↑Friday 02 October 2020 18:05 yep... I changed my version to this to t=get the rain and time variables filled now :JosCode: Select all
while true do line = file:read("*line") if not line then break end rain,linetime = line:match("(%d+).-|(.+)%s?") rain = tonumber(rain) or 0 linetime = linetime or "00:00" linetime = linetime:gsub("[\r\n]","") if debug then print('Rain in timerange: '..rain .. ' linetime:'..linetime..' Line:' ..line ) end
Thanks for your help. I'm not experienced in scripting, so I have no clue where to change this. Can you post your full script and if possible in Dutch?
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
Just Email me your script and I will have a look as it could very well be you are using a totally different version.
My email address can be found in my github account details.
Jos
ps: .. and in Dutch is fine too.
My email address can be found in my github account details.
Jos
ps: .. and in Dutch is fine too.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 82
- Joined: Tuesday 04 February 2020 11:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Location: The Netherlands
- Contact:
Re: buienradar lua script
Thanks to @jvdz it's working again.
Change this line in the script from
to
Thanks Jos!
Change this line in the script from
Code: Select all
for k,v in tmp:gmatch('(.-)|(.-)\r?\n') do
Code: Select all
for k,v in tmp:gmatch('(%d+).-|(.-)\r?\n') do
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
You're welcome. It actually simply takes the numeric part up to the comma and skips the rest as they change the values for rain|time from:
to
.. but we really do not need the part behind the comma (which is use in the Netherlands as Decimal sign).
The other option would to replace the comma for a decimal point in the string value before converting to a number.
Jos
Code: Select all
123|10:00
Code: Select all
123,456789|10:00
The other option would to replace the comma for a decimal point in the string value before converting to a number.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- HansieNL
- Posts: 957
- Joined: Monday 28 September 2015 15:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: buienradar lua script
Can you help me to change my lua script so it will work with the decimal point? Thanks in advance.
Code: Select all
-- script_time_buienradar.lua
--
-- BuienRadar Module
--
-- curl in os required!!
-- create dummy text device from dummy hardware 'Buien Radar'
-- create dummy rain sensor from dummy hardware 'BuienRadarMeter'
-- create dummy switch from dummy hardware for triggering screens etc based on rain
-- add as time based lua script
-- set your longitude & latitude below!
--
-- 2017-12-27 working version
-- 2017-12-28 trying to get the rain device working .. missing documentation ..
-- 2017-12-30 isolated the bug, i was overwriting the updatedevice .. should be ok now
-- 2018-03-28 updated buienradar url
-- 2018-04-02 added follow redirect for curl & fixed typo as tipped by gizmocuz
--
commandArray = {}
local myBuienRadarDevice = 'Buienradar'
local myBuienRadarMeter = 'RegenData'
local myBuienRadarFlg = 'Paraplu'
-- longitude latitude
local lat='51.00'
local lon='3.00'
time = os.date("*t")
if time.min % 5 == 0 then
print('(Buienradar) Get data from Buienradar')
function os.capture(cmd, rep) -- execute command to get site
-- rep is nr of repeats if result is empty
r = rep or 1
local s = ""
while ( s == "" and r > 0) do
r = r-1
local f = assert(io.popen(cmd, 'r'))
s = assert(f:read('*a'))
f:close()
end
if ( rep - r > 1 ) then
print("(Buienradar) os.capture needed more than 1 call: " .. rep-r)
end
return s
end
-- get data from buienradar
-- local command = "curl --max-time 3 -L -s 'https://gpsgadget.buienradar.nl/data/raintext?lat=" .. lat .. "&lon=" .. lon .. "'" -- timeout 3 secs
local command = "curl --max-time 3 -L -s 'https://gps.buienradar.nl/getrr.php?lat=" .. lat .. "&lon=" .. lon .. "'" -- timeout 3 secs
-- print("command: " .. command)
local tmp = os.capture(command, 3) -- nr of repetitions 3
-- print('buienRadar data:\n' .. tmp)
if ( tmp == "" ) then
print("(BuienRadar) Empty result from curl command")
else
-- analyse data
-- to mm/h 10^((waarde-109)/32)
function tomm(r)
return 10^((r-109)/32)
end
-- to string formatted
function tos(r, c)
c = c or 1
return string.format("%." .. c .. "f", r)
end
local c=0
local rainNow=0
local rainNowAvg = 0
local rainSoon = 0
local rainTime = ""
local rainMax = 0
for k,v in tmp:gmatch('(.-)|(.-)\r?\n') do -- k is rain value, v is time
kn = tonumber(k)
if c<=1 then
if rainNow < kn then
rainNow = kn
end
if kn > 0 then
rainNowAvg = rainNowAvg + tomm(kn)/2
end
end
if c<=3 and rainSoon < kn then
rainSoon = kn
end
if rainTime == "" and kn > 0 then
rainTime = v
end
if kn > rainMax then
rainMax = kn
end
c = c+1
end
-- if c = 0 no data found!
if ( c == 0 ) then
print("(BuienRadar) Unparsable result from curl command")
else
if rainNow>0 then
tmp = "Nu " .. tos(tomm(rainNow)) .. " mm/uur"
if rainMax > rainNow then
tmp = tmp .. " tot " .. tos(tomm(rainMax)) .. " mm/uur"
end
elseif rainSoon>0 then
tmp = "Verwacht " .. tos(tomm(rainSoon)) .. " mm/uur"
if rainMax > rainSoon then
tmp = tmp .. " tot " .. tos(tomm(rainMax)) .. " mm/uur"
end
elseif rainTime ~= "" then
tmp = "Verwacht om " .. rainTime .. " tot " .. tos(tomm(rainMax)) .. " mm/uur"
else tmp = "Voorlopig droog"
end
-- calculate totalrainfall using rainNowAvg as average of 2 next reports
-- print("buienRadarMeterOld: " .. otherdevices_svalues[myBuienRadarMeter])
local rainTot = tonumber(otherdevices_svalues[myBuienRadarMeter]:match("[^;]+;([^;]+)")) + rainNowAvg/12 -- /12 to acount for 5min measurements ?? ..
-- print("buienRadarDebug: rainNow=" .. tos(tomm(rainNow)) .. " rainNowAvg=" .. tos(rainNowAvg) .. " rainSoon=" ..
-- tos(tomm(rainSoon)) .. " rainTot=" .. tos(rainTot,2) .. " rainTime=" .. rainTime .. " rainMax=" .. tos(tomm(rainMax)))
local cmd = otherdevices_idx[myBuienRadarMeter] .. "|0|" .. tos(tomm(rainNow)*100,0) .. ";" .. tos(rainTot,2)
-- print("buienRadar: " .. cmd)
table.insert(commandArray, { ['UpdateDevice'] = cmd } ) -- table.insert needed to avoid overwriting with next updatedevice
-- write to text device
if otherdevices[myBuienRadarDevice] ~= tmp then
table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[myBuienRadarDevice] .. '|0|' .. tmp })
-- trigger based when rainNow or rainSoon
if ( rainNow>0 or rainSoon>0 ) then
if otherdevices[myBuienRadarFlg] == "Off" then
commandArray[myBuienRadarFlg] = "On"
end
elseif otherdevices[myBuienRadarFlg] == "On" then
commandArray[myBuienRadarFlg] = "Off"
end
end
end -- unparsable
end -- empty result
end
return commandArray
Blah blah blah
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
I see you didn't change line 80 yet as suggested as fix a couple of posts ago or you do you like to see the other solution?
Maybe this script helps to explain the issue .... just save this is a test.lua file and run this with lua from the commandline:
Jos
Maybe this script helps to explain the issue .... just save this is a test.lua file and run this with lua from the commandline:
Code: Select all
tmp = "123,456789|10:00\r\n"
print("-- the original issue after buienradar changed the value to include decimals using a ,")
for k,v in tmp:gmatch('(.-)|(.-)\r?\n') do
print("Data:",k,v)
kn = tonumber(k)
print("Result:",kn,v)
end
print("")
print("-- proposed fix in regex")
for k,v in tmp:gmatch('(%d+).-|(.-)\r?\n') do
print("Data:",k,v)
kn = tonumber(k)
print("Result:",kn,v)
end
print("")
print("-- the second option replace , with .")
for k,v in tmp:gmatch('(.-)|(.-)\r?\n') do
print("Data:",k,v)
k = k:gsub(",",".")
kn = tonumber(k)
print("Result:",kn,v)
end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- HansieNL
- Posts: 957
- Joined: Monday 28 September 2015 15:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: buienradar lua script
@jvdz Runned your LUA script and it makes clear what's happening with the comma.
I would like to see the other solution (replace the comma for a decimal point).
If you have time can you show that solution?
Thanks in advance.
I would like to see the other solution (replace the comma for a decimal point).
If you have time can you show that solution?
Thanks in advance.
Blah blah blah
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
Mmm ... that one is in that script too ... in the last part
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- HansieNL
- Posts: 957
- Joined: Monday 28 September 2015 15:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: buienradar lua script
Ok. I hope that I understand it well
Code: Select all
...
for k,v in tmp:gmatch('(.-)|(.-)\r?\n') do -- k is rain value, v is time
k = k:gsub(",",".") -- replace the comma for a decimal point
kn = tonumber(k)
...
Blah blah blah
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: buienradar lua script
Correct..
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Who is online
Users browsing this forum: No registered users and 1 guest