Help with formatting "Payload" results from a Restful service call

I’m tired of battling with the NWS integration in HA. It’s never worked well and is now broken again, so I’d like to bypass it completely and just get the data directly from NWS.

I can get the full forecast I need from this service call

https://api.weather.gov/gridpoints/BOI/110,92/forecast

However I’m not sure how I would get the resulting output into Sensor I can then use. I want to extract the very first detailedForecast text from this output at all times.

        "periods": [
            {
                "number": 1,
                "name": "Tonight",
                "startTime": "2024-06-23T22:00:00-06:00",
                "endTime": "2024-06-24T06:00:00-06:00",
                "isDaytime": false,
                "temperature": 59,
                "temperatureUnit": "F",
                "temperatureTrend": "",
                "probabilityOfPrecipitation": {
                    "unitCode": "wmoUnit:percent",
                    "value": null
                },
                "windSpeed": "12 mph",
                "windDirection": "NW",
                "icon": "/icons/land/night/skc?size=medium",
                "shortForecast": "Clear",
                "detailedForecast": "Clear, with a low around 59. Northwest wind around 12 mph, with gusts as high as 21 mph."
            },

Anyone have any clues as to how I might go about this? All my wall displays and dashboards use this text and are stuck on data from last week, so it’s time to brute force it.

Definitive guide to Weather integrations 🌦.

Yeah, I saw that. Not helpful for what I’m trying to do…

I set this up (copied it from another I had created) and it calls the data, but how do I extract the correct value using the payload? There are multiple objects returned and I only want the first one…

rest_command:
  detailed_forecast:
    url: https://api.weather.gov/gridpoints/BOI/110,92/forecast
    method: GET
    content_type: application/json
    payload: '{"cmd":"notify","data" {"detailedForecast":"{{detailedForecast}}"}}'

I ended up with this and it works great

rest:
  - resource: https://api.weather.gov/gridpoints/BOI/110,92/forecast
    scan_interval: 14400
    method: GET
    sensor:
      - name: "Detailed Forecast"
        value_template: "{{ value_json.properties.periods[0].detailedForecast }}"
        unique_id: detfor

Thanks to @petro on Discord. Much appreciated!

This works great except when the detailed forecast is greater than 255 characters. Can someone provide the syntax needed to store the forecast in a json_attribute? I haven’t had any success trying to change the sensor.

Figured it out. I also set the state to be the time of the forecast.


rest:
  - resource: https://api.weather.gov/gridpoints/GYX/37,26/forecast
    scan_interval: 14400
    method: GET
    sensor:
      - name: "Detailed Forecast"
        value_template: "{{ value_json.properties.periods[0].startTime }}"
        json_attributes_path: "$.properties.periods[0]"
        json_attributes:
          - "detailedForecast"
        unique_id: detfor

I don’t know why it’s so hard for folks to make the NWS integration actually work when we can query the API like this and it works every time.

That info doesn’t exist everywhere. It’s completely absent from my region via the api.

So how did you get this all to work? The steps like actually installing REST and the layering in the config.yaml since you have to watch out for multiple uses and therefore combine in proper sequence.

Rest is already built into HA. You just need to add the sensor or sensors into configuration.yaml

https://www.home-assistant.io/integrations/rest/