Value template for scrape sensor

Dear all,

I want to scrape the daily Belgian Gas price from a website.
The scrape sensor returns as a value ‘€ 5.30000’ .

I want to use an altered version of this value (convert from cents to euro and include taxes) to calculate my daily energy cost in the energy panel.
I am however unable to add anything in the value-template as the value will change into unknown.
Currently I have the status unknown with the following in the value template: {{ ( value.split(’ ')[1] | float ) * 0.102153 }}

Anyone knows which mistake / error I am making?
Additional information, I scrape the gas price of Luminus on the following website: Gasprijs België per kWh in 2023 en de actuele gasprijzen

Many thanks for the information and support.

Kind regards,

Robin

You need to format your code properly using backticks, see this link. Your code has a fancy single quote and a normal single quote, but I don’t know if that’s because you didn’t format it properly in your reply, or if your code actually contains that mistake.

I see what you mean.
I have altered the quote, but still get the value unknown.
Could you please further assist me with this issue?
Many thanks.

Please post your scrape sensor config

Dear mekaneck Rick Auch,

Please find my sensor config below:

Resource
https://callmepower.be/nl/energie/gids/tarief/prijs-gas

Method
GET

Select authentication method
basic

Select
tbody > tr:nth-child(9) > td:nth-child(3) > p

Value Template
{{ ( value.split(’ ')[1] | float(0) ) * 0.102153 }}

Please paste the actual code in using proper formatting. I can’t help you unless I know exactly what characters and spacing is in your yaml. Please read the link in my first reply and look specifically at the section titled Codeblocks

Edit: I should be pointing you instead to section 11 of the forum guidelines: How to help us help you - or How to ask a good question

Dear mekaneck Rick Auch,

Is this the extraction from the yaml you require?

scrape:

Please note that a couple releases back the scrape sensor has received a UI setup, which causes the yaml configuration to be obsolete.

I hope I now have everything correct, as I really do not know what section of the link you refer to.

Many thanks for your support, I really appreciate it.

Kind regards,

Robin

Section 11 of the guide, as linked. Your code should look like this:

scrape:
  - resource: (etc)

not like this:

scrape:

  • resource:

The guide explains how to do this. Use the codeblock button (</>).

This might work for you:

value_template: "{{ value|select('in','.0123456789')|join)|float(0) * 0.102153 }}"

It ignores all characters except numbers or a decimal point, so is more resistant to multiple or unexpected spacing characters (e.g. HTML &nbsp;). Here it is in action in the template editor tool, with an additional round() filter:

1 Like

Dear Troon,

Many thanks for your support.
This has solved my issue.

Kind regards,

Robin