Fuel/Gas Prices integration

I’ve just released version 2024.11.0 which should fix these issues. It seems data collection by region is quite complex compared to what it once was as they split out into hundreds of different sub-regions (postal code areas).

While testing their API wasn’t returning fuel price information.

1 Like

You are the best :slight_smile:
Its working for me

1 Like

I have one additional question, not directly related to the plugin
I would like to create a button on dashboard to start a navigation in Android to the Cheapest Station. This would mean i would need to extract the address attribute from the entity and then configure a button.
Anybody did something like this already or has an tip how to do this?

I’ve used a notification to do it (button on home screen to get cheapest station in 5 miles, then an action within the notification to start navigation), but you might be able to broadcast an intent instead. Because I’m in the UK, I can use the name of the fuel station to navigate, but to use the address you would just change data.fuels[0]['name'] within the uri action at the bottom to data.fuels[0]['address']

sequence:
  - data:
      type: B7
      location:
        latitude: |
          {{ state_attr('device_tracker.sm_s918b', 'latitude') | float }}
        longitude: |
          {{ state_attr('device_tracker.sm_s918b', 'longitude') | float }}
        radius: |
          {{ 5 * 1609.34 }}
    response_variable: data
    action: fuel_prices.find_fuels
  - if:
      - condition: template
        value_template: "{{ (data.fuels | count) > 0 }}"
    then:
      - metadata: {}
        data:
          title: Fuel Search Result
          message: |-
            Cheapest Fuel Station: {{ data.fuels[0]['name'] }}
            Price (per litre): {{ data.fuels[0]['cost'] }}
          data:
            car_ui: true
            notification_icon: mdi:car
            actions:
              - action: URI
                title: Navigate
                uri: |
                  {{ "deep-link://waze://?q=" + data.fuels[0]['name'] }}
        action: notify.mobile_app_sm_s918b

This is really cool, thanks.
So this means you created a action to check which are the cheapest prices based on your phone location?
Could you share this code with us? Exactly this was something i would like to achieve, but wanted to start with something simpler :smiley:

No problem, yes this is based on the location of my phone, the above code block contains the sequence of the script itself that I created in Home Assistant.

I have another script that takes into account the current fuel level in my car, calculates how much it will cost to fill and sends a similar notification.

Replace device_tracker.sm_s918b in the above with the entity ID of your own device tracker, and notify.mobile_app_sm_s918b with the notify service. Might need to change the Price (per litre) too if measured differently.

Just updated to HA Core 24.11.3 and on reload Fuel Prices now fails to setup. Any clues? This was in log:

2024-11-23 10:30:52.530 ERROR (MainThread) [custom_components.fuel_prices]
2024-11-23 10:30:52.531 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Fuel Prices for fuel_prices
Traceback (most recent call last):
File “/config/custom_components/fuel_prices/init.py”, line 67, in async_setup_entry
await fuel_prices.update()
File “/usr/local/lib/python3.12/site-packages/pyfuelprices/init.py”, line 37, in update
await asyncio.gather(*coros)
File “/usr/local/lib/python3.12/site-packages/pyfuelprices/init.py”, line 31, in update_src
await s.update(areas=a, force=f)
File “/usr/local/lib/python3.12/site-packages/pyfuelprices/sources/uk/shell.py”, line 52, in update
raise UpdateFailedError(
pyfuelprices.sources.UpdateFailedError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 635, in __async_setup_with_context
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/fuel_prices/init.py”, line 73, in async_setup_entry
raise CannotConnect from err
custom_components.fuel_prices.CannotConnect

The SPS token for Shell expired on 21st, update the integration to 2024.11.2 and it will fix it.

Thanks - that sorted it. Thanks for you response and work on this!

Hi,

i think the “fuel_prices.find_fuels” Action is not working for me (spritpreisrechner)
I tried many locations in austria, everywhere the same.

Debug Log:

Log:
2024-11-26 21:54:45.163 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Error for call_service at pos 1: Country not available for fuel data.
2024-11-26 21:54:45.163 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140166632678464] Error handling message: Country not available for fuel data.

When i try the find fuel stations, i get data back for the fuel stations

@poudenes - I’ve started a direct conversation with the company behind DirectLease, they are keen to help us out too. Solution could be coming soon!

1 Like

ohh wow… you’re doing a great job with them!!!

1 Like

Hi @11harveyj
about this problem, should i create a github issue or did i set something wrong?

I just use multiscrape, i scrape germany and belgium prices at once.
works perfect and its EZ… doing it for years now :slight_smile:

Did you get any where with petrolprices.com? Whilst the data sources for the uk are good here i find petrol prices better as it includes more, for example my two nearest petrol stations aren’t included on this because they’re independent and they’re normally the cheapest as well!

Either way though i’m loving the integration!

On the back burner at the moment unfortunately as have been busy with other projects. If you can somehow get missing retailers to publish their fuel price feeds using the CMA spec (Access fuel price data - GOV.UK) then it’d be easy to add in. But I don’t think its as easy as that lol

First off want to say thank you for this custom integration was something I have been looking to find for ages! I have installed it and appear to have configured it correctly as it manages to find the 6 stations within my radius that I wanted, however where do I actually view the prices and how can I have them display on a dashboard?

Sorry I am pretty crap at these things so may need explaining like I’m a 5 year old!


Hi,

There is some history in this thread going back around displaying the data (I knocked this up quickly a while ago but requires some extra UI components installed) Fuel/Gas Prices integration - #14 by 11harveyj

I also came across this article a while ago too
https://keestalkstech.com/home-assistant-track-your-favourite-fuel-stations/

I do a “Integration” of Andorra Fuel/Gas prices with command line. If it’s helpful.

1 Like

Looks like that might use some Ajax calls so could potentially add as a source