- Rain to display the rain prediction for the coming hour.
Create a new TextSensor with the name 'Regen'
Use this script in which you can adapt the coordinates of where you live.
Code: Select all
return {
on = {
timer = { 'every 15 minutes' },
httpResponses = { 'rain_forecast_callback' }
},
logging = {
level = domoticz.LOG_ERROR,
marker = "Rain Forecast"
},
execute = function(domoticz, item)
-- Rain intensity classification with cascading conditionals
local function getRainIntensity(code)
code = tonumber(code)
if code > 110 then return "Zware regen"
elseif code >= 88 then return "Matige regen"
elseif code >= 77 then return "Lichte regen"
elseif code >= 51 then return "Regenachtig"
elseif code >= 20 then return "Motregen"
elseif code == 0 then return "Geen neerslag"
else return "Onbekend" end
end
-- Process timer trigger
if item.isTimer then
local location = domoticz.settings.location
if not location or not location.latitude or not location.longitude then
domoticz.log('Location data not configured', domoticz.LOG_ERROR)
return
end
domoticz.openURL({
url = string.format(
"https://gpsgadget.buienradar.nl/data/raintext/?lat=%.6f&lon=%.6f",
location.latitude,
location.longitude
),
method = 'GET',
callback = 'rain_forecast_callback'
})
-- Process HTTP response
elseif item.isHTTPResponse then
if not item.ok then
domoticz.log(string.format(
"Failed to fetch rain data (HTTP %d)",
item.statusCode
), domoticz.LOG_ERROR)
return
end
local forecast = {}
local lineCount = 0
for line in item.data:gmatch("[^\r\n]+") do
local intensity, time = line:match("(%d+)|(%d+:%d+)")
if time and tonumber(time:match("%d+$")) % 15 == 0 then
table.insert(forecast, string.format(
"%s | %3s | %-12s",
time,
intensity,
getRainIntensity(intensity)
))
lineCount = lineCount + 1
if lineCount >= 4 then break end
end
end
local rainSensor = domoticz.devices('Regen')
if rainSensor then
rainSensor.updateText(table.concat(forecast, "\n"))
domoticz.log(string.format(
"Updated rain forecast with %d intervals",
lineCount
), domoticz.LOG_INFO)
else
domoticz.log("Rain sensor device not found", domoticz.LOG_ERROR)
end
end
end
}
Read the instructions here and place this text in a textfile named weeronline.html in /home/pi/domoticz/www/templates
Code: Select all
<IFRAME SRC="https://www.weeronline.nl/widget/radar?id=123456789&circle=true" height="800" width="100%"></IFRAME>