Help Extracting Value out of String with a value_sensor

Hi All,

Unfortunately my Jinja skills aren’t that great - and I was wondering if its possible to grab the figures out of the current sensor - which I am scraping from a website displaying todays and tomorrow’s electricity prices.

The state is: “The Electricity Tracker November 2022 v1 Price on Mon 17/07/2023 is 16.58p/kWh, tomorrows price is 18.72p/kWh”

I’d like to pull out the 2 values separately into value sensors if that’s possible?

Thanks
Leacho

template:
  - sensor:
      - name: "Electricity price today"
        state: '{{ (states("sensor.YOUR_SCRAPE_SENSOR")|regex_findall("\ ([0-9\.]+)p\/kWh"))[0] }}'
        unit_of_measurement: "p/kWh"
      - name: "Electricity price tomorrow"
        state: '{{ (states("sensor.YOUR_SCRAPE_SENSOR")|regex_findall("\ ([0-9\.]+)p\/kWh"))[1] }}'
        unit_of_measurement: "p/kWh"

If it’s a time-of-use price that could potentially go negative, change the ([0-9\.]+) to (\-?[0-9\.]+).

That’s spot on thanks @Troon