Fuel/Gas Prices integration

You are right, i can see in another major city the data, but not in the searched smaller city.
5 miles radius would be enough for stations.
When i check Spritpreisrechner, both are showing results.

Working:
48.277495
14.294849
5miles

Not working: (or only showing 4 from 10 possible stations)
48.212120650046984
14.287071446311938
5miles

Thank you, I will take a look. Perhaps there is some new API configurations that need to be applied.

1 Like

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: