Hey all,
are there any online tools that help with syntax for using a template and a split, ive never done this before, so not really sure what my options are and how to put things together.
either way, im using this:
which returns:
Monday 10 Jun 2019Monday 17 Jun 2019Monday 24 Jun 2019
i would like to now split this into 3 values, one for each date.
i managed the first one, with this, however not sure if this is the best way to do it or not?
{{states.sensor.test_bin_scrape2.state.split()[0]}}{{' '}}{{states.sensor.test_bin_scrape2.state.split()[1]}}{{' '}}{{states.sensor.test_bin_scrape2.state.split()[2]}}
however when i move to the next date, teh 2019Monday are joined, so im at a loss.
Not sure if there’s an easier way but this works, give it a try. Think whitespace is assumed if you don’t specify a split character
{{ states.sensor.worthing_refuse_grey_bin.state.split()[0] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[1] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[2] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[3][:4] }}
{{ states.sensor.worthing_refuse_grey_bin.state.split()[3][4:] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[4] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[5] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[6][:4] }}
{{ states.sensor.worthing_refuse_grey_bin.state.split()[6][4:] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[7] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[8] + ' ' + states.sensor.worthing_refuse_grey_bin.state.split()[9] }}
Much simpler…you can remove the + '2019'
at the end if you don’t need the year in your sensor
{{ states.sensor.worthing_refuse_grey_bin.state.split('2019')[0] + '2019' }}
{{ states.sensor.worthing_refuse_grey_bin.state.split('2019')[1] + '2019' }}
{{ states.sensor.worthing_refuse_grey_bin.state.split('2019')[2] + '2019' }}
1 Like
Hero!! thanks so much
my final result is this.
Giving me the current and next, for all 3 bin types.
- platform: scrape
name: worthing_refuse_bin
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(1) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[0] + '2019' }}"
- platform: scrape
name: worthing_refuse_bin_next
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(1) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[1] + '2019' }}"
- platform: scrape
name: worthing_recycling_bin
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(2) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[0] + '2019' }}"
- platform: scrape
name: worthing_recycling_bin_next
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(2) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[1] + '2019' }}"
- platform: scrape
name: worthing_garden_bin
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(3) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[0] + '2019' }}"
- platform: scrape
name: worthing_garden_bin_next
resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061882207&return-url=%2Fbin-day%2F
select: 'tr:nth-child(3) td:nth-child(3)'
scan_interval: 86400
value_template: "{{ value.split('2019')[1] + '2019' }}"