Recently I did some digging how to incorporate Austrian fuel prices into HA. Since there might be others interested in this topic I decided to share my findings.
Where to get the data
Every site that you can check fuel prices on (like ÖAMTC, ARBÖ,…) bases its data on those by Spritpreisrechner.at. You can query this data via the E-Control Sprit API.
The first step is to go to the API documentation and build yourself a request URL. You can either do that by region (Bezirk or Bundesland) or by geo coordinates. Since I only want fuel stations nearby I chose geo coordinates. Navigate in the search section to GET /search/gas-stations/by-address and hit “Try it out”.
Update 2023: The URLs built by swagger are for some reason wrong. you need to replace “api” in the part after the domain with “sprit/1.0”
Get your geo coordinates for example on latlong.net and enter them. Choose your fuel type and whether you want to include closed stations. Hit “execute” and copy the request URL.
Setting up HA
In your configuration.yaml set up the rest platform and some sensors.
rest:
- resource: my_request_URL
scan_interval: 1200
sensor:
- name: Diesel Preis 1
value_template: "{{ value_json[0]['prices'][0]['amount'] }}"
unit_of_measurement: "€"
- name: Diesel Name 1
value_template: "{{ value_json[0]['name'] }}"
- name: Diesel Preis 2
value_template: "{{ value_json[1]['prices'][0]['amount'] }}"
unit_of_measurement: "€"
- name: Diesel Name 2
value_template: "{{ value_json[1]['name'] }}"
- name: Diesel Preis 3
value_template: "{{ value_json[2]['prices'][0]['amount'] }}"
unit_of_measurement: "€"
- name: Diesel Name 3
value_template: "{{ value_json[2]['name'] }}"
In this example I made for each of the 3 cheapest fuel stations in my area a sensor for its name and the price.
It is important to set a reasonable scan interval. If you don’t, your request URL (not your IP) will get banned for a day.
The JSON response is a list of all fuel stations. The first 5 are ordered by price and have price values in them, for the rest there are no prices. So by choosing the first element [0] you get the cheapest one and so on. Basically this makes it almost impossible to track the prices of a specific fuel station, but you can get an overview of the prices and where you can refuel the cheapest.
Here’s how it looks in my dashboard (using a fake location):