To avoid multiple request to the site for every gasstation I created a template to extract the data from the commandline sensor to sepperate entities. This I did with the following sensors:
Works perfect! Too bad the Tamoil close by doesn’t give any information via www.brandstof-zoeker.nl.
But even for a n00b like me, I got it working. Thanks!
Tinq has recenlty done an update on their site, so the example in this topic doesn’t work anymore.
I am now playing with BeautifulSoup to get the diesel price from my local fueling station, but I have too little experience to get there. Is there anyone able to help?
And that’s where I’m stuck at the moment. I see the correct price in the content tag, so that would be the easiest place in my opinion to get the price from, but how do I get it from there?
edit: sometimes it helps to ask for help to get to the sollution yourself
looking at the example from @legoracers I found the following sollution:
Let me know what you think. Later on i can make it run faster (it’s on a slow server now). For now it supplies the gasoline and diesel prices. ocr_station is just an indication of the first OCR line in the image, so don’t use it.
I was just playing with the scrape function but I was not able to get the data from the esso and shell sites so I will look to your solution. I’ll tried a few and it seems to work fine, not slow at all. As a copy-paste programmer I have to look how to get the data into 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.
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
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
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.