Rest sensor with attributes?

I am pulling Top3 in drivers championship for Formula 1 from a Ergast API, I am using reset sensors

rest:

  - authentication: basic
    scan_interval: 1800
    resource: http://ergast.com/api/f1/2023/driverStandings.json
    sensor:

      - name: "F1 Driver Standings - P1"
        json_attributes_path: "$.MRData.StandingsTable.StandingsLists[0].DriverStandings[0].Driver"
        value_template: OK
        json_attributes:
          - ".code"
          - "givenName"
          - "familyName"
      - name: "F1 Driver Standings - P2"
        json_attributes_path: "$.MRData.StandingsTable.StandingsLists[0].DriverStandings[1].Driver"
        value_template: OK
        json_attributes:
          - ".code"
          - "givenName"
          - "familyName"
      - name: "F1 Driver Standings - P3"
        json_attributes_path: "$.MRData.StandingsTable.StandingsLists[0].DriverStandings[2].Driver"
        value_template: OK
        json_attributes:
          - ".code"
          - "givenName"
          - "familyName"

This will give me the result of three different sensors

I am going to extend this to all 20 drivers’ standings and therefore am trying to get all into one sensor instead of having 3 sensors. Is it possible to do a rest sensor with more attributes?

This is the JSON response i get from the API

{
	"MRData": {
		"xmlns": "http:\/\/ergast.com\/mrd\/1.5",
		"series": "f1",
		"url": "http://ergast.com/api/f1/2023/driverstandings.json",
		"limit": "30",
		"offset": "0",
		"total": "20",
		"StandingsTable": {
			"season": "2023",
			"StandingsLists": [{
				"season": "2023",
				"round": "10",
				"DriverStandings": [{
					"position": "1",
					"positionText": "1",
					"points": "255",
					"wins": "8",
					"Driver": {
						"driverId": "max_verstappen",
						"permanentNumber": "33",
						"code": "VER",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Max_Verstappen",
						"givenName": "Max",
						"familyName": "Verstappen",
						"dateOfBirth": "1997-09-30",
						"nationality": "Dutch"
					},
					"Constructors": [{
						"constructorId": "red_bull",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Red_Bull_Racing",
						"name": "Red Bull",
						"nationality": "Austrian"
					}]
				}, {
					"position": "2",
					"positionText": "2",
					"points": "156",
					"wins": "2",
					"Driver": {
						"driverId": "perez",
						"permanentNumber": "11",
						"code": "PER",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Sergio_P%C3%A9rez",
						"givenName": "Sergio",
						"familyName": "Pérez",
						"dateOfBirth": "1990-01-26",
						"nationality": "Mexican"
					},
					"Constructors": [{
						"constructorId": "red_bull",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Red_Bull_Racing",
						"name": "Red Bull",
						"nationality": "Austrian"
					}]
				}, {
					"position": "3",
					"positionText": "3",
					"points": "137",
					"wins": "0",
					"Driver": {
						"driverId": "alonso",
						"permanentNumber": "14",
						"code": "ALO",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Fernando_Alonso",
						"givenName": "Fernando",
						"familyName": "Alonso",
						"dateOfBirth": "1981-07-29",
						"nationality": "Spanish"
					},
					"Constructors": [{
						"constructorId": "aston_martin",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Aston_Martin_in_Formula_One",
						"name": "Aston Martin",
						"nationality": "British"
					}]
				}, {
					"position": "4",
					"positionText": "4",
					"points": "121",
					"wins": "0",
					"Driver": {
						"driverId": "hamilton",
						"permanentNumber": "44",
						"code": "HAM",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Lewis_Hamilton",
						"givenName": "Lewis",
						"familyName": "Hamilton",
						"dateOfBirth": "1985-01-07",
						"nationality": "British"
					},
					"Constructors": [{
						"constructorId": "mercedes",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Mercedes-Benz_in_Formula_One",
						"name": "Mercedes",
						"nationality": "German"
					}]
				}, {
					"position": "5",
					"positionText": "5",
					"points": "83",
					"wins": "0",
					"Driver": {
						"driverId": "sainz",
						"permanentNumber": "55",
						"code": "SAI",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Carlos_Sainz_Jr.",
						"givenName": "Carlos",
						"familyName": "Sainz",
						"dateOfBirth": "1994-09-01",
						"nationality": "Spanish"
					},
					"Constructors": [{
						"constructorId": "ferrari",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Scuderia_Ferrari",
						"name": "Ferrari",
						"nationality": "Italian"
					}]
				}, {
					"position": "6",
					"positionText": "6",
					"points": "82",
					"wins": "0",
					"Driver": {
						"driverId": "russell",
						"permanentNumber": "63",
						"code": "RUS",
						"url": "http:\/\/en.wikipedia.org\/wiki\/George_Russell_%28racing_driver%29",
						"givenName": "George",
						"familyName": "Russell",
						"dateOfBirth": "1998-02-15",
						"nationality": "British"
					},
					"Constructors": [{
						"constructorId": "mercedes",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Mercedes-Benz_in_Formula_One",
						"name": "Mercedes",
						"nationality": "German"
					}]
				}, {
					"position": "7",
					"positionText": "7",
					"points": "74",
					"wins": "0",
					"Driver": {
						"driverId": "leclerc",
						"permanentNumber": "16",
						"code": "LEC",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Charles_Leclerc",
						"givenName": "Charles",
						"familyName": "Leclerc",
						"dateOfBirth": "1997-10-16",
						"nationality": "Monegasque"
					},
					"Constructors": [{
						"constructorId": "ferrari",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Scuderia_Ferrari",
						"name": "Ferrari",
						"nationality": "Italian"
					}]
				}, {
					"position": "8",
					"positionText": "8",
					"points": "44",
					"wins": "0",
					"Driver": {
						"driverId": "stroll",
						"permanentNumber": "18",
						"code": "STR",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Lance_Stroll",
						"givenName": "Lance",
						"familyName": "Stroll",
						"dateOfBirth": "1998-10-29",
						"nationality": "Canadian"
					},
					"Constructors": [{
						"constructorId": "aston_martin",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Aston_Martin_in_Formula_One",
						"name": "Aston Martin",
						"nationality": "British"
					}]
				}, {
					"position": "9",
					"positionText": "9",
					"points": "42",
					"wins": "0",
					"Driver": {
						"driverId": "norris",
						"permanentNumber": "4",
						"code": "NOR",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Lando_Norris",
						"givenName": "Lando",
						"familyName": "Norris",
						"dateOfBirth": "1999-11-13",
						"nationality": "British"
					},
					"Constructors": [{
						"constructorId": "mclaren",
						"url": "http:\/\/en.wikipedia.org\/wiki\/McLaren",
						"name": "McLaren",
						"nationality": "British"
					}]
				}, {
					"position": "10",
					"positionText": "10",
					"points": "31",
					"wins": "0",
					"Driver": {
						"driverId": "ocon",
						"permanentNumber": "31",
						"code": "OCO",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Esteban_Ocon",
						"givenName": "Esteban",
						"familyName": "Ocon",
						"dateOfBirth": "1996-09-17",
						"nationality": "French"
					},
					"Constructors": [{
						"constructorId": "alpine",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Alpine_F1_Team",
						"name": "Alpine F1 Team",
						"nationality": "French"
					}]
				}, {
					"position": "11",
					"positionText": "11",
					"points": "17",
					"wins": "0",
					"Driver": {
						"driverId": "piastri",
						"permanentNumber": "81",
						"code": "PIA",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Oscar_Piastri",
						"givenName": "Oscar",
						"familyName": "Piastri",
						"dateOfBirth": "2001-04-06",
						"nationality": "Australian"
					},
					"Constructors": [{
						"constructorId": "mclaren",
						"url": "http:\/\/en.wikipedia.org\/wiki\/McLaren",
						"name": "McLaren",
						"nationality": "British"
					}]
				}, {
					"position": "12",
					"positionText": "12",
					"points": "16",
					"wins": "0",
					"Driver": {
						"driverId": "gasly",
						"permanentNumber": "10",
						"code": "GAS",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Pierre_Gasly",
						"givenName": "Pierre",
						"familyName": "Gasly",
						"dateOfBirth": "1996-02-07",
						"nationality": "French"
					},
					"Constructors": [{
						"constructorId": "alpine",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Alpine_F1_Team",
						"name": "Alpine F1 Team",
						"nationality": "French"
					}]
				}, {
					"position": "13",
					"positionText": "13",
					"points": "11",
					"wins": "0",
					"Driver": {
						"driverId": "albon",
						"permanentNumber": "23",
						"code": "ALB",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Alexander_Albon",
						"givenName": "Alexander",
						"familyName": "Albon",
						"dateOfBirth": "1996-03-23",
						"nationality": "Thai"
					},
					"Constructors": [{
						"constructorId": "williams",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Williams_Grand_Prix_Engineering",
						"name": "Williams",
						"nationality": "British"
					}]
				}, {
					"position": "14",
					"positionText": "14",
					"points": "9",
					"wins": "0",
					"Driver": {
						"driverId": "hulkenberg",
						"permanentNumber": "27",
						"code": "HUL",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Nico_H%C3%BClkenberg",
						"givenName": "Nico",
						"familyName": "Hülkenberg",
						"dateOfBirth": "1987-08-19",
						"nationality": "German"
					},
					"Constructors": [{
						"constructorId": "haas",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Haas_F1_Team",
						"name": "Haas F1 Team",
						"nationality": "American"
					}]
				}, {
					"position": "15",
					"positionText": "15",
					"points": "5",
					"wins": "0",
					"Driver": {
						"driverId": "bottas",
						"permanentNumber": "77",
						"code": "BOT",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Valtteri_Bottas",
						"givenName": "Valtteri",
						"familyName": "Bottas",
						"dateOfBirth": "1989-08-28",
						"nationality": "Finnish"
					},
					"Constructors": [{
						"constructorId": "alfa",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Alfa_Romeo_in_Formula_One",
						"name": "Alfa Romeo",
						"nationality": "Swiss"
					}]
				}, {
					"position": "16",
					"positionText": "16",
					"points": "4",
					"wins": "0",
					"Driver": {
						"driverId": "zhou",
						"permanentNumber": "24",
						"code": "ZHO",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Guanyu_Zhou",
						"givenName": "Guanyu",
						"familyName": "Zhou",
						"dateOfBirth": "1999-05-30",
						"nationality": "Chinese"
					},
					"Constructors": [{
						"constructorId": "alfa",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Alfa_Romeo_in_Formula_One",
						"name": "Alfa Romeo",
						"nationality": "Swiss"
					}]
				}, {
					"position": "17",
					"positionText": "17",
					"points": "2",
					"wins": "0",
					"Driver": {
						"driverId": "tsunoda",
						"permanentNumber": "22",
						"code": "TSU",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Yuki_Tsunoda",
						"givenName": "Yuki",
						"familyName": "Tsunoda",
						"dateOfBirth": "2000-05-11",
						"nationality": "Japanese"
					},
					"Constructors": [{
						"constructorId": "alphatauri",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Scuderia_AlphaTauri",
						"name": "AlphaTauri",
						"nationality": "Italian"
					}]
				}, {
					"position": "18",
					"positionText": "18",
					"points": "2",
					"wins": "0",
					"Driver": {
						"driverId": "kevin_magnussen",
						"permanentNumber": "20",
						"code": "MAG",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Kevin_Magnussen",
						"givenName": "Kevin",
						"familyName": "Magnussen",
						"dateOfBirth": "1992-10-05",
						"nationality": "Danish"
					},
					"Constructors": [{
						"constructorId": "haas",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Haas_F1_Team",
						"name": "Haas F1 Team",
						"nationality": "American"
					}]
				}, {
					"position": "19",
					"positionText": "19",
					"points": "0",
					"wins": "0",
					"Driver": {
						"driverId": "sargeant",
						"permanentNumber": "2",
						"code": "SAR",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Logan_Sargeant",
						"givenName": "Logan",
						"familyName": "Sargeant",
						"dateOfBirth": "2000-12-31",
						"nationality": "American"
					},
					"Constructors": [{
						"constructorId": "williams",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Williams_Grand_Prix_Engineering",
						"name": "Williams",
						"nationality": "British"
					}]
				}, {
					"position": "20",
					"positionText": "20",
					"points": "0",
					"wins": "0",
					"Driver": {
						"driverId": "de_vries",
						"permanentNumber": "21",
						"code": "DEV",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Nyck_de_Vries",
						"givenName": "Nyck",
						"familyName": "de Vries",
						"dateOfBirth": "1995-02-06",
						"nationality": "Dutch"
					},
					"Constructors": [{
						"constructorId": "alphatauri",
						"url": "http:\/\/en.wikipedia.org\/wiki\/Scuderia_AlphaTauri",
						"name": "AlphaTauri",
						"nationality": "Italian"
					}]
				}]
			}]
		}
	}
}

fafaik you can only have one json_attribtues_path per sensor
Depening on what you want to have in the end, you could load the whole output as an attribute and then use the cards to extract the data accordingly…not the basic ones but quite a few allow to define the attrib.

Thanks, what I wanted to was to my minimize the number of sensors that I needed to create. From what I understand it’s not possible add multiple levels from the JSON in one attribute. I tried this without success so don’t think it’s supported.

        json_attributes:
          - "Driver.code"
          - "Driver.givenName"

Indeed that does not work…so you have the option as per my comment above…or create X sensors.
You could try , setup a card with the atrribs for (say) 2 cars/drivers and then decide which is best.]
EDIT: I think that if you have 1 sensor then you can take the information as it comes, i.e. you donot need to know which one is where in the attrib as you will use the infor as-it-comes …

Unfortunately, I will not use this in a card, I will provide the data for an e-paper screen run by an ESP32 so I need the sensors. I will have to go and create multiple sensors for now I think.

Another question if someone knows, from the API I get a response like this when it comes to time and date in a sensor. I need to convert that to a timestamp so I can treat it as time in Home Assistant. How do I do that?

How do I do that? I have tried everything I can think of, but I exceed the maximum character

The closest I got is this, without success.

  - platform: rest
    resource: http://ergast.com/api/f1/current/last/results.json
    name: F1 - test sensor
    scan_interval: 3600
    value_template: '1'  # dummy value, not used; that should avoids the "State max length is 255 characters" error
    json_attributes:
      - value_json.MRData.RaceTable.Races[0]

you can not walk a path in the attributes so use a json_attributes_path
example

json_attributes_path: '$.MRData.RaceTable.Races[0]'
json_attributes:
  - season
  - Circuit
  - Results

Thanks, now it works! Good to reduce the amount of sensors