Austrian fuel prices from Spritpreisrechner

Hy,
The indention of third and fourth line (headers and accept) is wrong.
There was mistake during copying to the forum, I’ve already changed my post.

1 Like

Hi there,

@FPro first thanks for the thread, very helpful.

Everything works as desired, the three cheapest gas stations in the area are displayed dynamically. But now I want to get the price of a specific gas station with the associated price? For example, the gas station with the ID 4143:

{
      "id":4143,
      "name":"Disk",
      "location":{
         "address":"Milser Straße 22",
         "postalCode":"6060",
         "city":"Hall",
         "latitude":47.2831587,
         "longitude":11.519987
      },
      "contact":{
         "telephone":"435022776061",
         "fax":"435022774061",
         "mail":"[email protected]",
         "website":"http://www.gutmann.cc"
      },
      "openingHours":[
         {
            "day":"MO",
            "label":"Montag",
            "order":1,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"DI",
            "label":"Dienstag",
            "order":2,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"MI",
            "label":"Mittwoch",
            "order":3,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"DO",
            "label":"Donnerstag",
            "order":4,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"FR",
            "label":"Freitag",
            "order":5,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"SA",
            "label":"Samstag",
            "order":6,
            "from":"06:00",
            "to":"20:00"
         },
         {
            "day":"SO",
            "label":"Sonntag",
            "order":7,
            "from":"07:00",
            "to":"19:00"
         },
         {
            "day":"FE",
            "label":"Feiertag",
            "order":8,
            "from":"07:00",
            "to":"19:00"
         }
      ],
      "offerInformation":{
         "service":false,
         "selfService":true,
         "unattended":false
      },
      "paymentMethods":{
         "cash":true,
         "debitCard":true,
         "creditCard":true,
         "others":"Gutmann-Card"
      },
      "paymentArrangements":{
         "cooperative":false,
         "clubCard":false
      },
      "otherServiceOffers":"CARWASH",
      "position":1,
      "open":true,
      "prices":[
         {
            "fuelType":"SUP",
            "amount":1.717,
            "label":"Super 95"
         }
      ]
   },

I would now like to receive the current price for this gas station, no matter how it is ranked. I’ve tried adding the ID directly to the URL, but to no avail.

It would be great if someone could help me with this!

Hi,

the API doesn’t allow this directly (see e-control FAQ).

But you can implement a template sensor that loads the value from the cheapest sensors.
Below you find a simple script to do that.

{% set station_id = 1471127 %}
{% if state_attr('sensor.fuel_price_bruck_die_1', 'id') == station_id %}
{{ states('sensor.fuel_price_bruck_die_1') }}        
{% elif state_attr('sensor.fuel_price_bruck_die_2', 'id') == station_id %}
{{ states('sensor.fuel_price_bruck_die_2') }}        
{% elif state_attr('sensor.fuel_price_bruck_die_3', 'id') == station_id %}
{{ states('sensor.fuel_price_bruck_die_3') }}     
{% elif state_attr('sensor.fuel_price_bruck_die_4', 'id') == station_id %}
{{ states('sensor.fuel_price_bruck_die_4') }}  
{% elif state_attr('sensor.fuel_price_bruck_die_5', 'id') == station_id %}
{{ states('sensor.fuel_price_bruck_die_5') }}  
{% else %}
unavailable
{% endif %}
1 Like

Thanks @matrixx567, that was exactly what i needed!

Thank you @FPro for the idea and @matrixx567 for the card design, that help me how to do this for my country and it’s API.

https://community.home-assistant.io/t/cheapest-5-gas-stations-in-your-zone-city-spain/

Hi,

you could also just filter the json data - no need for a script.
Here is my configuration for a sensor with specified id (value_template info came from @petro @Craig_McGowan in this thread):

      - name: Diesel F.Leitner Leoben
        unit_of_measurement: €
        device_class: monetary
        value_template: "{{(value_json | selectattr('id','eq',1469006) | list | first).prices[0].amount}}"
        json_attributes_path: "$.[?(@.id== 1469006)].location"
        json_attributes:
          - latitude
          - longitude

You would only need to adapt the id to in value_template and json_attributes_path to make it work for you. I extracted lat/long as attributes, so that ha shows the fuel stations on the map.

br

2 Likes

Great work, loving it!

Just one little improvement for the address in the secondary information, you might want to use |title instead of |capitalize which (in my case) will render “innsbrucker bundesstraße” to “Innsbrucker Bundesstraße” instead of “Innsbrucker bundesstraße” :wink:

1 Like

Hy,

I’ve implemented an improved version of the lovelace card using auto-entities

type: custom:auto-entities
card: 
  type: entities
  title: Bruck an der Mur
filter:
  include:
    - entity_id: "sensor.fuel_price_bruck_die_*"
      options:
        type: custom:template-entity-row
        icon: mdi:gas-station-outline
        state: >
          {% set state=states(config.entity) %}
          {% if state != 'unknown' %}
          {% set state = state + " " + state_attr(config.entity, 'unit_of_measurement') %}
          {% endif %}
          {{state}}
        name: "{{state_attr(config.entity, 'name')}}"
        secondary: >-
          {{state_attr(config.entity, 'location')['postalCode']}}
          {{state_attr(config.entity, 'location')['city']}},
          {{state_attr(config.entity, 'location')['address']|title}}
sort:
  method: state
1 Like

Wow, thanks for sharing! That’s great!

But maybe edit your original post to include this solution.
Would have saved me some time to edit all the config and throw it away again! :smiley:

Pretty sure others would appreciate to avoid to wast the time as well.

But really, that’s great.
Thanks again :slight_smile:

I’m also using your solution now. Really great work that is much appreciated!

Hi @pachi,
sorry for my late feedback, i must have overlooked your post.
Anyway, i implemented the filter and it works great, that’s what i was looking for!
Thanks for sharing and best regards,
Chris

2 Likes

Hi! I also tried this snippet but I always get the first entry.
Can someone support me in this regard? → to get data from a specific gas station…
Thx, Chris

Hi, what does your filter look like and what entries do you want to see?

Currently, I can only see the first entry (it’s a list of many gas stations but I only get the first entry).
To verify the data - i used in HASSIO developer mode to check the sensor status (I can see the value, the name of the gas station, etc.) and compared with Firefox (it automatically creates a readable JSON) - same entries. I checked SUP and DIE (HASSIO and Firefox) - it’s the same.
→ I want to get some values from a specific gas station as already mentioned - there’s an ID which I can use but - no change the get the values for one specific.

I also tried this one:

value_template: "{{(value_json | selectattr('id','eq',1469006) | list | first).prices[0].amount}}"
        json_attributes_path: "$.[?(@.id== 1469006)].location"

But without any success.

Any ideas?

Hallo ich habe es versucht aber irgendwie bekomme ich es nicht zum laufen steht immer unknow

rest:
  - resource: https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=47.405965&longitude=15.261849&fuelType=DIE&includeClosed=true
    headers:
      accept: application/json
    scan_interval: 1800
    sensor:
      - name: fuel_price_bruck_die_1
        device_class: monetary
        value_template: "{{ value_json[0]['prices'][0]['amount'] }}"
        unit_of_measurement: "EUR"
        force_update: True
        json_attributes_path: "$[0]"
        json_attributes:
          - name
          - id
          - location
      - name: fuel_price_bruck_die_2
        device_class: monetary
        value_template: "{{ value_json[1]['prices'][0]['amount'] }}"
        unit_of_measurement: "EUR"
        force_update: True
        json_attributes_path: "$[1]"
        json_attributes:
          - name
          - id
          - location
      - name: fuel_price_bruck_die_3
        device_class: monetary
        value_template: "{{ value_json[2]['prices'][0]['amount'] }}"
        unit_of_measurement: "EUR"
        force_update: True
        json_attributes_path: "$[2]"
        json_attributes:
          - name
          - id
          - location
      - name: fuel_price_bruck_die_4
        device_class: monetary
        value_template: "{{ value_json[3]['prices'][0]['amount'] }}"
        unit_of_measurement: "EUR"
        force_update: True
        json_attributes_path: "$[3]"
        json_attributes:
          - name
          - id
          - location
      - name: fuel_price_bruck_die_5
        device_class: monetary
        value_template: "{{ value_json[4]['prices'][0]['amount'] }}"
        unit_of_measurement: "EUR"
        force_update: True
        json_attributes_path: "$[4]"
        json_attributes:
          - name
          - id
          - location

wo habe ich denn hund drinnen?

Hi, hast du es hinbekommen?

Hab das gleiche Problem und finde auch den Fehler nicht…oder funktioniert die API nicht mehr?
Bin eher Neuling auf dem ganzen Gebiet :wink:

Edit: habs nun hinbekommen indem ich bei mir die URL angepasst hab von der Vorgabe hier im Forum und nicht die generierte URL von der Swagger Ui genommen habe…nun läuft alles wie es soll!

Vielen Dank!

lg Richi

Hallo, kann mir vielleicht wer helfen diese Fehler weg zu bekommen.

Logger: homeassistant.helpers.template
Source: helpers/template.py:2209
First occurred: 11:42:25 (15 occurrences)
Last logged: 11:42:25

Template variable warning: 'None' has no attribute 'postalCode' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'
Template variable warning: 'None' has no attribute 'city' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'
Template variable warning: 'None' has no attribute 'address' when rendering '{{state_attr(config.entity, 'location')['postalCode'] }} {{state_attr(config.entity, 'location')['city'] }}, {{state_attr(config.entity, 'location')['address']|title}}'

Ich verwende folgenden Sensor Code:

    - name: diesel_preise_tankstelle_5
      device_class: monetary
      value_template: "{{ value_json[4]['prices'][0]['amount'] | default(0) | float }}"
      unit_of_measurement: "EUR"
      force_update: True
      json_attributes_path: "$[4]"
      json_attributes:
        - name
        - id
        - "location"

Does anyone have any advice for me on how I can have the name and price of the gas station sent to my cell phone? I’ve only gotten so far that I can have all the data sent to me from the sensor, but I just want the price and the name of the gas station, maybe the address, but nothing more

This is what it looks like at the moment:

<template TemplateState(<state sensor.fuel_price_bruck_die_1=1.599; name=freie Tankstelle, id=34019, location=address=Salzburgerstr. 35, postalCode=4713, city=Gallspach, latitude=, longitude=, unit_of_measurement=EUR, device_class=monetary, friendly_name=fuel_price_bruck_die_1 @ 2024-02-04T19:16:54.344159+01:00>)>

Anybody an idea why some gas stations shows prices for diesel but not for Super?
“spritpreisrechner.at” shows only"
image