Trying to get JSON data from here (don’t worry, not my real house) into a restful sensor.
The output is longer than 255 chars so Restful won’t store it; I believe I can break it down using json_attributes but I just can’t make the nesting work no matter which way I try it (I think due to the import at the start).
Ideally I would have three template sensors which just hold the dates mentioned so I can make a custom card.
Sorry; here you go. It comes all in one line in the web browser also which makes it more difficult
import({"Results":{"bin_collections_combined":[{"__":100010877913,"_":"<div class=\"clearfix 2\"><img class=\"isharefeed\" src=\"https://maps.bolton.gov.uk/residents/custom/mybolton_files/beigebin.jpg\"/><p>Your next beige bin collection will be on </p><p><strong>Wednesday 11 September 2019</strong></p></div>"},{"__":100010877913,"_":"<div class=\"clearfix 2\"><img class=\"isharefeed\" src=\"https://maps.bolton.gov.uk/residents/custom/mybolton_files/burgundybin.jpg\"/><p>Your next burgundy bin collection will be on </p><p><strong>Wednesday 11 September 2019</strong></p></div>"},{"__":100010877913,"_":"<div class=\"clearfix 2\"><img class=\"isharefeed\" src=\"https://maps.bolton.gov.uk/residents/custom/mybolton_files/greenbin.jpg\"/><p>Your next green bin collection will be on </p><p><strong>Wednesday 11 September 2019</strong></p></div>"},{"__":100010877913,"_":"<div class=\"clearfix 2\"><img class=\"isharefeed\" src=\"https://maps.bolton.gov.uk/residents/custom/mybolton_files/greybin.jpg\"/><p>Your next grey bin collection will be on </p><p><strong>Wednesday 04 September 2019</strong></p></div>"}]}});
Yeah, ideally I would have three sensors with the three different dates. The rest sensor was reading the whole string in when it was shorter but I just couldn’t format it into a template.
Yeah, it looks like it’s json with html values. Super shitty tbh. Anyways, you can do a regex. Hopefully the order of the bins doesn’t change.
index
bin
0
beige
1
burgundy
2
green
3
grey
value_template possibilities
Whole sentance ( Your next beige bin collection will be on Wednesday 11 September 2019 )
{%- set find = '[\w\s]+<\/p><p><strong>[\w\s]+<\/strong>' %}
{%- set index = 0 %}
{%- set result = value | regex_findall_index(find, index ) %}
{{ result.replace('</p><p><strong>','').replace('</strong>','') }}
Just the date ( Wednesday 11 September 2019 ):
{%- set find = '<\/p><p><strong>[\w\s]+<\/strong>' %}
{%- set index = 0 %}
{%- set result = value | regex_findall_index(find, index ) %}
{{ result.replace('</p><p><strong>','').replace('</strong>','') }}
Color: date ( beige: Wednesday 11 September 2019 )
{%- set find = '[\w\s]+<\/p><p><strong>[\w\s]+<\/strong>' %}
{%- set index = 0 %}
{%- set result = value | regex_findall_index(find, index ) %}
{{ result.replace('Your next ','').replace(' bin collection will be on ',': ').replace('</p><p><strong>','').replace('</strong>','') }}
Petro, got it thanks! Had to create 4 instances of Rest as it isn’t JSON so couldn’t get json_attributes to work but its getting the data, I’ve just set scan_interval to 24hrs to avoid repeated calls.
Thanks so much for your assistance; I really appreciate it - spent hours trying to get this work! Cheers.
Hi Petro, sorry to try and appoint you as my personal assistant but is there a way to convert this to a true date format that HA can understand for automations, I’m having trouble trying to convert just a string to a useable date format following a few posts on here …