I am trying to pull nhl data into home assistant using their api and REST sensor. I am able to pull the data but do not know how to assign the values to different template sensors.
I have a sensor setup to just grab the away team name.
nhl_away_team:
value_template: '{{ states.sensor.nhl_game.attributes["dates"]["games"]["teams"]["away"]["team"]["name"] }}'
The JSON comes into the Rest Sensor nhl_game like this:
"dates" : [ {
"date" : "2019-12-01",
"totalItems" : 1,
"totalEvents" : 0,
"totalGames" : 1,
"totalMatches" : 0,
"games" : [ {
"gamePk" : 2019020416,
"link" : "/api/v1/game/2019020416/feed/live",
"gameType" : "R",
"season" : "20192020",
"gameDate" : "2019-12-01T20:00:00Z",
"status" : {
"abstractGameState" : "Final",
"codedGameState" : "7",
"detailedState" : "Final",
"statusCode" : "7",
"startTimeTBD" : false
},
"teams" : {
"away" : {
"leagueRecord" : {
"wins" : 15,
"losses" : 10,
"ot" : 3,
"type" : "league"
},
"score" : 2,
"team" : {
"id" : 25,
"name" : "Dallas Stars",
"link" : "/api/v1/teams/25"
}
},
"home" : {
"leagueRecord" : {
"wins" : 12,
"losses" : 11,
"ot" : 4,
"type" : "league"
},
"score" : 3,
"team" : {
"id" : 30,
"name" : "Minnesota Wild",
"link" : "/api/v1/teams/30"
}
}
},
I think that dates, and games are actually arrays of different objects but I do not know how to show this in value templating and could not find examples. My knowledge of JSON is pretty limited. Is this possible with templating?