hello,
I am trying to get football score from air using the below template but it keep giving me the below error
Invalid config for [sensor.rest]: template value should be a string for dictionary value @ data[‘headers’][‘json_attributes’]. Got [‘api’]. (See ?, line ?).
template sensor is
- platform: rest
name: Team 2929 Goals
resource: https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4
method: GET
scan_interval: 3600 # Set the update interval in seconds (e.g., every hour)
value_template: "{{ value_json[api.statistics[0].team_name] }} Goals: {{ value_json[api.statistics[0].goals.for] }}"
headers:
X-RapidAPI-Host: api-football-v1.p.rapidapi.com
X-RapidAPI-Key: YOUR_API_KEY # Replace with your actual API key
json_attributes:
- api
According to the documentation, the example you posted contains incorrect indentation.
It should look like this:
- platform: rest
name: Team 2929 Goals
resource: https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4
method: GET
scan_interval: 3600 # Set the update interval in seconds (e.g., every hour)
value_template: "{{ value_json[api.statistics[0].team_name] }} Goals: {{ value_json[api.statistics[0].goals.for] }}"
headers:
X-RapidAPI-Host: api-football-v1.p.rapidapi.com
X-RapidAPI-Key: YOUR_API_KEY # Replace with your actual API key
json_attributes:
- api
It was due to incorrect indentation which is solved by the example I posted above.
The sensor’s inability to report “other attributes” is a separate problem. The configuration you created for value_template and/or json_attributes may be incorrect.
In order to help you, I would need to see an example of the JSON data reported by https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4. Alternately, is this sensor’s configuration based on an example you saw elsewhere?
I suggest you remove the json_attributes option from the sensor’s configuration.
EDIT
Are you certain that the data example you posted is correct? It doesn’t even have a statistics key or team_name or goals yet all three are referenced by your value_template option: