NWS Integration API Key - Where to obtain ley?

Hello,

The default Meteorologisk weather integration does not work well at all. For example, it reports it is currently 73.9F when it is in fact 29F. Yes, I am sure I have the correct coordinates defined in my configuration. I’ve been trying to integrate an alternative that still provides a free API. I’m attempting to integrate National Weather Service (NWS). The problem is that when I go to add the integration it requires an API Key. But going to the NWS webiste (https://www.weather.gov/documentation/services-web-api) , I can find nowhere on their site how one obtains a key. In fact, the only reference to a key on the page states an API key will replace the “website or email” in the future. Currently, simply using https://api.weather.gov/points/{latitude},{longitude} returns a JSON response, without a key. Is the integration no longer supported?

Authentication
A User Agent is required to identify your application. This string can be anything, and the more unique to your application the less likely it will be affected by a security event. If you include contact information (website or email), we can contact you if your string is associated to a security event. This will be replaced with an API key in the future.

Integration prompt in HA
Selection_220
Thank you

Update:

I sent an email to NWS’ support asking about how to obtain an API Key from/for the National Weather Service (NWS) API. This is the response I got back:

I am going to forward your request to our Branch that handles the API. They should respond back to you.

Thanks
Tech Control / SEC

A short time later this response…

At this time no key is required. The only requirement for access is that machine-machine requests need to send a UserAgent string. We ask that you include identifying information like an email address in case there are any problems it is easier to track it down.

Joshua Huber
NCEP Central Operations
Onboarding Team Lead
301.323.3581

As far as I remember (and was told directly by the integration author in september) the API can be anything right now. Unless something has changed since then just try putting something in there and see what happens.

@finity

Well heck, I entered 1234567890 for the API Key and voila, data. I guess I should have tried a random number but who’d of thought? Thanks again!

2 Likes

Yeah, I tested it again right after I posted and literally put “something” in and it worked. :laughing:

I looked at the NWS Addon (https://github.com/home-assistant/core/tree/dev/homeassistant/components/nws) to see if I could perhaps create a pull request to make the API Key not required at setup but it looks like it uses an external SimpleNWS python library. I’m not much/if at all a python coder so my journey ends there. But at least it’s only a simple matter of entering in whatever you want. Sad thing is others wanting to use the addon that will find the same speed bump.

I agree.

Maybe the author could put some additional instruction in the ui confug box that the api key can be anything for now.

That should be easy to implement and minimize confusion.

Everyone should have their own user key, or else we will overrun their api limits as a collective. A randomly generated key would solve this, but it also seems to go against the guidance provided. I think the current state is the most aligned it can be with the NWS api guidelines while not causing issues with too many requests from a single user key.

If you think the documentation could be improved in some way, PRs are welcome.

@MatthewFlamm

Everyone should have their own user key, or else we will overrun their api limits as a collective. A randomly generated key would solve this, but it also seems to go against the guidance provided.

I don’t disagree. The challenge is that to ensure randomness, it would have to be part of the addon and not left to the installer. Having said that, according to the response I got back from the National Weather Service (NWS) tech support they state an API key isn’t necessary or even used. So I don’t see that the API would be overrun with the use of a single or common key used by many users.

I think the current state is the most aligned it can be with the NWS api guidelines while not causing issues with too many requests from a single user key.

I’m not sure I understand your statement.

If you think the documentation could be improved in some way, PRs are welcome.

Documentation could be updated to be more clear on the fact that the NWS API does not currently require an API. And that a “random” string of any kind will satisfy the addon installation. Perhaps include a command line (one liner) to create a random string for the API Key that would help ensure randomness of the keys. But again, I don’t think this will have any end impact on the API. And if/when they start requiring an API Key, the key used to install the addon will no longer work and the addon will break.

I’m happy to amend the documentation.

This is true that you don’t need an API key that is registered with NWS, but you still need to provide a “User-Agent”. If you do not, you get permission denied errors. I do not see anything in their response that indicates that they do not use the “User-Agent” string provided. In fact, the part where they say that they recommend an email address in case there is a problem indicates , to me, that they might shut down access for a user-agent in case of too many requests (this isn’t clear, but it is always a possibility). This is how I interpret it.

I took the clearest path and followed their own guidance to allow users to put in an email address or whatever they want.

done -

OOPS!

I updated the wrong spot. So I’ve closed that one and opened another - Update strings.json to clarify the requirements for the API key by finity69x2 · Pull Request #44143 · home-assistant/core · GitHub

1 Like

@MatthewFlamm

Thanks for that clarification. As the developer of the addon you would know best what responses you got back from the API calls in your development and testing. And you are correct regarding the NWS response and User-Agent.

@finity

Thank you for your quick PR. Me not being familiar with the HA source it would have taken me a long while to learn where/what to target for the update. Very much appreciated!

To comply and work in harmony with the tenant of the NWS API service and the HA Addon, I’ll uninstall and reinstall the addon and use my email address as the API Key.

Thanks again for everybody’s help and response. In my mind this is what makes HA superior and a joy to use, explore and contribute.

Best

Tony

1 Like