REST-API Sensor for OpenligaDB

Hello,

I’m new to the forum and have a problem/question. I’d like to save the content of a REST API into a state, similar how team tracker plugin. I set up the following sensor in configuration.yaml:

sensor:  
  - platform: rest
    name: bund1_table
    unique_id: bund1_table
    scan_interval: 3600
    resource: https://site.web.api.espn.com/apis/v2/sports/soccer/ger.1/standings?type=0&level=0&lang=de
    value_template: "{{ now() }}"
    json_attributes_path: "$['children'][0]['standings']"
    json_attributes:
      - entries
  - platform: rest
    name: bund3_table
    unique_id: bund3_table
    scan_interval: 3600
    resource: https://api.openligadb.de/getbltable/bl3/2025
    value_template: "{{ now() }}"
    json_attributes_path: "$"
    json_attributes:
      - ""

"bund3_table" isn't working, but "bund1_table" not. They are different addresses, Can anyone help me for "bund3_table" to make it work?

What information are you looking for from bund3?

All Informations from the api/json to display the table from the ligue

Looks like grabbing a list as an attribute directly with a rest sensor is not possible.

You could use a command_line sensor with a curl to achieve this.
Idea is to transform the output into something like:

{
  "result": [
    {
      "teamInfoId": 36,
      "teamName": "VfL Osnabrück",
      "shortName": "Osnabrück",
      "teamIconUrl":   "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/VfL_Osnabrueck_Logo_2021%E2%80%93.svg/960px-VfL_Osnabrueck_Logo_2021%E2%80%93.svg.png",
      "points": 80,
      "opponentGoals": 34,
     "goals": 66,
      "matches": 38,
      "won": 24,
      "lost": 6,
      "draw": 8,
      "goalDiff": 32
    },
    {
      "teamInfoId": 93,
[...]
}

to be able to do

json_attributes:
  - result

Thank for your reply. Why does a rest not work? With the other is work fine. How must/can a command line sensor work?

Because, as you noticed, the resulting json is an array at root, and, according to what I get from the actual code, this is not handled by HA. HA wants a dictionary as a result from the json_attributes_path from which it can extract the attributes.

Ok, that a shame to hear this. And how can i managed with command line?

Use this command to generate the json as outlined above:

curl https://api.openligadb.de/getbltable/bl3/2025 | jq '{ result: . }'

I add this to my configuration, It is right? But the state is empty. In ssh it is work.

command_line:
  - sensor:
      name: bund3_table
      unique_id: bund3_table
      scan_interval: 3600
      icon: "mdi:soccer"
      command: >-
        curl "https://api.openligadb.de/getbltable/bl3/2025" | jq '{ result: . }'
      command_timeout: 30 

Add

    value_template: "{{ now() }}"
    json_attributes:
      - result

Thank you. That work for me :+1:

Have you please an ideo to display the position/number of the array, when i use the flex-table-card?

type: custom:flex-table-card
entities:
  include: sensor.bund3_table
columns:
  - name: Place
    data: result
    modify: x.???
  - name: Team
    data: result
    modify: x.teamName
  - name: P
    data: result
    modify: x.points
  .....
strict: true
css:
  tbody td:nth-child(8)+: "width: 40px;"

in the column "Place" the position in the array, also 1,2,3...

Does anyone have an idea how to display only the entry's position as information? Here is the requirement:

Pl                   Team                  P
1                    BVB                   78
2                    FCK                   75
3                    FCB                   73
4                    BMG                   69
.........

The values are in the array only the Pl(Place) is missing.

use :

curl https://api.openligadb.de/getbltable/bl3/2025  | jq '[sort_by(.points) | reverse | to_entries[] | {rank: (.key + 1)} + .value] | { result: . }'

to sort the array and add the indesx (as rank).

Thanks Claude for the syntax

Perfect :+1: