I’m querying my local council’s bin collection schedule using the following sensors.
- platform: rest
name: "Black Bin Collection"
resource: !secret bincollectionuri
method: GET
scan_interval: 604800
timeout: 30
json_attributes_path: "$.BinCollections.[?(@.JobStatus=='Scheduled' && @.BinType=='Black bin')]"
value_template: "OK"
json_attributes:
- JobStatus
- BinType
- JobScheduledStart
- platform: rest
name: "Green Bin Collection"
resource: !secret bincollectionuri
method: GET
scan_interval: 604800
timeout: 30
json_attributes_path: "$.BinCollections.[?(@.JobStatus=='Scheduled' && @.BinType=='Green bin' && @.)]"
value_template: "OK"
json_attributes:
- JobStatus
- BinType
- JobScheduledStart
- platform: rest
name: "Orange Bin Collection"
resource: !secret bincollectionuri
method: GET
scan_interval: 604800
timeout: 30
json_attributes_path: "$.BinCollections.[?(@.JobStatus=='Scheduled' && @.BinType=='Orange bin')]"
value_template: "OK"
json_attributes:
- JobStatus
- BinType
- JobScheduledStart
Sample json from !secret bincollectionuri is on pastebin
This works well enough (although one single query instead of three would be better), up until the JobStatus attribute is not updated in a timely fashion.
This happened recently - a Green Bin pickup scheduled for 10-March was delayed and still has the JobStatus as ‘Scheduled’ - meaning that my query still shows next pickup for the Green Bin as the 10th.
I’ve tried to figure out a way to adjust the json_attributes_path to look for a JobScheduledStart greater than the current date but after several days fiddling have not been able to resolve it.
Are any JSON / REST gurus here able to give me the benefit of their experience?
TIA