Ress sensor attributes list

Hi,

I have an api that returns a list of json objects.

Example: [
  {
    "EventType": "Liiga",
    "HomeTeam": "KalPa",
    "AwayTeam": "Ilves",
    "Start": "2024-12-05T16:30:00Z"
  },
  {
    "EventType": "Liiga",
    "HomeTeam": "Kärpät",
    "AwayTeam": "Ilves",
    "Start": "2024-12-07T15:00:00Z"
  },
  {
    "EventType": "Liiga",
    "HomeTeam": "Ilves",
    "AwayTeam": "SaiPa",
    "Start": "2024-12-09T16:30:00Z"
  },
  {
    "EventType": "Liiga",
    "HomeTeam": "JYP",
    "AwayTeam": "Ilves",
    "Start": "2024-12-11T16:30:00Z"
  },
  {
    "EventType": "Liiga",
    "HomeTeam": "TPS",
    "AwayTeam": "Ilves",
    "Start": "2024-12-13T16:30:00Z"
  },
  {
    "EventType": "Liiga",
    "HomeTeam": "K-Espoo",
    "AwayTeam": "Ilves",
    "Start": "2024-12-14T15:00:00Z"
  }
]

I’ve added them as attributes to a rest sensor.
I’m struggling to get the list of objects into a template and iterate.

This works to get the first item:

- platform: rest
    name: liiga1
    resource: http://x.x.x.x:8081/liiga?teams=team&weeks=weeks
    value_template: '1'
    json_attributes_path : '$.[1]'
    json_attributes:
      - EventType
      - HomeTeam
      - AwayTeam
      - Start

Since the number of items on that list is changing, I would rather just loop through it.
Is that possible?

Thanks,
Heikki

You cannot loop on attribute level.
You can

  • create multiple sensors with [0], [1], etc…this you already seem to know :slight_smile:
  • try to load the whole ‘example’ as an attribute and work your way through from the card-side (flextable/markdown)
  • use command_line with JQ to make something readable, donot know your target though