Dutch Gas Priceses

@proton999, you could use the rest sensor of HA:

  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/XXXX.png
    name: Give The Station A Name
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€"

Still improving the code, so if there is a station which is not working or providing wrong prices let me know.

Thanks for the code, as soon I find some time (probably this weekend) I’ll do some testing and let you know.

It’s working fine, only the last digit is hard to catch for your OCR software because sometimes it;'s missing or wrong and sometimes spot on. But I’m already happy with it. I don’t know what de refresh rate of the directlease.nl site is or at your site so probably the one hour refresh update I use is to much.
Below my results en code. (have to make the card a bit nicer

Fuel

homeassistant:
   customize_glob:
    sensor.euro95*:
      unit_of_measurement: "€/L"

sensor:
  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/4895.png
    name: Shell Express Dorp
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€/L"
    scan_interval: 3600 # once per hour only

  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/4916.png
    name: Esso Randweg Noord
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€/L"
    scan_interval: 3600 # once per hour only

  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/4929.png
    name: Tango Smulders
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€/L"
    scan_interval: 3600 # once per hour only

  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/4966.png
    name: Tinq Praxis
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€/L"  
    scan_interval: 3600 # once per hour only

  - platform: rest
    resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/5002.png
    name: Gulf Leto
    value_template: '{{ value_json.benzine_prijs }}'
    unit_of_measurement: "€/L" 
    scan_interval: 3600 # once per hour only
    
  - platform: scrape
    name: Euro95 Advies
    resource: "https://www.unitedconsumers.com/brandstofprijzen"
    select: ".table div:nth-of-type(2) div:nth-of-type(3)"
    value_template: "{{ value |replace('€', '') |replace(',', '.') |round(3) }}"
    scan_interval: 3600 # once per hour only
1 Like

Great. I improved the code again so it will use a cache of 3600 seconds. I don’t know how good/up to date directlease prices are but stations seem to be updated more times in a day from what I see.

Good that you use a scan_interval it helps with performance on the server side.

1 Like

Very nice API!
Works like a charm, except for some fuel stations the OCR’ed data is incorrect or null.
For example 7016.png.

Are you willing to share or open-source your API ?
Would be cool to host it myself for myself.

I’ve tried your config for the scrape, but getting error:

Error loading /config/configuration.yaml: 'utf-8' codec can't decode byte 0x80 in position 6022: invalid start byte

I think there must be something wrong in your configuration? Can you post your code?

Yes will definitely publish the code on Github! Hopefully I get some time this or next week to make it a version 1.0 and publish it.

I’ve only edit the following in my sensor.yaml.

  - platform: scrape
    name: Euro95 Advies
    resource: "https://www.unitedconsumers.com/brandstofprijzen"
    select: ".table div:nth-of-type(2) div:nth-of-type(3)"
    value_template: "{{ value |replace('€', '') |replace(',', '.') |round(3) }}"
    scan_interval: 3600 # be nice; once per hour only

  - platform: scrape
    name: Diesel Advies
    resource: "https://www.unitedconsumers.com/brandstofprijzen"
    select: ".table div:nth-of-type(3) div:nth-of-type(3)"
    value_template: "{{ value |replace('€', '') |replace(',', '.') |round(3) }}"
    scan_interval: 3600 # be nice; once per hour only

  - platform: scrape
    name: LPG Advies
    resource: "https://www.unitedconsumers.com/brandstofprijzen"
    select: ".table div:nth-of-type(4) div:nth-of-type(3)"
    value_template: "{{ value |replace('€', '') |replace(',', '.') |round(3) }}"
    scan_interval: 3600 # be nice; once per hour only

@sanderdw very interesting api and thanks for sharing. I added some stations but found on some the prices are not what is published. For example;

2963
Is shown as;

Code:

- platform: rest
  resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/2963.png
  name: BP Heerbaan Breda
  value_template: '{{ value_json.benzine_prijs }}'
  unit_of_measurement: "€/L"
  scan_interval: 3600 # once per hour only

And
3095
Is shown as;


Code;

- platform: rest
  resource: https://brandstof-api.sanwil.net/api/v1/brandstof_prijzen/3095.png
  name: Berkman Beneluxweg Oosterhout
  value_template: '{{ value_json.benzine_prijs }}'
  unit_of_measurement: "€/L"
  scan_interval: 3600 # once per hour only

Any idea why this happens?

Try just leaving one in and remove the others. Perhaps a single one is causing the issue?

Well I was playing with this. Now I had something that works.
I was checking at your github and copied the code from there. That was working.
Now I’m checking for the prices nearby.
Somebody who has the prices from Argos and Tamoil? The sites doesn’t specify that like others I see.

Hi @sjee , the small number on the end is not recognized very well by the OCR software, so i’m afraid i can’t do much about that.

But I see that the other one (BP Heerbaan) should possibly work so I’m working on an improved version. But due the lack of time that’s going to be somewhere finished next week. Bare with me
:slight_smile:

How to get the correct png - codes

@curious just find your tankstation on https://directlease.nl/tankservice and use the png name.

I moved the api to my new server so it’s much faster now. Next step is to update the code and move it to Github.

1 Like

Feel a little dumb…what is a png name (is that a zip code ?) and where should I use it on that site

No problem. When you find the station you are looking for and click on it, you see the prices appearing on the right. You need to get that image url in which you will find the picture *.png link.

1 Like

@sanderdw is there any progress in making the code public? It works fine, but I would like to not have to rely on external services to make this work. And I am just very curious how this service works

@donnie-dominguez, @wimb0, code is now public: https://github.com/sanderdw/Dutch-Gas-prices-API, unfortunately no time yet to properly rewrite and document the ocr logic (_search_value). Also i translated some things in English for the technical re-use & readability of it. This version is not implemented yet on the main server as endpoints are changed.

1 Like

@sanderdw Thanks!
I’m testing it now.
Seems to work so far :slight_smile: