it converts it to the format I want, but I cannot work out how to combine the two items
value_template: “{{ value.replace(‘Data delayed at least 15 minutes, as of ‘, ‘’)|replace(’.’,’’) }}”
and
{{ strptime(state_attr(“sensor.fund1”, “fund_date”), “%b %d %Y”) .strftime(’%d/%m/%y’) }}
This might be off by an hour depending on timezones. I’m not messing around with replace, but just pulling the character positions ([40:51]) to get Dec 01 2022, then strptime-ing it to a UNIX timestamp and timestamp_custom-ing it to the format you want.
Please format your code snippets correctly using the </> button.
I don’t have multiscrape installed, so I can’t try it out. I’m not suggesting a second value_template. My code replaces your template. Here it is with value instead of the sensor:
- resource: https://markets.ft.com/data/funds/tearsheet/summary?s=GB0006061963:GBX
scan_interval: 28800
sensor:
- unique_id: Fund1
name: Fund 1
select: "body > div.o-grid-container.mod-container > div:nth-child(2) > section:nth-child(1) > div > div > div.mod-tearsheet-overview__overview.clearfix > div.mod-tearsheet-overview__quote > ul > li:nth-child(1) > span.mod-ui-data-list__value"
attributes:
- name: Fund Price
select: "body > div.o-grid-container.mod-container > div:nth-child(2) > section:nth-child(1) > div > div > div.mod-tearsheet-overview__overview.clearfix > div.mod-tearsheet-overview__quote > ul > li:nth-child(1) > span.mod-ui-data-list__value"
- name: Fund Date
select: "body > div.o-grid-container.mod-container > div:nth-child(2) > section:nth-child(1) > div > div > div.mod-tearsheet-overview__overview.clearfix > div.mod-tearsheet-overview__quote > div"
value_template: >
{{ strptime(value[40:51], "%b %d %Y", default="")|as_timestamp|timestamp_custom("%d/%m/%Y") }}
Still not quite sure how you did that (I will need to better understand the “value” aspect), but you have fixed it for me, so thank you very much indeed.
It’s quite simple: value is what the scrape sensor pulls out of the page, and value_template allows you to do something with it before it falls out of your sensor. Using your method rather than mine:
value_template: "{{ strptime(value|replace('Data delayed at least 15 minutes, as of ', '')|replace('.',''), '%b %d %Y').strftime('%d/%m/%Y') }}"
(note %Y for 2022 rather than %y for 22)
If you use multi-line templates, you can make it more readable:
value_template: >
{{
strptime(
value|
replace('Data delayed at least 15 minutes, as of ', '')|
replace('.',''),
'%b %d %Y'
).strftime('%d/%m/%Y')
}}