Accessing nested data in JSON returned to a sensor (adding forecast to Weather Underground)

So looking at the Weather Underground sensor, I want to extend it to include forecast data (which I did before it was integrated into HASS, and now it’s changed). In the JSON returned from WUnd, all of the existing monitored conditions are on the top level under current_observation. But the forecast data I want to get at is in a dict in a list in a dict, for example:

"current_observation": {
  "temp_f":58.7,
  ...
}
"forecast":{
    "txt_forecast": {
        "forecastday": [
            { "fcttext":"Cloudy early",
   ...
}

So the question is, what’s the blessed way to get at that data in HASS, and add it to SENSOR_TYPES? Maybe smoosh the data up to the top level in the update function so that we can add it to the allowed SENSOR_TYPES and address it without any dots or anything? (before HASS integration I was using a template to get at states.sensor.weather_underground_pws.attributes.txt_forecast.forecastday.0.fcttext)

2 Likes

Hello @AlucardZero,
I’ve asked myself this question and I decided to create a new dict to look up this information for the weather alerts.
Maybe there is a better way to do it, but it worked for me. The PR https://github.com/home-assistant/home-assistant/pull/3505/files is still waiting for to analyzed.

Thanks
mmello