US NWS weather observations and forecast

I have an NWS weather platform (component? integration?) ready for testing and feedback.

You can put the files into: config_path/custom_components/nws

Sample config:

  - platform: nws
    api_key: email_address

api_key can be any string, but it is recommended to include an email address. The forecast is only day+night right now, although I’m working on adding hourly. The weather component (platform?) frontend currently doesn’t support day+night well, so it will display with timestamps as if hourly. See next post for the status of frontend changes if I can figure out how to make it a custom card.

One can also specify a name, latitude, longitude, or specific station as options. The station is for the current conditions, and the component will use the closest station if not specified. A list of nearby stations is printed in the logs with level INFO if no station is specified. They can also be found, although I don’t know of any convenient page, on the website. The forecast is generated by the lat/lon point (or default lat/lon).

  - platform: nws
    api_key: email_address
    latitude: 38.85
    longitude: -77.03
    station: KADW
    name: DC weather

Custom card info to come later if I can figure it out.

So far I can’t figure it out. It doesn’t seem like one can drop in a slightly modified existing card as a custom card without significant rewrite, although I hardly know any javascript to really tell.

1 Like

Nice Job. Works great for me.

Thanks for the feedback! I’m going to push in the hourly forecast soon (in a few days if I get time to finish). I will post here when I do.

My plan is to submit this as a PR to be a new integration natively in HA once it can be tested with hourly forecasts.

Count me in as a tester.

I pushed a new version with hourly forecast. You can use it with:

- platform: nws
  mode: hourly

The mode can also be daynight, which is the default.

New version works good… Now I can’t decide whether to use the hourly or the default…

I’m finalizing putting in some tests and then will submit a PR. One thing that needs to be addressed, probably in a follow-up PR, is to disregard data received that is reported to be poor quality and fall back to a previous value.

I’ve managed to splice this into hassio, to give it a try. It works mostly, except day and night get out of phase (hourly mode was fine):


If the 6a.m. Was labeled ‘daytime high’ and 6pm was labeled ‘nighttime low’, it would maybe make more sense.

The problem is that the Lovelace weather card only supports two modes well, one forecast daily or ‘hourly’. This one gets treated as hourly, so the hours are displayed. What you are noticing is that the forecast for the current day keeps increasing the hour until it is night.

I have a modified weather card as in my second post that fixes this issue, but I need to wait for the nws weather platform to be integrated to submit a PR. No other weather platform to my knowledge provides data in this format (one forecast for day, one forecast for night). All others have one forecast for both, but report a low temperature overnight in that forecast.

Also, thanks for the feedback! I’m nearing completion on submitting the PR. I have to consider how to approach the card changes, either in parallel or subsequently. I fear too many change requests at once will bog down the developers during review, but as you are pointing out, it is confusing in it’s current state.

@MatthewFlamm. Thanks for responding, and thanks for your work on this. If it’s reasonable, I would be interested in a “daily” mode that looks more like the standard weather card (five days out, daily high and low temp in over/under format).

I had considered this. It isn’t straightforward however. What do you do if the forecast for the day is Sunny, but the forecast for the night is Snowy? A lot of subjective decisions need to be made. I also have the weather forecast description as a forecast attribute, we’d have to somehow combine them together in a sensible way. In my experience, you wouldn’t want to simply discard the night forecast entirely.

I suggest that once the current modes are merged, someone can add a third mode ‘daily’ by accounting for these issues. Or, if someone wanted to lay out a path forward on most of the thorny decisions, I can do the code changes easily.

I have updated the repo to work with metric and bring it even with the PR I submitted.

I’ve updated the repo to use the raw metar code as a fall back when the weather API data is missing. There are some stations where this seems to be essential.

Updated platform to handle cases where both the base API and metar code are missing data.

Just updated to Hassio 94.0 Seems to have broken your code…

Log Details (ERROR)

Wed Jun 05 2019 23:44:43 GMT-0400 (Eastern Daylight Time)
Error while setting up platform nws
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/”, line 126, in _async_setup_platform
File “/usr/local/lib/python3.7/asyncio/”, line 416, in wait_for
return fut.result()
File “/config/custom_components/nws/”, line 136, in async_setup_platform
from pynws import Nws
ModuleNotFoundError: No module named ‘pynws’

hmmmm… It works just fine on my end. What makes me think this is not a code issue is that it can’t import the package dependency, but you already had it installed and working on the previous version.

I am also not using hassio. I see a few breaking changes related to hassio and package management therein, which might be related. Can you try the age old trick of restarting?

I will try to see if there are any changes needed to work with hassio.

I have re started numerous times with no changes in the errors.