@nigelm wrote:
In Multiple sensors in one REST call the question was about handling data returned from a REST service as a JSON dictionary.
My problem relates to a service that returns its items as an array - which could be transformed to a dictionary (but unfortunately aren’t), so how would the documented bedoom1/bedroom2/bedroom3 sensor be configured if the returned JSON instead looked like this:-
[ { "room": "bedroom1", "temperature": 14.98, "humidity": 53.68, "battery": 5.26, "timestamp": "2019-02-25T21:27:52Z" }, { "room": "bedroom2", "temperature": 18.49, "humidity": 47.65, "battery": 5.08, "timestamp": "2019-02-25T21:27:26Z" }, { "room": "bedroom3", "temperature": 18.14, "humidity": 48.16, "battery": 5.15, "timestamp": "2019-02-25T21:31:16Z" } ]
Is it possible to use the
json_attributes
orjson_attributes_path
to be able to end up with sets of attributes forbedroom1
,bedroom2
andbedroom3
.For a real world application for this, the York Bin Collection API returns between 1 and 3 dictionaries for a property, each of which describes one type of bin collection - it is not specified (but appears to be generally consistant) what order the sets of bin collection data are returned in, which is why I would like to link it to one entry within the dictionary as an index.
An example of the sort of entry you may get is given below - for two sets of bins (for my own properly there are three sets, for a total of approx 3.5KB of JSON)
[ { "AlternativeRoundNumber": null, "AlternativeRoundNumberDescription": null, "BinType": "GREY 240", "BinTypeDescription": "Grey Bin 240L", "CollectionAvailable": "Y", "CollectionCalendar": "?", "CollectionDay": "MON", "CollectionDayFull": "Monday", "CollectionDayOfWeek": 1, "CollectionFrequency": "Alternate Weeks", "CollectionFrequencyShort": "WEEK 1", "CollectionPoint": "FRONT", "CollectionPointDescription": "Edge of Property at Front", "CollectionPointLocation": null, "CollectionType": "GREY BIN/SACK", "CollectionTypeDescription": "Grey Bin/Black Sack Collection", "Frequency": { "ExcludeSunday": null, "FrequencyInDays": 14, "StartingWeekNumber": 2 }, "ImageName": "blackbin", "LastCollection": "/Date(1586732400000)/", "Locality": null, "MaterialsCollected": "General Domestic", "NextCollection": "/Date(1587942000000)/", "NumberOfBins": "1", "Postcode": "YO24 1NB", "PropertyName": null, "PropertyNumber": "10", "Provider": "City of York Council", "ProviderShort": "CYC", "RoundNumber": "TEAM 2", "RoundNumberDescription": "Team 2", "SaonName": null, "SaonNo": null, "ShortAddress": "10 LYCETT ROAD", "Street": "LYCETT ROAD", "UPRN": 100050567115, "Ward": "Dringhouses & Woodthorpe", "WasteType": "GREY BIN/SACK", "WasteTypeDescription": "Grey Bin/Black Sack Collection" }, { "AlternativeRoundNumber": null, "AlternativeRoundNumberDescription": null, "BinType": "BOX 55", "BinTypeDescription": "Box 55L", "CollectionAvailable": "Y", "CollectionCalendar": "?", "CollectionDay": "WED", "CollectionDayFull": "Wednesday", "CollectionDayOfWeek": 3, "CollectionFrequency": "Alternate Weeks", "CollectionFrequencyShort": "WEEK 2", "CollectionPoint": "FRONT", "CollectionPointDescription": "Edge of Property at Front", "CollectionPointLocation": null, "CollectionType": "KERBSIDE", "CollectionTypeDescription": "Kerbside Collection", "Frequency": { "ExcludeSunday": null, "FrequencyInDays": 14, "StartingWeekNumber": 1 }, "ImageName": "box", "LastCollection": "/Date(1586300400000)/", "Locality": null, "MaterialsCollected": "Paper/Card : Plastic/Cans : Glass", "NextCollection": "/Date(1587510000000)/", "NumberOfBins": "3", "Postcode": "YO24 1NB", "PropertyName": null, "PropertyNumber": "10", "Provider": "City of York Council", "ProviderShort": "CYC", "RoundNumber": "B", "RoundNumberDescription": "Round B", "SaonName": null, "SaonNo": null, "ShortAddress": "10 LYCETT ROAD", "Street": "LYCETT ROAD", "UPRN": 100050567115, "Ward": "Dringhouses & Woodthorpe", "WasteType": "KERBSIDE", "WasteTypeDescription": "Kerbside Collection" } ]
I’d really like to grab everything as a single API call rather than hammering the API due to deficiencies in the data de-serialisation.
Thanks
Nigel.
Posts: 1
Participants: 1