US NWS weather observations and forecast

The hour delay issue is indeed a concern. I wish NWS offered point quasi-observations on the grids instead of just hourly forecasts. Maybe they do but I haven’t found them. Then we could use their models more directly for more real-time info. I guess this was the value darksky was bringing?

Anyway I do have it working now locally with the first forecast replacing the observation (plus a few unit conversion hacks) and am playing around with testing and am comparing results to the NWS direct API calls and with the DarkSky integration at the moment. Can publish as a custom component if you prefer.

One thought to look into. There is also a raw data forecast endpoint for the grid forecasts. When I looked, it has similar data to the hourly, but not as convenient for HA use but maybe it is better for this particular use case? Unfortunately this endpoint isn’t yet supported in pynws.

I do think there is precedence for other weather APIs in home assistant to use this strategy of using the first hourly forecast to be the observation. So I don’t think this is a non starter. It would be good to understand the implications before added to the core code however.

Do you find the NWS servers reliable? I switched over from Darksky on Friday and the NWS server has consistently given me a 503 ever since Saturday morning.

It is mostly reliable in my experience. It does have outages though, both temporary and sometimes extended.

Are you in the US? Have you gotten any weather data at all? It is fairly common in my experience to have short periods of not being able to retrieve data.

There is a new PR that is going to drastically update the ha code to hopefully output less error messages (only once per disconnection and one per reconnection).

I think I am in the US although many people don’t realize NM is a state, lol
I’m not getting the forecast info. Have tried both within HA and on browser, same result.
Do see the forecast info when I go to forecast.weather.gov but not via the api.

Have you tried slightly changing your latitude and longitude? Do you know how to extract your weather forecast office and grid points from lat and Lon? Have you tried adjusting these?

Maybe they don’t report forecasts for top secret military base areas?

yes, yes & yes…I’ve tried 3 big cities with no luck.
I think they shut off the server for the week-end.

Mine is working fine. Likely your whole weather forecast area doesn’t work right now.

I would like to show both the hourly and the daily forecast. Is there a way to do that?

You may need to adapt it slightly, but this is the idea below. This all changes in the next version when it is converted to a config flow according to the recent home assistant decision. So be on the lookout for the breaking change upcoming!

weather:
  - platform: nws
    api_key: YOUR_API_KEY
    mode: hourly
    name: hourly
  - platform: nws
    api_key: YOUR_API_KEY
    mode: daynight
    name: daynight

PS welcome to the forum!

Appreciate your work on this integration @MatthewFlamm!

Would you consider adding the name attribute that the API outputs to your detailedForecast attribute for the daily entity?

For example, the NWS API returns this for my local forecast:

        "periods": [
            {
                "number": 1,
                "name": "Today",     <------------  THIS
                "startTime": "2020-07-13T11:00:00-05:00",
                "endTime": "2020-07-13T18:00:00-05:00",
                "isDaytime": true,
                "temperature": 101,
                "temperatureUnit": "F",
                "temperatureTrend": null,
                "windSpeed": "10 mph",
                "windDirection": "S",
                "icon": "https://api.weather.gov/icons/land/day/hot?size=medium",
                "shortForecast": "Sunny",
                "detailedForecast": "Sunny, with a high near 101. Heat index values as high as 112. South wind around 10 mph."
            },
            {
                "number": 2,
                "name": "Tonight",         <------------  THIS
                "startTime": "2020-07-13T18:00:00-05:00",
                "endTime": "2020-07-14T06:00:00-05:00",
                "isDaytime": false,
                "temperature": 76,
                "temperatureUnit": "F",
                "temperatureTrend": null,
                "windSpeed": "5 to 15 mph",
                "windDirection": "S",
                "icon": "https://api.weather.gov/icons/land/night/few?size=medium",
                "shortForecast": "Mostly Clear",
                "detailedForecast": "Mostly clear, with a low around 76. Heat index values as high as 110. South wind 5 to 15 mph."
            },

Sometimes the API returns special names like “Independence Day” or “Christmas Day”, so it would be great to have this in the entity’s attributes. Before you released the official integration, I had hacked together my own that had each forecast day as an entity, and I have a TTS automation that reads out the period name and the forecast, eg: “The forecast for Independence Day is …”

I can write some jinja to extract everything from the attributes available through your integration but I’d love to still be able to hear what the name attribute is in my TTS readouts!

The is easy enough to add, but I’m not sure if home assistant prefers to add all possible attributes to entities like this. It adds unnecessary data for the vast majority of people. I don’t really have a preference if it is in there or not, but I think we’d need guidance on the policy. Since it sounds like you are familiar with python and homeassistant development, you can submit a PR, and then we can ask whether this is a welcome attribute.

Completely understandable, and it’s no big deal, honestly - I’m probably a very rare use case. I can continue to use my custom integration as it’s been working for me for a long time. Thanks!

You can also always download the current files and modify them to create your own custom component. All you need to add is one line.

1 Like

@MatthewFlamm Thanks for the NWS integration. I’ve been using it for awhile to get the day/night updates. Today I noticed in AdGuard it’s calling every 10 minutes, so I looked at the files to see it has a DEFAULT_SCAN_INTERVAL of 10 minutes. Could that be exposed as a configurable option for users?

This is fine with me. Pull Requests are welcome if you are capable. If so, we should pin the allowable range for the user to be no more frequent than once a minute.

I would note for completeness that the integration normally polls every 10 minutes, but upon a failed update, it will try to update every minute.

Another workaround is that you can call the homeassistant.update_entity service for the entity (ies) of interest. You can even set up an automation to do this every 2 minutes or whatever. The minimum time it will update is 1 minute.

I wanted my choice of weather card to display the NWS daily forecast data correctly so I forked bramkragten/weather-card and made it display the NWS data accordingly. It can be found here. I requested a purge for https://cdn.jsdelivr.net/gh/Wetzel402/weather-card-nws/dist/ but that hasn’t happened yet so if installed via HACS the icon for exceptional weather will not display.