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