Raingadgets

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
HvdW
Posts: 613
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Raingadgets

Post 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>
Last edited by HvdW on Tuesday 25 March 2025 11:55, edited 2 times in total.
Bugs bug me.
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Raingadgets

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 613
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Raingadgets

Post 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 356 times
Simple table plotting 🕰️ and 🌦️ risk.
Bugs bug me.
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Raingadgets

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 613
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Raingadgets

Post 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.
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest