Problem with accessing https://api.open-meteo.com/

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

I'm using a script in accessing open.meteo. I running with dockge and the latest beta. My code is :
Domoticz is reporting a 503 error, api.open.meteo is not accessible, but 10000 hits are available and Ive had some sussesvol sessions, but few
Anyone have the same problem?

Code: Select all

return {
   active = true,
   on = {
     timer = { "every 30 minutes" },
     httpResponses = { 'openmeteo_cloud_api' }
   },

execute = function(domoticz, item)

domoticz.log(
    "Cloud trigger: timer="..tostring(item.isTimer)..
    " http="..tostring(item.isHTTPResponse),
    domoticz.LOG_STATUS)
 
    -------------------------------------------------
    -- CONFIG
    -------------------------------------------------
    local var = domoticz.variables("CloudForecast_LastUpdate")
    local lastUpdate = var and tonumber(var.value) or 0

    local now = os.time()

    local retryVar = domoticz.variables("CloudForecast_LastAttempt")
    local lastAttempt = retryVar and tonumber(retryVar.value) or 0

    domoticz.log("Time Now : "..now.. "  Time LastAttempt : " .. lastAttempt .. "  Time- LastAttempt : " .. now-lastAttempt, domoticz.LOG_STATUS) 

    if (now - lastAttempt) < 1800 then
        domoticz.log("Cloud API retry delay active", domoticz.LOG_DEBUG)
        return
    end

    -------------------------------------------------
    -- STEP 1: THROTTLED REQUEST
    -------------------------------------------------
    if item.isTimer then

        -- ⛔ SKIP IF DATA IS STILL FRESH (15 min cache)
        if (now - lastUpdate) < 900 then
            domoticz.log("Cloud API skipped (cached)", domoticz.LOG_DEBUG)
            return
        end

    if retryVar then
        retryVar.set(now)
    end

    local URL = "https://api.open-meteo.com/v1/forecast?latitude=51.46&longitude=5.45&hourly=shortwave_radiation,cloud_cover&timezone=auto&tilt=55"

    domoticz.openURL({
        url = URL,
        method = 'GET',
        timeout = 30,
        callback = 'openmeteo_cloud_api',
         })

        domoticz.log("Cloud API request sent", domoticz.LOG_STATUS)
        return
    end
    -------------------------------------------------
    -- STEP 2: RESPONSE HANDLING
    -------------------------------------------------
    if not item.isHTTPResponse then return end
    
    domoticz.log("HTTP status: " .. tostring(item.statusCode), domoticz.LOG_STATUS)

    if item.statusCode == 503 then
--        domoticz.variables("CloudForecast_LastAttempt").set(os.time())
        domoticz.log(
            "Open-Meteo overloaded. Keeping previous forecast.",
            domoticz.LOG_STATUS
        )
        return
    end

    if item.statusCode ~= 200 then
        domoticz.log(
            "Weather download failed: "..tostring(item.statusCode),
            domoticz.LOG_ERROR
        )
        domoticz.log(tostring(item.data), domoticz.LOG_ERROR)
        return
    end
    
    if item.headers then
    for k,v in pairs(item.headers) do
        domoticz.log(k.." = "..tostring(v), domoticz.LOG_ERROR)
        end
    end
    -------------------------------------------------
    -- HARD VALIDATION
    -------------------------------------------------
    local body = tostring(item.data or ""):match("^%s*(.*)")

    if body == "" or body:sub(1,1) ~= "{" then
        domoticz.log("Invalid response: " .. body, domoticz.LOG_ERROR)
        return
    end
    -------------------------------------------------
    -- SAFE PARSE
    -------------------------------------------------
    local ok, data = pcall(domoticz.utils.fromJSON, item.data)

    if not ok then
        domoticz.log("JSON parse failed", domoticz.LOG_ERROR)
        return
    end

    domoticz.log("JSON parsed successfully", domoticz.LOG_STATUS)
    domoticz.log(item.data, domoticz.LOG_STATUS)
    -------------------------------------------------
    -- FIELD CHECK
    -------------------------------------------------
    if not data.hourly or not data.hourly.time or not data.hourly.cloud_cover or not data.hourly.shortwave_radiation then
        domoticz.log("Cloud API missing required fields", domoticz.LOG_ERROR)
        --domoticz.log(item.data, domoticz.LOG_ERROR)
        return
    end
    -------------------------------------------------
    -- BUILD CLEAN FORECAST
    -------------------------------------------------
    local out = {}

    local max = math.min(24, #data.hourly.time)

    for i = 1, max do

    local t = data.hourly.time[i]
    local c = data.hourly["cloud_cover"][i]
    local r = data.hourly["shortwave_radiation"][i]

    if t and c ~= nil then
        out[#out+1] = {
            t = t,
            c = tonumber(c) or 50,
            rad = tonumber(r) or 0
        }
        end
    end

    if #out == 0 then
        domoticz.log("Cloud API empty result", domoticz.LOG_ERROR)
        return
    end
    -------------------------------------------------
    -- SAVE FORECAST
    -------------------------------------------------
    if var then
        var.set(os.time())
    else
        domoticz.log("Missing CloudForecast_LastUpdate variable", domoticz.LOG_ERROR)
    end

    local store = domoticz.variables("CloudForecast")
    if store then
        store.set(domoticz.utils.toJSON(out))
    end
    -------------------------------------------------
    -- LOG
    -------------------------------------------------
    domoticz.log(string.format(
        "Cloud API updated OK (%d entries)",
        #out
    ), domoticz.LOG_STATUS)

end
}
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

The line

Code: Select all

if not item.isHTTPResponse then return end
is not doing anything. The next lines running the http response is always running also when it is timer response. Then you will get an error.

So make httpresponse working eg

Code: Select all

if item.isHTTPResponse then 
  
  -- Do your httpresponse code
  
  end
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

I dont think that that was the problem. I could go to the website with the http address and get the needed info, and i could use curl command to get the file with a new script, it was the openURL that was failing, and still is failing
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

I should give it a try if I were you.....

An if you think it is openurl then try the curl from within the docker container.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

I did try it, and it doesn't give the result. I also implemented a version with curl, which works flawlessly, so i have a running solution. But the fact that openURL is failing made me think. I worked it out with ChatGPT, ant it says after running several experiments that the version of:

I'm seeing intermittent HTTP 503 responses when using dzVents domoticz.openURL() to query the Open-Meteo API. The exact same URL, executed from the same Docker container with the command-line curl, consistently returns HTTP 200 and valid JSON.

I verified:

The URL is correct.
The request rate is low (every 30 minutes).
Manual curl requests can be repeated without issue.
The problem occurs only when using openURL().

As a workaround, I changed the script to execute curl externally, read the JSON from a temporary file, and parse it in dzVents. This has been reliable. Occasionally the first curl attempt fails, but a retry 5 seconds later succeeds, suggesting a transient network or server issue that curl handles better than openURL().

My Domoticz version is 18133 (beta) running in Docker, and the binary is linked against libcurl-gnutls (libcurl-gnutls.so.4).
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

I see no reason why dzvents function OpenUrl should not work properly in docker.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

Strange, if i run the curl script, and in the same timeslot the openURL, the openURL script runs without error, as if the curl script primes someting, very strange. If i run the openURL script alone, it fails.
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

My idea that some kind of trigger must prime the openURL is true, if i check any site (for instance google) then the full previous code is succesvol:

Code: Select all

    if item.isTimer then
        
    local URL = "https://www.google.com/"  --https://httpbin.org/get

    domoticz.openURL({
        url = URL,
        method = "GET",
        callback = "warmup"
        })

    os.execute("sleep 5")

    local URL = "https://api.open-meteo.com/v1/forecast?latitude=51.46&longitude=5.45&hourly=shortwave_radiation,cloud_cover&forecast_hours=24&timezone=auto&tilt=55"

     domoticz.openURL({
        url = URL,
        method = 'GET',
        timeout = 30,
        headers = {
        ["Accept"] = "*/*",
        ["User-Agent"] = "curl/8.14.1",
        ["Connection"] = "close"
        },
        callback = 'openmeteo_cloud_api',
         })

        domoticz.log("Cloud API request sent", domoticz.LOG_STATUS)
        return
    end
    
    if item.trigger == "warmup" then
     return
    end
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

it should be as simple as in the Dzvents wiki example. Callback and httpResponses should be the same value. Also they should be unique so no reuse of a callback else another script with the same httpResponse will be triggered.

https://wiki.domoticz.com/DzVents:_next ... d_handling

Code: Select all

return {
    on = {
        timer = { 'every 5 minutes' },
        httpResponses = { 'energyRetrieved' }
    },
    execute = function(domoticz, item)
        if (item.isTimer) then
            domoticz.openURL({
            url = 'http://url/to/service',
            method = 'GET',
            callback = 'energyRetrieved'
            })
        elseif (item.isHTTPResponse) then
            if (item.ok) then -- statusCode == 2xx
                local current = item.json.consumption
                domoticz.devices('myCurrentUsage').updateEnergy(current)
            end
        end
    end
}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

I just tested this with the following script and it is working just fine on my docker system also after some minutes.

Code: Select all

return {
    on = {
        timer = { 'every minute' },
        httpResponses = { 'meteotest' }
    },
    logging = {
		    level = domoticz.LOG_INFO,
		    marker = 'meteo',
	},
    execute = function(domoticz, item)
        if (item.isTimer) then
            domoticz.openURL({
            url = 'https://api.open-meteo.com/v1/forecast?latitude=51.46&longitude=5.45&hourly=shortwave_radiation,cloud_cover&forecast_hours=24&timezone=auto&tilt=55',
            method = 'GET',
            callback = 'meteotest'
            })
            domoticz.log('openurl called')
        elseif (item.isHTTPResponse) then
            if (item.ok) then -- statusCode == 2xx
                domoticz.log('Could get data from website ',domoticz.LOG_INFO)
                domoticz.log(item.data,domoticz.LOG_INFO)
            else    
                domoticz.log('Could not get (good) data from website ',domoticz.LOG_STATUS)
                domoticz.log(item.data,domoticz.LOG_INFO)
            end
        end
    end
}
Logging:

Code: Select all

2026-07-22 18:56:00.148  dzVents: meteo: openurl called
2026-07-22 18:56:00.496  dzVents: meteo: Could get data from website 
2026-07-22 18:56:00.496  dzVents: meteo: {"latitude":51.466,"longitude":5.4519997,"generationtime_ms":0.06568431854248047,"utc_offset_seconds":7200,"timezone":"Europe/Amsterdam","timezone_abbreviation":"GMT+2","elevation":39.0,"hourly_units":{"time":"iso8601","shortwave_radiation":"W/m²","cloud_cover":"%"},"hourly":{"time":["2026-07-22T18:00","2026-07-22T19:00","2026-07-22T20:00","2026-07-22T21:00","2026-07-22T22:00","2026-07-22T23:00","2026-07-23T00:00","2026-07-23T01:00","2026-07-23T02:00","2026-07-23T03:00","2026-07-23T04:00","2026-07-23T05:00","2026-07-23T06:00","2026-07-23T07:00","2026-07-23T08:00","2026-07-23T09:00","2026-07-23T10:00","2026-07-23T11:00","2026-07-23T12:00","2026-07-23T13:00","2026-07-23T14:00","2026-07-23T15:00","2026-07-23T16:00","2026-07-23T17:00"],"shortwave_radiation":[148.0,228.0,68.0,21.0,5.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,5.0,59.0,103.0,143.0,109.0,174.0,596.0,727.0,734.0,639.0,550.0],"cloud_cover":[99,100,100,100,100,100,100,100,100,99,100,100,100,100,100,92,100,100,93,99,96,100,100,100]}}
2026-07-22 18:57:00.198  dzVents: meteo: openurl called
2026-07-22 18:57:00.507  dzVents: meteo: Could get data from website 
2026-07-22 18:57:00.508  dzVents: meteo: {"latitude":51.466,"longitude":5.4519997,"generationtime_ms":0.08022785186767578,"utc_offset_seconds":7200,"timezone":"Europe/Amsterdam","timezone_abbreviation":"GMT+2","elevation":39.0,"hourly_units":{"time":"iso8601","shortwave_radiation":"W/m²","cloud_cover":"%"},"hourly":{"time":["2026-07-22T18:00","2026-07-22T19:00","2026-07-22T20:00","2026-07-22T21:00","2026-07-22T22:00","2026-07-22T23:00","2026-07-23T00:00","2026-07-23T01:00","2026-07-23T02:00","2026-07-23T03:00","2026-07-23T04:00","2026-07-23T05:00","2026-07-23T06:00","2026-07-23T07:00","2026-07-23T08:00","2026-07-23T09:00","2026-07-23T10:00","2026-07-23T11:00","2026-07-23T12:00","2026-07-23T13:00","2026-07-23T14:00","2026-07-23T15:00","2026-07-23T16:00","2026-07-23T17:00"],"shortwave_radiation":[148.0,228.0,68.0,21.0,5.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,5.0,59.0,103.0,143.0,109.0,174.0,596.0,727.0,734.0,639.0,550.0],"cloud_cover":[99,100,100,100,100,100,100,100,100,99,100,100,100,100,100,92,100,100,93,99,96,100,100,100]}}
2026-07-22 18:58:00.245  dzVents: meteo: openurl called
2026-07-22 18:58:00.551  dzVents: meteo: Could get data from website 
2026-07-22 18:58:00.551  dzVents: meteo: {"latitude":51.466,"longitude":5.4519997,"generationtime_ms":0.08940696716308594,"utc_offset_seconds":7200,"timezone":"Europe/Amsterdam","timezone_abbreviation":"GMT+2","elevation":39.0,"hourly_units":{"time":"iso8601","shortwave_radiation":"W/m²","cloud_cover":"%"},"hourly":{"time":["2026-07-22T18:00","2026-07-22T19:00","2026-07-22T20:00","2026-07-22T21:00","2026-07-22T22:00","2026-07-22T23:00","2026-07-23T00:00","2026-07-23T01:00","2026-07-23T02:00","2026-07-23T03:00","2026-07-23T04:00","2026-07-23T05:00","2026-07-23T06:00","2026-07-23T07:00","2026-07-23T08:00","2026-07-23T09:00","2026-07-23T10:00","2026-07-23T11:00","2026-07-23T12:00","2026-07-23T13:00","2026-07-23T14:00","2026-07-23T15:00","2026-07-23T16:00","2026-07-23T17:00"],"shortwave_radiation":[148.0,228.0,68.0,21.0,5.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,5.0,59.0,103.0,143.0,109.0,174.0,596.0,727.0,734.0,639.0,550.0],"cloud_cover":[99,100,100,100,100,100,100,100,100,99,100,100,100,100,100,92,100,100,93,99,96,100,100,100]}}
2026-07-22 18:59:00.288  dzVents: meteo: openurl called
2026-07-22 18:59:00.563  dzVents: meteo: Could get data from website 
2026-07-22 18:59:00.564  dzVents: meteo: {"latitude":51.466,"longitude":5.4519997,"generationtime_ms":0.058770179748535156,"utc_offset_seconds":7200,"timezone":"Europe/Amsterdam","timezone_abbreviation":"GMT+2","elevation":39.0,"hourly_units":{"time":"iso8601","shortwave_radiation":"W/m²","cloud_cover":"%"},"hourly":{"time":["2026-07-22T18:00","2026-07-22T19:00","2026-07-22T20:00","2026-07-22T21:00","2026-07-22T22:00","2026-07-22T23:00","2026-07-23T00:00","2026-07-23T01:00","2026-07-23T02:00","2026-07-23T03:00","2026-07-23T04:00","2026-07-23T05:00","2026-07-23T06:00","2026-07-23T07:00","2026-07-23T08:00","2026-07-23T09:00","2026-07-23T10:00","2026-07-23T11:00","2026-07-23T12:00","2026-07-23T13:00","2026-07-23T14:00","2026-07-23T15:00","2026-07-23T16:00","2026-07-23T17:00"],"shortwave_radiation":[148.0,228.0,68.0,21.0,5.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,5.0,59.0,103.0,143.0,109.0,174.0,596.0,727.0,734.0,639.0,550.0],"cloud_cover":[99,100,100,100,100,100,100,100,100,99,100,100,100,100,100,92,100,100,93,99,96,100,100,100]}}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

But now I get the error, but after that no issues, so it seems an issue on the server that has some issues sometimes:

Code: Select all

2026-07-22 19:00:01.307  Error: Error opening url: https://api.open-meteo.com/v1/forecast?latitude=51.46&longitude=5.45&hourly=shortwave_radiation,cloud_cover&forecast_hours=24&timezone=auto&tilt=55
2026-07-22 19:00:01.795  Error: dzVents: meteo: HTTP/1.1 response: 503 ==>> Service Unavailable
2026-07-22 19:00:01.796  Status: dzVents: meteo: Could not get (good) data from website 
2026-07-22 19:00:01.796  dzVents: meteo: {"error":true,"reason":"The service is overloaded"}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

i found a return that shouldnt be there .... and i added a os.execute("sleep 5") to get the https request out of the busy area around the vol minute.

Is there any other way to delay that period, for instance 30 seconds after the minute, and then every half hour?

Thanks for the help!
User avatar
waltervl
Posts: 7016
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by waltervl »

Do not use a sleep as it stalls Domoticz for 5 seconds!

I think you can use afterSec(5) so

Code: Select all

domoticz.openURL(---).afterSec(5)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 318
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Problem with accessing https://api.open-meteo.com/

Post by hjzwiers »

Perfect, it working!
Post Reply