Sensor attribute from list

So, wondering if there’s a way to configured a homeassistant sensor in esphome to pull attributes from a list? For a weather component I have a state, plus a long list of attributes, like such:

temperature: 90
humidity: 17
ozone: 286.49
pressure: 24.96
wind_bearing: 294.94
wind_speed: 6.622
visibility: 10
forecast: 
- datetime: '2022-06-18T00:00:00+00:00'
  temperature: 91
  precipitation: null
  condition: cloudy
- datetime: '2022-06-18T01:00:00+00:00'
  temperature: 90
  precipitation: null
  condition: cloudy

Wondering how I could pull the second temperature, and 3rd, and so on. Normally I’d use jq or yq on the command line, but that’s not possible here. Any idea?
Hopefully I don’t have to create a template sensor for each, in home-assistant.

You can get attributes in to homeassistant: Home Assistant Text Sensor — ESPHome

However I am not sure how to specify a nested attribute. If it is possible, perhaps something like [1].temperature, [2].temperature.

Hmm, good guess, but that didn’t work.

  in "/config/edsw.yaml", line 80, column 5:
      - platform: homeassistant
        ^
expected <block end>, but found '<scalar>'
  in "/config/edsw.yaml", line 82, column 19:
        attribute: [1].temperature
                      ^

Any other ideas?

If I had to guess it would be forecast[1].temperature because forecast is the name of the array.

hmm, good guess but still no love.
Tried forecast[1].temperature & forecast.[1]temperature.

For once in my life I actually wish the output was in JSON.

What if you only do forecast? do you get the whole array to the other side so you can parse it there?

Hm, that’s an option, wondering how I would parse out the individual hourly forecasts from that.

Wonder if a solution was found. :man_shrugging: I now also am trying to do similar to go through attribute sub keys / values to list on my esphome display.

did you find time to go look at the documents while also wondering? Seems like a good place to start. Mostly because it specifically talks about importing attributes and provides an example for importing a sensor attributes…

It works just fine with just adding one attribute from an entity. The question I had here was if the attribute had sub keys and you would
I have an energy entity. It has a lot of attributes some of them like the example below have sub key values like hour, price. Would like to enumerate over them somehow.

today_min:
hour: “2024-03-06T03:00:00+01:00”
price: 2.1
today_max:
hour: “2024-03-06T18:00:00+01:00”
price: 3.69

I was able to find quite a bit with a couple quick searches. They’re all pretty old going back to 2020,21’ and IDK if they still work. It sounds like the quickest/simplest way would be to break the attributes out of the sensor in HA and then make each of them their own sensor that you import into esphome.