Yeah pleasemarkk wrote:Hi Tlpetertlpeter wrote:Hi Hans i know, that is the problem![]()
I use a different script now and i have it working.
But thanks anyway.
Would you mind sharing your windows script please?
Thanks
Mark

Moderator: leecollings
Yeah pleasemarkk wrote:Hi Tlpetertlpeter wrote:Hi Hans i know, that is the problem![]()
I use a different script now and i have it working.
But thanks anyway.
Would you mind sharing your windows script please?
Thanks
Mark
Code: Select all
-----------------------------------------------------------------------------
-- LUA Script
-- Extract values from Weather Underground device and 'Buienradar'-rain
-- prediction to control the sunscreen
-- Auteur: Luuc_A
-- Datum : 29-05-2014
-----------------------------------------------------------------------------
-- Setup uservariables:
-- 1) Weather_Debug = String = True / False
-- 2) Weather_WindSpeedThreshold = integer
-- 3) Weather_WindGustThreshold = integer
-- 4) Weather_RainThreshold = integer
-- 5) Weather_UVThreshold = integer
-- 6) Weather_TempThreshold = integer
-- Create Switches:
-- 1) Regen = Dummy Humiditysensor
-- 2) WindSnelheid = Dummy Text
-- 3) WindRichting = Dummy Text
-- 4) Barometer = Weather Underground/Forecast IO
-- 5) Wind = Weather Underground/Forecast IO
-- 6) Regen = Weather Underground/Forecast IO
-- 7) Zon = Weather Underground/Forecast IO
-- 8) Zonnescherm = Up/Down switch
-- 9) Zonnescherm manual override = Dummy switch
-----------------------------------------------------------------------------
commandArray = {}
------------------------------------------------------------------------
-- Variabelen
lat='52.025526' -- example lat/lon for Gouda
lon='4.692806'
sDebug = tostring(uservariables["Weather_Debug"])
UVThreshold = uservariables["Weather_UVThreshold"]
WindSpeedThreshold = uservariables["Weather_WindSpeedThreshold"]
WindGustThreshold = uservariables["Weather_WindGustThreshold"]
RainThreshold = uservariables["Weather_RainThreshold"]
TempThreshold = uservariables["Weather_TempThreshold"]
tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable
idx = 220 --idx regen
idx2 = 221 -- idx windrichting
idx3 = 222 -- idx windsnelheid
minuten = 5
sBarometer = 'Barometer Gouda'
sWind = 'Wind Gouda'
sRain = 'Regen Gouda'
sUV = 'UV Gouda'
sSolar = 'Zon Gouda'
------------------------------------------------------------------------
--Sunscreen thresholds:
-- Windspeed = 100.0 (value is multiplied by 100)
-- Rain = 0.0
-- UV = 2.0
-- Temperature = 12.0
-- Closed = Down = On
-- Open = Up = Off
------------------------------------------------------------------------
-- Functies
function Message(fMessage, fDebug)
if (fDebug == "True") then
print("Weather: " .. fMessage)
end
end
function Notification(fNotification, fDebug)
if (fDebug == "False") then
commandArray['SendNotification'] = "" .. fNotification .. ""
end
end
function IsItGonnaRain( minutesinfuture )
url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon
Message("-- "..url,sDebug)
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
Message("-- Line:" ..line,sDebug)
linetime=string.sub(tostring(line), 5, 9)
Message("-- Linetime: "..linetime,sDebug)
-- 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
Message("-- Line in time range found",sDebug)
rain=tonumber(string.sub(tostring(line), 0, 3))
totalrain = totalrain+rain
rainlines=rainlines+1
Message("-- Rain in timerange: "..rain,sDebug)
Message("-- Total rain now: "..totalrain,sDebug)
end
end
file:close()
averagerain=totalrain/rainlines
return(averagerain)
end
regen = IsItGonnaRain(minuten)
Message("-- Regen verwacht: "..regen.." binnen "..minuten.." minuten.",sDebug)
if (regen > 0 ) then verw = 3 else verw = 2 end
--Weatherstation data:
sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[sBarometer]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV = tonumber(sWeatherUV);
sWeatherUV2 = tonumber(sWeatherUV2);
Message("______________________________________________________________________________________",sDebug)
Message("Weather station: Temperature is " .. sWeatherTemp .. " ",sDebug)
Message("Weather station: Humidity is " .. sWeatherHumidity .. " ",sDebug)
Message("Weather station: Pressure is " .. sWeatherPressure .. " ",sDebug)
Message("Weather station: UV is " .. sWeatherUV .. " ",sDebug)
Message("Weather station: UV2 is " .. sWeatherUV2 .. " ",sDebug)
Message("______________________________________________________________________________________",sDebug)
------------------------------------------------------------------------
--Windmeter data:
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[sWind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);
Message("______________________________________________________________________________________",sDebug)
Message("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ",sDebug)
Message("Windmeter: Winddirection is: " .. sWindDirection .. " ",sDebug)
Message("Windmeter: Windspeed is: " .. sWindSpeed .. " ",sDebug)
Message("Windmeter: Windgust is: " .. sWindGust .. " ",sDebug)
Message("Windmeter: Windtemperature is: " .. sWindTemperature .. " ",sDebug)
Message("Windmeter: Windfeel is: " .. sWindFeel .. " ",sDebug)
Message("______________________________________________________________________________________")
------------------------------------------------------------------------
--Rainmeter data:
sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[sRain]:match("([^;]+);([^;]+)")
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);
Message("______________________________________________________________________________________",sDebug)
Message("Rainmeter: Actual rain is: " .. sRainmeterCurrent .. " ",sDebug)
Message("Rainmeter: Total rain is: " .. sRainmeterTotal .. " ",sDebug)
Message("Rainmeter: Predicted rain is: " .. regen .. " ",sDebug)
Message("______________________________________________________________________________________",sDebug)
------------------------------------------------------------------------
--UV data:
sUV = otherdevices_svalues[sUV]:match("([^;]+)")
sSolar = otherdevices_svalues[sSolar]:match("([^;]+)")
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);
Message("UV: UV Strength is: " .. sUV .." ",sDebug)
Message("UV: Solar radiation is: " .. sSolar .." ",sDebug)
--Thresholds:
Message("______________________________________________________________________________________",sDebug)
Message("Thresholds: Temp threshold is: " .. TempThreshold .." ",sDebug)
Message("Thresholds: UV threshold is: " .. UVThreshold .." ",sDebug)
Message("Thresholds: WindSpeed threshold is: " .. WindSpeedThreshold .." ",sDebug)
Message("Thresholds: WindGust threshold is: " .. WindGustThreshold .." ",sDebug)
Message("Thresholds: Rain threshold is: " .. RainThreshold .." ",sDebug)
Message("______________________________________________________________________________________",sDebug)
if (timeofday['Daytime']) then
Message('It is past sunrise, monitoring variables for sunscreen',sDebug)
if (otherdevices['Zonnescherm'] == 'Open' ) then
Message ('Sunscreen is up',sDebug)
else
Message ('Sunscreen is down',sDebug)
end
if (otherdevices['Zonnescherm'] == 'Open'
and sRainmeterCurrent == RainThreshold
and sWeatherTemp > TempThreshold
and sUV > UVThreshold
and sWindSpeed < WindSpeedThreshold
and sWindGust < WindGustThreshold)
then
Message ('Sun is shining, all thresholds OK, lowering sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen down --> Sun is shining',sDebug)
commandArray['Zonnescherm']='On'
elseif (otherdevices['Zonnescherm'] == 'Closed' and (sRainmeterCurrent > RainThreshold or regen > 0)) then
Message ('It is raining, raising sunscreen')
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is raining',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWeatherTemp < TempThreshold and otherdevices['Zonnescherm manual override'] == 'Off') then
Message ('Temperature too low, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is too cold',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sUV < UVThreshold and otherdevices['Zonnescherm manual override'] == 'Off') then
Message ('Sun not shining too bright, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Sunshine not too bright',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindSpeed > WindSpeedThreshold) then
Message ('Windspeed too high, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Windspeed too high',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindGust > WindGustThreshold) then
Message ('Windgust too high, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Windgust too high',sDebug)
commandArray['Zonnescherm']='Off'
else
Message('Sunscreen status OK --> No action',sDebug)
Message('______________________________________________________________________________________',sDebug)
end
::done::
Message("At the end of the script",sDebug)
Message("______________________________________________________________________________________",sDebug)
elseif (timeofday['Nighttime'] and otherdevices['Zonnescherm'] == 'Closed') then
Message('It is night, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is night',sDebug)
commandArray['Zonnescherm']='Off'
else
Message('Sunscreen already up --> No action',sDebug)
Message('______________________________________________________________________________________',sDebug)
end
commandArray[1] = {['UpdateDevice'] = idx .. '|'..tostring(regen)..'|'..tostring(verw)}
commandArray[2] = {['UpdateDevice'] = idx2 .. '|0|'.. sWindDirection}
commandArray[3] = {['UpdateDevice'] = idx3 .. '|0|'.. sWindSpeed}
return CommandArray
Thanks for the script. I tested it (only on temperature).Luuc_a wrote:I have taken the script of tlpeter and made it to my needs.
I have done the following
- Integrate the script with the rain prediction of 'buienradar'.
- made user variables from the thresholds in Domoticz so I can control it from the web interface.
There is a little question. In the settings of Domoticz you can set the langitude and longitude. Is it possible to read this out by LUA?Code: Select all
----------------------------------------------------------------------------- -- LUA Script -- Extract values from Weather Underground device and 'Buienradar'-rain -- prediction to control the sunscreen -- Auteur: Luuc_A -- Datum : 29-05-2014 ----------------------------------------------------------------------------- -- Setup uservariables: -- 1) Weather_Debug = String = True / False -- 2) Weather_WindSpeedThreshold = integer -- 3) Weather_WindGustThreshold = integer -- 4) Weather_RainThreshold = integer -- 5) Weather_UVThreshold = integer -- 6) Weather_TempThreshold = integer -- Create Switches: -- 1) Regen = Dummy Humiditysensor -- 2) WindSnelheid = Dummy Text -- 3) WindRichting = Dummy Text -- 4) Barometer = Weather Underground/Forecast IO -- 5) Wind = Weather Underground/Forecast IO -- 6) Regen = Weather Underground/Forecast IO -- 7) Zon = Weather Underground/Forecast IO -- 8) Zonnescherm = Up/Down switch -- 9) Zonnescherm manual override = Dummy switch ----------------------------------------------------------------------------- commandArray = {} ------------------------------------------------------------------------ -- Variabelen lat='52.025526' -- example lat/lon for Gouda lon='4.692806' sDebug = tostring(uservariables["Weather_Debug"]) UVThreshold = uservariables["Weather_UVThreshold"] WindSpeedThreshold = uservariables["Weather_WindSpeedThreshold"] WindGustThreshold = uservariables["Weather_WindGustThreshold"] RainThreshold = uservariables["Weather_RainThreshold"] TempThreshold = uservariables["Weather_TempThreshold"] tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable idx = 220 --idx regen idx2 = 221 -- idx windrichting idx3 = 222 -- idx windsnelheid minuten = 5 sBarometer = 'Barometer Gouda' sWind = 'Wind Gouda' sRain = 'Regen Gouda' sUV = 'UV Gouda' sSolar = 'Zon Gouda' ------------------------------------------------------------------------ --Sunscreen thresholds: -- Windspeed = 100.0 (value is multiplied by 100) -- Rain = 0.0 -- UV = 2.0 -- Temperature = 12.0 -- Closed = Down = On -- Open = Up = Off ------------------------------------------------------------------------ -- Functies function Message(fMessage, fDebug) if (fDebug == "True") then print("Weather: " .. fMessage) end end function Notification(fNotification, fDebug) if (fDebug == "False") then commandArray['SendNotification'] = "" .. fNotification .. "" end end function IsItGonnaRain( minutesinfuture ) url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon Message("-- "..url,sDebug) 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 Message("-- Line:" ..line,sDebug) linetime=string.sub(tostring(line), 5, 9) Message("-- Linetime: "..linetime,sDebug) -- 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 Message("-- Line in time range found",sDebug) rain=tonumber(string.sub(tostring(line), 0, 3)) totalrain = totalrain+rain rainlines=rainlines+1 Message("-- Rain in timerange: "..rain,sDebug) Message("-- Total rain now: "..totalrain,sDebug) end end file:close() averagerain=totalrain/rainlines return(averagerain) end regen = IsItGonnaRain(minuten) Message("-- Regen verwacht: "..regen.." binnen "..minuten.." minuten.",sDebug) if (regen > 0 ) then verw = 3 else verw = 2 end --Weatherstation data: sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[sBarometer]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)") sWeatherTemp = tonumber(sWeatherTemp); sWeatherHumidity = tonumber(sWeatherHumidity); sWeatherPressure = tonumber(sWeatherPressure); sWeatherUV = tonumber(sWeatherUV); sWeatherUV2 = tonumber(sWeatherUV2); Message("______________________________________________________________________________________",sDebug) Message("Weather station: Temperature is " .. sWeatherTemp .. " ",sDebug) Message("Weather station: Humidity is " .. sWeatherHumidity .. " ",sDebug) Message("Weather station: Pressure is " .. sWeatherPressure .. " ",sDebug) Message("Weather station: UV is " .. sWeatherUV .. " ",sDebug) Message("Weather station: UV2 is " .. sWeatherUV2 .. " ",sDebug) Message("______________________________________________________________________________________",sDebug) ------------------------------------------------------------------------ --Windmeter data: sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[sWind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)") sWindDirectionDegrees = tonumber(sWindDirectionDegrees); sWindDirection = (sWindDirection); sWindSpeed = tonumber(sWindSpeed); sWindGust = tonumber(sWindGust); sWindTemperature = tonumber(sWindTemperature); sWindFeel = tonumber(sWindFeel); Message("______________________________________________________________________________________",sDebug) Message("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ",sDebug) Message("Windmeter: Winddirection is: " .. sWindDirection .. " ",sDebug) Message("Windmeter: Windspeed is: " .. sWindSpeed .. " ",sDebug) Message("Windmeter: Windgust is: " .. sWindGust .. " ",sDebug) Message("Windmeter: Windtemperature is: " .. sWindTemperature .. " ",sDebug) Message("Windmeter: Windfeel is: " .. sWindFeel .. " ",sDebug) Message("______________________________________________________________________________________") ------------------------------------------------------------------------ --Rainmeter data: sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[sRain]:match("([^;]+);([^;]+)") sRainmeterCurrent = tonumber(sRainmeterCurrent); sRainmeterTotal = tonumber(sRainmeterTotal); Message("______________________________________________________________________________________",sDebug) Message("Rainmeter: Actual rain is: " .. sRainmeterCurrent .. " ",sDebug) Message("Rainmeter: Total rain is: " .. sRainmeterTotal .. " ",sDebug) Message("Rainmeter: Predicted rain is: " .. regen .. " ",sDebug) Message("______________________________________________________________________________________",sDebug) ------------------------------------------------------------------------ --UV data: sUV = otherdevices_svalues[sUV]:match("([^;]+)") sSolar = otherdevices_svalues[sSolar]:match("([^;]+)") sUV = tonumber(sUV); sSolar = tonumber(sSolar); Message("UV: UV Strength is: " .. sUV .." ",sDebug) Message("UV: Solar radiation is: " .. sSolar .." ",sDebug) --Thresholds: Message("______________________________________________________________________________________",sDebug) Message("Thresholds: Temp threshold is: " .. TempThreshold .." ",sDebug) Message("Thresholds: UV threshold is: " .. UVThreshold .." ",sDebug) Message("Thresholds: WindSpeed threshold is: " .. WindSpeedThreshold .." ",sDebug) Message("Thresholds: WindGust threshold is: " .. WindGustThreshold .." ",sDebug) Message("Thresholds: Rain threshold is: " .. RainThreshold .." ",sDebug) Message("______________________________________________________________________________________",sDebug) if (timeofday['Daytime']) then Message('It is past sunrise, monitoring variables for sunscreen',sDebug) if (otherdevices['Zonnescherm'] == 'Open' ) then Message ('Sunscreen is up',sDebug) else Message ('Sunscreen is down',sDebug) end if (otherdevices['Zonnescherm'] == 'Open' and sRainmeterCurrent == RainThreshold and sWeatherTemp > TempThreshold and sUV > UVThreshold and sWindSpeed < WindSpeedThreshold and sWindGust < WindGustThreshold) then Message ('Sun is shining, all thresholds OK, lowering sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen down --> Sun is shining',sDebug) commandArray['Zonnescherm']='On' elseif (otherdevices['Zonnescherm'] == 'Closed' and (sRainmeterCurrent > RainThreshold or regen > 0)) then Message ('It is raining, raising sunscreen') Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> It is raining',sDebug) commandArray['Zonnescherm']='Off' elseif (otherdevices['Zonnescherm'] == 'Closed' and sWeatherTemp < TempThreshold and otherdevices['Zonnescherm manual override'] == 'Off') then Message ('Temperature too low, raising sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> It is too cold',sDebug) commandArray['Zonnescherm']='Off' elseif (otherdevices['Zonnescherm'] == 'Closed' and sUV < UVThreshold and otherdevices['Zonnescherm manual override'] == 'Off') then Message ('Sun not shining too bright, raising sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> Sunshine not too bright',sDebug) commandArray['Zonnescherm']='Off' elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindSpeed > WindSpeedThreshold) then Message ('Windspeed too high, raising sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> Windspeed too high',sDebug) commandArray['Zonnescherm']='Off' elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindGust > WindGustThreshold) then Message ('Windgust too high, raising sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> Windgust too high',sDebug) commandArray['Zonnescherm']='Off' else Message('Sunscreen status OK --> No action',sDebug) Message('______________________________________________________________________________________',sDebug) end ::done:: Message("At the end of the script",sDebug) Message("______________________________________________________________________________________",sDebug) elseif (timeofday['Nighttime'] and otherdevices['Zonnescherm'] == 'Closed') then Message('It is night, raising sunscreen',sDebug) Message('______________________________________________________________________________________',sDebug) Notification('Sunscreen#Sunscreen up --> It is night',sDebug) commandArray['Zonnescherm']='Off' else Message('Sunscreen already up --> No action',sDebug) Message('______________________________________________________________________________________',sDebug) end commandArray[1] = {['UpdateDevice'] = idx .. '|'..tostring(regen)..'|'..tostring(verw)} commandArray[2] = {['UpdateDevice'] = idx2 .. '|0|'.. sWindDirection} commandArray[3] = {['UpdateDevice'] = idx3 .. '|0|'.. sWindSpeed} return CommandArray
Code: Select all
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWeatherTemp < TempThreshold and otherdevices['Zonnescherm manual override'] == 'Off') then
Code: Select all
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWeatherTemp < TempThreshold) then
Code: Select all
-----------------------------------------------------------------------------
-- LUA Script
-- Extract values from WU device
-- Auteur: Luuc Alarm
-- Datum : 29-05-2014
-----------------------------------------------------------------------------
-- Setup uservariables:
-- 1) Weather_Debug = String = True / False
-- 2) Weather_WindSpeedThreshold = integer
-- 3) Weather_WindGustThreshold = integer
-- 4) Weather_RainThreshold = integer
-- 5) Weather_RainPredThreshold = integer
-- 6) Weather_UVThreshold = integer
-- 7) Weather_SolarThreshold = integer
-- 8) Weather_TempThreshold = integer
-- Create Switches:
-- 1) Regen = Dummy Humiditysensor
-- 2) WindSnelheid = Dummy Text
-- 3) WindRichting = Dummy Text
-- 4) Barometer = Weather Underground/Forecast IO
-- 5) Wind = Weather Underground/Forecast IO
-- 6) Regen = Weather Underground/Forecast IO
-- 7) Zon = Weather Underground/Forecast IO
-- 8) Zonnescherm = Up/Down switch
-- 9) Zonnescherm manual override = Dummy On/Off switch
-----------------------------------------------------------------------------
commandArray = {}
-- tijd ophalen
time = os.date("*t")
------------------------------------------------------------------------
-- Variabelen
lat='52.025526' -- example lat/lon for Gouda
lon='4.692806'
sDebug = tostring(uservariables["Weather_Debug"])
UVThreshold = uservariables["Weather_UVThreshold"]
SolarThreshold = uservariables["Weather_SolarThreshold"]
WindSpeedThreshold = uservariables["Weather_WindSpeedThreshold"]
WindGustThreshold = uservariables["Weather_WindGustThreshold"]
RainThreshold = uservariables["Weather_RainThreshold"]
RainPredThreshold = uservariables["Weather_RainPredThreshold"]
TempThreshold = uservariables["Weather_TempThreshold"]
tempfilename = '/var/tmp/rain.tmp' -- can be anywhere writeable
idx = 220 --idx regen
idx2 = 221 -- idx windrichting
idx3 = 222 -- idx windsnelheid
minuten = 5 -- time within rainprediction
sBarometer = 'Barometer Gouda'
sWind = 'Wind Gouda'
sRain = 'Regen Gouda'
sUV = 'UV Gouda'
sSolar = 'Zon Gouda'
------------------------------------------------------------------------
--Sunscreen thresholds:
-- Windspeed = 100.0 (value is multiplied by 100)
-- Rain = 0.0
-- UV = 2.0
-- Temperature = 12.0
-- Closed = Down = On
-- Open = Up = Off
------------------------------------------------------------------------
-- Functies
function Message(fMessage, fDebug)
if (fDebug == "True") then
print("Weather: " .. fMessage)
end
end
function Notification(fNotification, fDebug)
if (fDebug == "False") then
commandArray['SendNotification'] = "" .. fNotification .. ""
end
end
function IsItGonnaRain( minutesinfuture )
url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon
Message("-- "..url,sDebug)
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
Message("-- Line:" ..line,sDebug)
linetime=string.sub(tostring(line), 5, 9)
Message("-- Linetime: "..linetime,sDebug)
-- 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
Message("-- Line in time range found",sDebug)
rain=tonumber(string.sub(tostring(line), 0, 3))
totalrain = totalrain+rain
rainlines=rainlines+1
Message("-- Rain in timerange: "..rain,sDebug)
Message("-- Total rain now: "..totalrain,sDebug)
end
end
file:close()
averagerain=totalrain/rainlines
return(averagerain)
end
regen = IsItGonnaRain(minuten)
Message("-- Regen verwacht: "..regen.." binnen "..minuten.." minuten.",sDebug)
if (regen > 0 ) then verw = 3 else verw = 2 end
--Weatherstation data:
sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[sBarometer]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV = tonumber(sWeatherUV);
sWeatherUV2 = tonumber(sWeatherUV2);
Message("______________________________________________________________________________________",sDebug)
Message("Weather station: Temperature is " .. sWeatherTemp .. " ",sDebug)
Message("Weather station: Humidity is " .. sWeatherHumidity .. " ",sDebug)
Message("Weather station: Pressure is " .. sWeatherPressure .. " ",sDebug)
Message("Weather station: UV is " .. sWeatherUV .. " ",sDebug)
Message("Weather station: UV2 is " .. sWeatherUV2 .. " ",sDebug)
Message("______________________________________________________________________________________",sDebug)
------------------------------------------------------------------------
--Windmeter data:
sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[sWind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);
Message("______________________________________________________________________________________",sDebug)
Message("Windmeter: Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ",sDebug)
Message("Windmeter: Winddirection is: " .. sWindDirection .. " ",sDebug)
Message("Windmeter: Windspeed is: " .. sWindSpeed .. " ",sDebug)
Message("Windmeter: Windgust is: " .. sWindGust .. " ",sDebug)
Message("Windmeter: Windtemperature is: " .. sWindTemperature .. " ",sDebug)
Message("Windmeter: Windfeel is: " .. sWindFeel .. " ",sDebug)
Message("______________________________________________________________________________________")
------------------------------------------------------------------------
--Rainmeter data:
sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[sRain]:match("([^;]+);([^;]+)")
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);
Message("______________________________________________________________________________________",sDebug)
Message("Rainmeter: Actual rain is: " .. sRainmeterCurrent .. " ",sDebug)
Message("Rainmeter: Total rain is: " .. sRainmeterTotal .. " ",sDebug)
Message("Rainmeter: Predicted rain is: " .. regen .. " ",sDebug)
Message("______________________________________________________________________________________",sDebug)
------------------------------------------------------------------------
--UV data:
sUV = otherdevices_svalues[sUV]:match("([^;]+)")
sSolar = otherdevices_svalues[sSolar]:match("([^;]+)")
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);
Message("UV: UV Strength is: " .. sUV .." ",sDebug)
Message("UV: Solar radiation is: " .. sSolar .." ",sDebug)
--Thresholds:
Message("______________________________________________________________________________________",sDebug)
Message("Thresholds: Temp threshold is: " .. TempThreshold .." ",sDebug)
Message("Thresholds: UV threshold is: " .. UVThreshold .." ",sDebug)
Message("Thresholds: Solar threshold is: " .. SolarThreshold .." ",sDebug)
Message("Thresholds: WindSpeed threshold is: " .. WindSpeedThreshold .." ",sDebug)
Message("Thresholds: WindGust threshold is: " .. WindGustThreshold .." ",sDebug)
Message("Thresholds: Rain threshold is: " .. RainThreshold .." ",sDebug)
Message("Thresholds: Rain Prediction threshold is: " .. RainPredThreshold .." ",sDebug)
Message("______________________________________________________________________________________",sDebug)
Message("Override: ".. otherdevices['Zonnescherm manual override'],sDebug)
Message("______________________________________________________________________________________",sDebug)
if (timeofday['Daytime']) then
Message('It is past sunrise, monitoring variables for sunscreen',sDebug)
if (otherdevices['Zonnescherm'] == 'Open' ) then
Message ('Sunscreen is up',sDebug)
else
Message ('Sunscreen is down',sDebug)
end
if (otherdevices['Zonnescherm'] == 'Open'
and sRainmeterCurrent == RainThreshold
and sWeatherTemp > TempThreshold
and (sUV > UVThreshold or sSolar > SolarThreshold)
and sWindSpeed < WindSpeedThreshold
and sWindGust < WindGustThreshold)
then
Message ('Sun is shining, all thresholds OK, lowering sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen down --> Sun is shining',sDebug)
commandArray['Zonnescherm']='On'
elseif (otherdevices['Zonnescherm'] == 'Closed' and (sRainmeterCurrent > RainThreshold or regen > RainPredThreshold)) then
Message ('It is raining, raising sunscreen')
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is raining',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWeatherTemp < TempThreshold-1 and otherdevices['Zonnescherm manual override'] == 'Off') then
Message ('Temperature too low, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is too cold',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and (sUV < UVThreshold-1 or sSolar < SolarThreshold) and otherdevices['Zonnescherm manual override'] == 'Off') then
Message ('Sun not shining too bright, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Sunshine not too bright',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindSpeed > WindSpeedThreshold) then
Message ('Windspeed too high, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Windspeed too high',sDebug)
commandArray['Zonnescherm']='Off'
elseif (otherdevices['Zonnescherm'] == 'Closed' and sWindGust > WindGustThreshold) then
Message ('Windgust too high, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> Windgust too high',sDebug)
commandArray['Zonnescherm']='Off'
else
Message('Sunscreen status OK --> No action',sDebug)
Message('______________________________________________________________________________________',sDebug)
end
::done::
Message("At the end of the script",sDebug)
Message("______________________________________________________________________________________",sDebug)
elseif (timeofday['Nighttime'] and otherdevices['Zonnescherm'] == 'Closed') then
Message('It is night, raising sunscreen',sDebug)
Message('______________________________________________________________________________________',sDebug)
Notification('Sunscreen#Sunscreen up --> It is night',sDebug)
commandArray['Zonnescherm']='Off'
else
Message('Sunscreen already up --> No action',sDebug)
Message('______________________________________________________________________________________',sDebug)
end
commandArray[1] = {['UpdateDevice'] = idx .. '|'..tostring(regen)..'|'..tostring(verw)}
commandArray[2] = {['UpdateDevice'] = idx2 .. '|0|'.. sWindDirection}
commandArray[3] = {['UpdateDevice'] = idx3 .. '|0|'.. sWindSpeed}
return CommandArray
Code: Select all
----------------------------------------------------------------------------------------------------------------
-- IsItGonnaRain( int minutesinfuture)
-- returns: int avarage rainfall for the next minutesinfuture
--
-- Function to get rain prediction from Buienradar.nl (dutch)
--
-- http://gratisweerdata.buienradar.nl/#Buienradar You may use their free service for non-commercial purposes.
--
-- Written in LUA by Hans van der Heijden (h4nsie @ gmail.com)
-- Spring 2015
-- 28-03-2015 v0.3 bug: quotes around url added.
-- 27-03-2015 v0.2 return value is now average for next time
-- 26-03-2015 v0.1 Initial release
-- todo: some error checking on http and file handling (tmp file)
----------------------------------------------------------------------------------------------------------------
function IsItGonnaRain( minutesinfuture )
-- config ---------------------------------------------------------
lat='50.891508' -- example lat/lon for Heerlen
lon='5.960975'
debug=False
tempfilename = 'C:\\Rain\\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('"C:/Rain/Curl/bin/curl.exe -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) (example: 77 = 0.1 mm/hour)
averagerain=totalrain/rainlines
return(averagerain)
end
----- REGEN ------
commandArray = {}
minuten=15
regen = IsItGonnaRain(minuten)
print('Regen verwacht(0-255 hoe hoger hoe meer regen): '..regen..' binnen '..minuten..' minuten.')
if (regen > 0 ) then verw = 3 else verw = 2 end
commandArray['UpdateDevice'] = '170|'..tostring(regen)..'|'..tostring(verw)
return commandArray
Maybe you could try my script, just finished it and does what you want...Bram81 wrote:Hi Hans,
I've tried to send you a PM (in Dutch) but it seems that I can't get any messasges sent. I'm not familiar witch lua just yet but I would like to get data from Buienradar as well to add to my garden irrigation system and moisture sensors already in place. Can you put me on the right track about how to integrate this in domoticz exactly?
Thank in advance!
Can you post an example of your Blockly?jjnj wrote:I would like to use the outcome of the rain value/virtual humidity sensor in blocky. But for some reason blocky doesn't seem to respond to the value of the virtual humidity sensor. anybody has an idea?
Just a plain and simple blocky just to testBrutus wrote:Can you post an example of your Blockly?jjnj wrote:I would like to use the outcome of the rain value/virtual humidity sensor in blocky. But for some reason blocky doesn't seem to respond to the value of the virtual humidity sensor. anybody has an idea?
jjnj wrote:Just a plain and simple blocky just to testBrutus wrote:Can you post an example of your Blockly?jjnj wrote:I would like to use the outcome of the rain value/virtual humidity sensor in blocky. But for some reason blocky doesn't seem to respond to the value of the virtual humidity sensor. anybody has an idea?
Thanks! Haven't worked with lua before, so I guess there is a lot to learn but this will help me for sure!Siewert308SW wrote:Maybe you could try my script, just finished it and does what you want...Bram81 wrote:Hi Hans,
I've tried to send you a PM (in Dutch) but it seems that I can't get any messasges sent. I'm not familiar witch lua just yet but I would like to get data from Buienradar as well to add to my garden irrigation system and moisture sensors already in place. Can you put me on the right track about how to integrate this in domoticz exactly?
Thank in advance!
viewtopic.php?f=23&t=7290
Why a threshold for 70? Then it would already be raining right below 70? So that would be to lateHansbit wrote:Posted a install instruction in the Wiki
https://www.domoticz.com/wiki/Is_it_gonna_rain
Please note that a threshold of 70 is (in my opinion) the best value to trigger for rain.
With lower values to trigger for rain you'll get too many false positives. Even on sunny days with clear blue sky, Buienrader sometimes reports values like 35 or 40.jjnj wrote:Why a threshold for 70? Then it would already be raining right below 70? So that would be to late
Code: Select all
return CommandArray
Users browsing this forum: No registered users and 0 guests