German Fuel Prices

Thats my configuration to see the fuel prices for my often used petrol stations (Germany):

  • Create an API-Key on creativecommons.tankerkoenig.de
  • Get station ID’s from the finder: TankstellenFinder
  • Create an json sensor in configuration to retrieve prices from Tankerkoenig and a template sensor per station/attribute (eg. Diesel)
  • Some logos I stored in /config/www/fuel
sensor:

  - platform: rest
    name: Fuel
    resource: "https://creativecommons.tankerkoenig.de/json/prices.php?apikey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&ids=22301ffd-8110-47c6-a9d6-2bf873a10c72,c18cef16-99cc-4f8e-b959-e6ab6521d2be"
    scan_interval: 900
    verify_ssl: false
    value_template: '{ value_json.prices.[] }'
    json_attributes:
    - prices

  - platform: template
    sensors:
      bft_wolfhagen_diesel:
        friendly_name: Wolfhagen
        unit_of_measurement: €
        entity_picture_template: /local/fuel/bft.png
        value_template: '{{ states.sensor.fuel.attributes["prices"]["22301ffd-8110-47c6-a9d6-2bf873a10c72"]["diesel"]}}'
  • For Lovelace sorting I used the custom auto-entiies card:
type: custom:auto-entities
card:
  type: entities
  show_header_toggle: false
  state_color: false
  title: Diesel-Preise
filter:
  include:
    - entity_id: sensor.*diesel
  exclude: []
sort:
  method: state
  reverse: false
  numeric: true
show_empty: false

2 Likes

There is an integration for that:

And with that, this is the only code I have in my configuration:

tankerkoenig:
  # https://www.home-assistant.io/integrations/tankerkoenig/
  api_key: 99d55e5d-9999-1111-f543-d1c11a999cd9
  radius: 1
  fuel_types:
    - "diesel"
    - "e10"
  scan_interval: "0:15:01"
  stations:
    - awergfghi-9999-654a-a4a8-9c9bf99b9c9d

Sensors are then automatically there, no need for manual configuration.

2 Likes

Are you sure you want to post your API key in public?

I am sure that I don‘t (even though I just use a throw away mail/account for that and in the worst case it would get blocked if too many use it), and that is why you see quite a lot of the same numbers in there :wink:

To exclude the closed stations I used the filter exclude.

unknown = closed

type: custom:auto-entities
card:
  type: entities
  show_header_toggle: false
  state_color: false
  title: Super E10-Preise
filter:
  include:
    - entity_id: sensor.*_super_e10
  exclude:
    - state: unknown
sort:
  method: state
  reverse: false
  numeric: true
show_empty: false