OpenWeatherMap OneCall Invalid API-Key

Hi,
I have a Openhab3 installation and tried to integrate the OpenWeatherMap Binding to read information using the OneCall API.
I Subscribed to the OneCall Plan on their website and I am also able to receive data using the API call with a created key:

https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude={part}&appid=

Openhab Things Creation:

Bridge openweathermap:weather-api:api "OpenWeatherMap Account OneCall" [apikey="XXXXXXXXXXXXXXXXXXXX", refreshInterval=30, language="de"] {
    Thing onecall localWeather "Aktuelle Vorhersage" [location="50.990711,6.961780",forecastMinutes=0 , forecastHours=15, forecastDays=4] 
}

Unfortunately, when I create the Bridge and the OneCall Thing in Openhab, the bridge as well as the OneCall thing states change to “OFFLINE”.
In addition to that, I can find the following text in the openhab log (Invalid API-KEy, Error 401):

2022-08-21 10:59:38.823 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'openweathermap:onecall:api:local' changed from UNKNOWN to OFFLINE (CONFIGURATION_ERROR): Ungültiger API Schlüssel. Mehr Infos unter https://openweathermap.org/faq#error401.

Is someone familiar with this problem and can help me out? I would really love to use the OpenWeatherMap binding and weather data.
If you need any more data or logs to invastigate, just let me know.

Many thanks in advance,
Justus

Hi Justus,
welcome to the community :slight_smile:

When I configured OpenWheaterMap I had to wait a while until the thing went online. As I recall it needed nearly an hour.

Hi Stefan,
thanks for the quick answer.
I will wait for a few hours and hope for the best.

It would be great and frustrating at the same time if this would have been my only problem for the whole time. :sweat_smile:

All,
after waiting for a couple of hours, nothing changed in my case.
Additional steps I already tested all led to the same result:

  • Restarted Raspberry with Openhab3
  • Deleted and added both Things (OneCall Thing and OWM bridge)
  • Removed and added OpenWeatherMap Binding
  • Used Thing creation via MainUi insted of textual file creation

Are there any further ideas what could be the issue or what I could try?

Thanks

The steps I would check are:

  1. Ensure you have access to the service from your Raspberry (e.g. “ping openweathermap.org” on a shell). That should eliminate network issues.
  2. Create the openweathermap bridge via UI. Creating things that way is far less error prone than doing it in a textual file. (Saying that although I have everything else in files :wink: )
    It should look like this:
  3. Wait until the bridge is online. A bit of patience is needed.
  4. Proceed with implementing the things you need. In my case a “weather-and-forecast” thing:

    Ensure the correct parent bridge is selected. Normally you only have one and that one should be preselected automatically.

Thanks for the suggestion, below the results of the tests:

  1. Check Network connection (Manual API-Request in Raspberry Browser)


    I did another test and misspelled my API-Key on purpose to see the result

  2. Deleted all things from files and start all over using UI (everything left to default if possible)

  3. Waited for the new Bridge to be online, only took around a minute

  4. Added needed things again
    The strange thing is, when I create the “weather-and-forecast” as thing, everything works normal, bridge and thing are ONLINE afterwards.
    When I add the “onecall” thing in addition, the new added thing is first UNKNOWN and then changes to OFFLINE (CONFIGURATION_ERROR).
    The bridge and the regular “weather-and-forecast”-thing stay online.

After doing these tests, the situation looks to me like summarized below:

  • API-Key in general is working for OneCall API-Requests from the same raspberry (I can also see the number of received requests in my OWM-Account)
  • Bridge and Thing are correctly configured inside Openhab
  • Regular Requests are working just fine, only the ones using the OneCall App are returned with an error

Is it possible, that inside the Binding there is an error when creating the API-Request?
I don’t really have another idea anymore why the normal API request is working and the OneCall request not, knowing that my API-Key is subscribed to the OneCall API.

Has anyone ideas how I could test the behaviour of the binding or where I could take a look into the code?
I’ve never looked that deep into “system behaviour” until now tbh.

Thanks and kind regards
Justus

I remeber that the maximum forcast for a free key is 5 days.
Have you tried to set it to 5 days?
Your configuration shows 6 days.

Yeah, this was also something I played around with quite a long time.
Just did another test to be certain, it does not matter what I put in there.
Below a screenshot with Number of hours and Number of Days set to “1”.

Hm, I am out of ideas …
It’s very long ago since I installed OWM.
If I remember right I did not add any thing manually.
I think they came up automatically:

Screenshot 2022-08-21 at 19-21-29 openHAB

As you can see my things having “local” at the end, yours has just digits.
I don’t know if this makes any difference.

I picked my weather and forecast thing from the inbox, the same as Christian mentioned. If that does not lead to a functional situation, my next suggestion is to enable DEBUG log level for this binding. There is a chance that the issue can be narrowed down further that way.

Changing the log level for the binding to TRACE, I could see the actual request.
When I enter this link in a browser (with the actual AppId of course) I get the same message like shown in Openhab (“Invalid API key …” )

https://api.openweathermap.org/data/2.5/onecall?appid=*****&lon=6.959960&exclude=minutely%2Calerts&units=metric&lang=de&lat=50.974462

For reference, this is the template request from the OpenWeatherMap site:

https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude={part}&appid=

After further testing in a web browser I found out that the number “2.5” in the bindings API Request seems not to be correct anymore (at least in my case with a brand new subscription). When I change it to 3.0 like shown in the OpenWeatherMap template, I receive the complete list of Items in my browser.

Is there a way to change this in the binding somehow or is it possible the binding needs an update?
At the moment I’m just glad I found out what is wrong, it was my second open problem I diagnosed today :wink:

Congratulations :+1: Although you don’t have a solution or a workaround yet, you found the root cause.

If you can’t find an configuration to work around the issue, my advise is to check the existing issues at openhab-addons if there is already an issue matching your finding. If not, open one.

Can confirm, I have the same problem. I just created an account and my API-Key is valid only for /3.0/ API, not /2.5/ API.

I also just updated OpenHAB to 3.3 and I’m using the corresponding plugin version.

It would be fine if there was a way to modify the api version number directly.

Always good to hear that you are not the only one having a problem.
Thanks for creating the git issue.

Is there already a solution for this? Also running in the same issue, that the onecall thing does not “work” with my oh3 installation =)

Hi, I’ve put together a draft PR to allow the One Call version to be set in the open weather account thing settings.

@rossbuggins Can you download your binding version already? Im not quite familiar with github / dont find the download there :smiley:

It’s just been merged into main, so I think the latest version snapshot should have it - but just get someone else to confirm :+1:

Normally in tomorrow snapshot.