Please Help with a Scrape Sensor

My config:

- platform: scrape
    scan_interval: 1800
    resource: https://tankbillig.in/index.php?long=16.0833&lat=48.5500&show=0&treibstoff=diesel&switch
    name: Diesel Preis
    select: '.listviewpreis'
    unit_of_measurement: "€/L"

gives me this state: 1,221 €1,8 km €/L

How can I get rid of this 1,8 km value that only the fuel price stops?

thanks

I would create a sensor template from it and in the value_template I would get rid of everything is after the € sign.

yes that would be a good idea, only I do not know how

Try

select: '.listviewpreis :not(.distanceAtPrice)'

combinators-and-selector-lists

Descendant combinators combine two selectors with whitespace ( ) in order to signify that the second element is matched if it has an ancestor that matches the first element.

1 Like

is better now I get the value ≥ 1.259 €, but still not only the number

For the sensor template it should be something like this:

diesel_pries:
  friendly_name: My diesel preis
  value_template: >
        {% set x = states.scrape.diesel_preis.state.find('€') %} 
        {% if x != -1 %}
          {{ states.scrape.diesel_preis.state[0:x] }}
        {% else %}              
          {{ states.scrape.diesel_preis.state }}            
        {% endif %}

First line search for euro sign.
If it finds euro sign it keeps everything before euro sign, otherwise it does nothing

This goes under “sensor” section in configuration.yaml

I suggest you to learn a bit of sensor template because they are really helpfull, they save me a lot of time.

1 Like

hello, thanks for your help!
I have now made a sensor template with attributes

- platform: template
    sensors:
      diesel_preis_template:
        friendly_name: "Diesel Preis Template"
        unit_of_measurement: '€/L'
        value_template: "{{states.sensor.diesel_preis.state | replace ("≥", "") | replace ("€", "") }}"
        attribute_templates: "{{ states('sensor.diesel_ort') }}"
        icon_template: mdi:gas-station
1 Like