HELP REST Sensor JSON

here is the json api:
{“id”:“jetnano01”,“description”:“MaskCam @ Jetson Nano”,“file_server_address”:“http://192.168.1.49:8080”,“statistics”:[{“device_id”:“jetnano01”,“datetime”:“2021-07-15T13:06:18.740421”,“statistic_type”:“REPORT”,“people_with_mask”:1,“people_without_mask”:0,“people_total”:1},{“device_id”:“jetnano01”,“datetime”:“2021-07-15T13:06:33.740174”,“statistic_type”:“REPORT”,“people_with_mask”:1,“people_without_mask”:0,“people_total”:1},{“device_id”:“jetnano01”,“datetime”:“2021-07-15T13:06:48.739909”,“statistic_type”:“REPORT”,“people_with_mask”:1,“people_without_mask”:0,“people_total”:1},{“device_id”:“jetnano01”,“datetime”:“2021-07-15T13:07:03.739594”,“statistic_type”:“REPORT”,“people_with_mask”:1,“people_without_mask”:0,“people_total”:1}

i want to get data of

  • people_with_mask
  • people_without_mask
  • people_total

This is my config:
sensor:

  • platform: rest
    name: “maskcam”
    resource: “http://ipcam:554/devices/jetnano01
    value_template: “{{ value_json.statistics }}”

    unit_of_measurement: people
    json_attributes:

    • people_with_mask
    • people_without_mask
    • people_total

so your JSON isn’t ‘whole’ - i had to add to it

{
	"id": "jetnano01",
	"description": "MaskCam @ Jetson Nano",
	"file_server_address": "http://192.168.1.49:8080",
	"statistics": [{
		"device_id": "jetnano01",
		"datetime": "2021-07-15T13:06:18.740421",
		"statistic_type": "REPORT",
		"people_with_mask": 1,
		"people_without_mask": 0,
		"people_total": 1
	}, {
		"device_id": "jetnano01",
		"datetime": "2021-07-15T13:06:33.740174",
		"statistic_type": "REPORT",
		"people_with_mask": 1,
		"people_without_mask": 0,
		"people_total": 1
	}, {
		"device_id": "jetnano01",
		"datetime": "2021-07-15T13:06:48.739909",
		"statistic_type": "REPORT",
		"people_with_mask": 1,
		"people_without_mask": 0,
		"people_total": 1
	}, {
		"device_id": "jetnano01",
		"datetime": "2021-07-15T13:07:03.739594",
		"statistic_type": "REPORT",
		"people_with_mask": 1,
		"people_without_mask": 0,
		"people_total": 1
	}]
}

once i did that I dropped in https://jsonpathfinder.com/ and you can see you can access

x.statistics[0].people_with_mask
x.statistics[1].people_with_mask
x.statistics[2].people_with_mask
x.statistics[3].people_with_mask

where x is the entity ID. Is x.statistics[0].people_with_mask the latest/last update? or whats the relevance of the 4 arrays?

So you could reference

x.statistics[0].people_with_mask

and

x.statistics[0].people_without_mask

if you want all of them you could use

x.statistics[*].people_with_mask

I’m not sure if HA supports .sum() as part of jsonpath but could try

x.statistics[*].people_with_mask.sum()