Setting up NWS since Dark sky is going away

You’re welcome!

Please mark my previous post with the Solution tag. Only you, the author of this topic, can do that. It will automatically place a check-mark next to the topic’s title which signals to others that this topic has an accepted solution. It will also automatically place a link beneath your first post that leads to the Solution. All of this helps others, who may have a similar question, find the answer.

So here is my working template setup for 2 days. If someone wanted to adapt this to their own setup, the would just need to change the ‘weather.kmmk’ to whatever their nws location is. I could probably add Friendly Names to everything in the next revision,

sensor:
  - platform: template
    sensors:
############ Current Temp and Humidity #################
      nws_currenttemp:
        value_template: "{{states.weather.kmmk.attributes.temperature}}"
        unit_of_measurement: 'degrees'
      nws_currenthumidity:
        value_template: "{{states.weather.kmmk.attributes.humidity}}"
        unit_of_measurement: 'percent'

################### Today Metrics ########################
      nws_0d_hightemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[0].temperature }}"
        unit_of_measurement: 'degrees'
      nws_0d_lowtemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[1].temperature }}"
        unit_of_measurement: 'degrees'
      nws_0d_daydescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[0].detailed_description }}"
      nws_0d_nightdescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[1].detailed_description }}"
      nws_0d_conditions:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[0].condition }}"
      nws_0d_precipprob:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[0].precipitation_probability }}"
        unit_of_measurement: 'percent'

###################### Tomorrow Metrics #############################
      nws_1d_hightemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[2].temperature }}"
        unit_of_measurement: 'degrees'
      nws_1d_lowtemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[3].temperature }}"
        unit_of_measurement: 'degrees'
      nws_1d_daydescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[2].detailed_description }}"
      nws_1d_nightdescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[3].detailed_description }}"
      nws_1d_conditions:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[2].condition }}"
      nws_1d_precipprob:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[2].precipitation_probability }}"
        unit_of_measurement: 'percent'      

#################### Day After Tomorrow Metrics #######################
      nws_2d_hightemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[4].temperature }}"
        unit_of_measurement: 'degrees'
      nws_2d_lowtemp:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[5].temperature }}"
        unit_of_measurement: 'degrees'
      nws_2d_daydescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[4].detailed_description }}"
      nws_2d_nightdescription:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[5].detailed_description }}"
      nws_2d_conditions:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[4].condition }}"
      nws_2d_precipprob:
        value_template: "{{ state_attr('weather.kmmk', 'forecast')[4].precipitation_probability }}"
        unit_of_measurement: 'percent'      

6 Likes

Day and night swap positions depending on what it is currently. In not sure how you want to handle this. There is a daytime attribute.

I thought i understood what you were saying initially, but trying to work my brain around it just confused me. Can you give an example of what you are talking about?

For example, right now forecast[0] is today, forecast[1] is tonight, and forecast[2] is tomorrow day. In about 8 hrs, it will be night, then forecast[0] is the night forecast, forecast[1] is tomorrow day, and forecast[2] is tomorrow night.

nws_0d_hightemp:
  value_template: "{{ state_attr('weather.kmmk', 'forecast')[0].temperature }}"
  unit_of_measurement: 'degrees'
nws_0d_lowtemp:
  value_template: "{{ state_attr('weather.kmmk', 'forecast')[1].temperature }}"
  unit_of_measurement: 'degrees'

I may have a fix for this, modified the existing NWS integration:

Dump this into a custom_component directory, ie: ha-nws

Then in your configuration.yaml:

weather:
  - platform: ha-nws
    api_key: <your email address>

This works if you do not care about the weather forecast at night except for the temperature. If you have a snowstorm only at night, you’ll never see it in your forecast.

If there is strong appetite for this, we could add a third mode, daily, that does something like this. I still don’t know what to do with the condition and detailed description in this case, unless they are discarded. Also doesn’t seem great.

The ideal situation IMO is to get day and night supported on the frontend.

I would love to see a third option for daily. What can I do to help?

As @firstof9’s code shows, it is a somewhat fairly small change to add the low temperature to get home assistant to recognize it as daily. However, more than half the forecast is still discarded this way. What to do with it? If it is simply discarded, important weather info may be lost.

This is what I need help on.

I’m going to create a new thread on this since we are veering away from the original topic.

It was a quick and dirty solution, could dump the overnight forecast into the main forcast as well prefixed with “Tonight…”

Wow - it’s amazing to see this thread has expanded. Sorry for not responding sooner. @MatthewFlamm what can I do to help make the integration better? Do I need to make a github issue?

Be safe out there!

I suppose we can keep it going here. Merging the detailed description makes sense, but what about the state itself, e.g. sunny vs snowy. This one simply cannot be combined and one or the other must be discarded.

I wondering why it needs to be merged at all. Would it be possible to just prevent the flipping until the next day? So 0 stays daytime and 1 stays nighttime and that gets replaced. 2 and 3 would always be tomorrow day and night, respectively, and so on. Wouldn’t that completely resolve the merging of the detailed and condition attributes?

Then the frontend display using weather card is no good.

I think I understand. Would it be possible to modify the name of the attributes to add day and night. So Day_Condition and Night_Condition. Day_Detailed_Description and Night_Detailed_Description?

We’d have to break it out into individual sensors like the Dark Sky integration, which I was planning to do eventually if someone else didn’t :stuck_out_tongue:

This I was planning to use myself as a stop gap till then.

My use case is very simple, I use the custom weather card with animated icons.
When using the 5 day forecast with NWS I get 2 Thu, 2 Fri and 1 Sat. (I understand why)
When using Darksky I get highs and lows for the next 5 days.
That’s all I want/need.

My little hack provides the 5 day forecast.

1 Like