I setup this RESTful Sensors:
# Bundesliga
rest:
- resource: https://apiv3.apifootball.com/?action=get_events&from={{ (now() - timedelta(days = 1)).strftime('%Y-%m-%d') }}&to={{ (now() + timedelta(days = 1)).strftime('%Y-%m-%d') }}&league_id=175&APIkey=...
scan_interval: 300
timeout: 60
sensor:
- name: "Bundesliga Match #1"
json_attributes_path: "$.[0]"
json_attributes:
- league_name
- match_date
- match_time
- match_status
- match_hometeam_name
- match_hometeam_score
- match_awayteam_name
- match_awayteam_score
- match_live
- match_round
- match_stadium
- team_home_badge
- team_away_badge
- league_logo
- country_logo
value_template: >-
{%- if value_json[0].match_status != "" -%}
{{ value_json[0].match_status }}
{%- else -%}
coming
{%- endif %}
- name: "Bundesliga Match #2"
json_attributes_path: "$.[1]"
json_attributes:
- league_name
- match_date
- match_time
- match_status
- match_hometeam_name
- match_hometeam_score
- match_awayteam_name
- match_awayteam_score
- match_live
- match_round
- match_stadium
- team_home_badge
- team_away_badge
- league_logo
- country_logo
value_template: >-
{%- if value_json[1].match_status != "" -%}
{{ value_json[1].match_status }}
{%- else -%}
coming
{%- endif %}
- name: "Bundesliga Match #3"
json_attributes_path: "$.[2]"
json_attributes:
- league_name
- match_date
- match_time
- match_status
- match_hometeam_name
- match_hometeam_score
- match_awayteam_name
- match_awayteam_score
- match_live
- match_round
- match_stadium
- team_home_badge
- team_away_badge
- league_logo
- country_logo
value_template: >-
{%- if value_json[2].match_status != "" -%}
{{ value_json[2].match_status }}
{%- else -%}
coming
{%- endif %}
URL is working, I checked in devtools. Result is:
[
{
"match_id": "220790",
"country_id": "4",
"country_name": "Germany",
"league_id": "175",
"league_name": "Bundesliga",
"match_date": "2023-09-29",
"match_status": "",
"match_time": "20:30",
"match_hometeam_id": "170",
"match_hometeam_name": "Hoffenheim",
"match_hometeam_score": "",
"match_awayteam_name": "Borussia Dortmund",
"match_awayteam_id": "92",
"match_awayteam_score": "",
"match_hometeam_halftime_score": "",
"match_awayteam_halftime_score": "",
"match_hometeam_extra_score": "",
"match_awayteam_extra_score": "",
"match_hometeam_penalty_score": "",
"match_awayteam_penalty_score": "",
"match_hometeam_ft_score": "",
"match_awayteam_ft_score": "",
"match_hometeam_system": "",
"match_awayteam_system": "",
"match_live": "0",
"match_round": "6",
"match_stadium": "PreZero Arena (Sinsheim)",
"match_referee": "",
"team_home_badge": "https://apiv3.apifootball.com/badges/170_hoffenheim.jpg",
"team_away_badge": "https://apiv3.apifootball.com/badges/92_borussia-dortmund.jpg",
"league_logo": "https://apiv3.apifootball.com/badges/logo_leagues/175_bundesliga.png",
"country_logo": "https://apiv3.apifootball.com/badges/logo_country/4_germany.png",
"league_year": "2023/2024",
"fk_stage_key": "304",
"stage_name": "Current",
"goalscorer": [],
"cards": [],
"substitutions": {
"home": [],
"away": []
},
"lineup": {
"home": {
"starting_lineups": [],
"substitutes": [],
"coach": [
{
"lineup_player": "A. Tatar",
"lineup_number": "",
"lineup_position": "",
"player_key": "1578790261"
}
],
"missing_players": []
},
"away": {
"starting_lineups": [],
"substitutes": [],
"coach": [
{
"lineup_player": "H. Kolvidsson",
"lineup_number": "",
"lineup_position": "",
"player_key": "152987288"
}
],
"missing_players": []
}
},
"statistics": [],
"statistics_1half": []
}
]
Unfortunately the sensors are all status “unknown” and no attribute gets added to the sensors. What am I doing wrong? Log entry is: “REST result could not be parsed as JSON”.
I know only the first sensor will/should get valid value for the posted result.