Page 1 of 1

Raingadgets

Posted: Monday 24 February 2025 12:01
by HvdW
Here is a script to add to domoticz
- 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
}
Another one to add Weeronline to a Custom menu.
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>

Re: Raingadgets

Posted: Monday 24 February 2025 13:25
by waltervl
With the default Buienradar integration there is already a rainrate forecast device: https://wiki.domoticz.com/Buienradar
So in my opinion you do not need to get it from buienradar again if you want to convert the rate into understandable text. Just read the existing sensor every 15 minutes and update the text sensor.

Re: Raingadgets

Posted: Monday 24 February 2025 15:48
by HvdW
Just the rain intensity translated per quarter hour coming, no mm's, that's all.
Screenshot_20250224_155141_Firefox.jpg
Screenshot_20250224_155141_Firefox.jpg (108.75 KiB) Viewed 359 times
Simple table plotting 🕰️ and 🌦️ risk.

Re: Raingadgets

Posted: Monday 24 February 2025 17:25
by waltervl
That is not what I was referring to. I do like the rainrate translated into text.
In your script you connect to https://gpsgadget.buienradar.nl to fetch data. That is not needed when you use the already existing buienradar hardware gateway. It saves some unnecessary calls to https://gpsgadget.buienradar.nl

Re: Raingadgets

Posted: Tuesday 25 February 2025 0:02
by HvdW
BTW
Thanks for your referral.
My next Custom page will be this one.
https://gpsgadget.buienradar.nl/gadget/radarfivedays
It has a lot of information in one view and will be called only when the Custom page is opened.