# UK Petrol prices

**URL:** <https://discourse.nodered.org/t/uk-petrol-prices/95796>\
**Category:** Share Your Projects\
**Created:** [4 March 2025 18:17 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796 "2025-03-04T18:17:42Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)\
**Post date:** [4 March 2025 18:17 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/1 "2025-03-04T18:17:43Z")

</div>

I didn't realise, but ASDA supermarket publish fuel prices daily for every petrol station in the UK, check it out:

[https://storelocator.asda.com/fuel\_prices\_data.json](https://storelocator.asda.com/fuel_prices_data.json)

I mocked up a little map showing the lowest and highest price today (also shows my local store in Park Royal):

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a6b857804f2b4ac929dc0d2e39d090eb25ccb3e0.jpeg)

Also because - overkill - I'm logging local / highest / lowest / mean / median / mode prices hourly to InfluxDB 😂 That way I can track fuel prices over the course of weeks and years.

Actually, you may already know - but .gov.uk website has a list of all retailers who publish their fuel prices, I haven't checked yet but it's probably in a standard format - let's hope so. I may even be tempted to querying all the APIs at the same time to find the ultimate cheapest and most expensive fuel in the UK for a given day:

> **[Access fuel price data](https://www.gov.uk/guidance/access-fuel-price-data)**
>
> Links to data provided by suppliers as part of the temporary road fuel price open data scheme.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 March 2025 21:02 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/2 "2025-03-04T21:02:22Z")

</div>

Very nice, thanks for sharing.

For bonus points, now calculate the cheapest from a given location, taking into account the cost of getting to/from the station. 😄 🧙‍♂️

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 March 2025 21:14 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/3 "2025-03-04T21:14:34Z")

</div>

That would depend on car mpg and how much you wished to fuel up.  
I think it would be fair to say anything over 10 miles (probably a lot less) would be a false economy.

Here's a flow that polls all api's and will find all stations within 10 miles approx, ordered by fuel type required.

```auto
[{"id":"fe12ef283c46ba4e","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"distance","v":"0.1","vt":"num"},{"p":"lat","v":"50.801530","vt":"num"},{"p":"lon","v":"0.316918","vt":"num"},{"p":"fuel","v":"E10","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"https://applegreenstores.com/fuel-prices/data.json\",\"https://fuelprices.asconagroup.co.uk/newfuel.json\",\"https://storelocator.asda.com/fuel_prices_data.json\",\"https://www.bp.com/en_gb/united-kingdom/home/fuelprices/fuel_prices_data.json\",\"https://fuelprices.esso.co.uk/latestdata.json\",\"https://jetlocal.co.uk/fuel_prices_data.json\",\"https://api2.krlmedia.com/integration/live_price/krl\",\"https://www.morrisons.com/fuel-prices/fuel.json\",\"https://moto-way.com/fuel-price/fuel_prices.json\",\"https://fuel.motorfuelgroup.com/fuel_prices_data.json\",\"https://www.rontec-servicestations.co.uk/fuel-prices/data/fuel_prices_data.json\",\"https://api.sainsburys.co.uk/v1/exports/latest/fuel_prices_data.json\",\"https://www.sgnretail.uk/files/data/SGN_daily_fuel_prices.json\",\"https://www.shell.co.uk/fuel-prices-data.html\",\"https://www.tesco.com/fuel_prices/fuel_prices_data.json\"]","payloadType":"json","x":490,"y":6060,"wires":[["ab0d0df2abeee858"]]},{"id":"ab0d0df2abeee858","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":630,"y":6060,"wires":[["1e1b7bed0286ad7c"]]},{"id":"1e1b7bed0286ad7c","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":6060,"wires":[["2ee19cfc3466c7ce"]]},{"id":"2ee19cfc3466c7ce","type":"http request","z":"d1395164b4eec73e","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"},{"keyType":"Accept","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Accept-Language","keyValue":"","valueType":"en-GB, en-US, en;q=0.9","valueValue":""}],"x":530,"y":6120,"wires":[["52581137ac93d4de"]]},{"id":"52581137ac93d4de","type":"switch","z":"d1395164b4eec73e","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"}],"checkall":"true","repair":true,"outputs":1,"x":730,"y":6120,"wires":[["bce35881c2b3f73c"]]},{"id":"bce35881c2b3f73c","type":"join","z":"d1395164b4eec73e","name":"","mode":"reduce","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"$append($A, $$.payload.stations)","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":890,"y":6120,"wires":[["33551654cad32b49"]]},{"id":"33551654cad32b49","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[\t $abs(\t $number($.location.latitude) - $$.lat\t ) < $$.distance and \t $abs(\t $number($.location.longitude) - $$.lon\t ) < $$.distance \t]^($lookup($.prices, $$.fuel))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":6120,"wires":[["f6cc12f4a74b0d62"]]},{"id":"f6cc12f4a74b0d62","type":"debug","z":"d1395164b4eec73e","name":"debug 2581","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":6060,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)\
**Post date:** [4 March 2025 21:22 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/4 "2025-03-04T21:22:40Z")

</div>

Some fun automation ideas with fuel prices:

- find the cheapest within x mile radius from a given postcode (or maybe easier based on coordinates)
- for consultants who travel around: Query your Google calendar and notify you of cheap fuel en-route (Google maps api)
- Alternatively for people who vary their routes a lot: use geolocation (eg owntracks) to ping you when you are out, and you are not too far away from a cheap retailer
- reverse engineer the pricing strategies of different retailers. Eg by looking at price distribution by area, etc
- respond to eg Apple Siri Shortcut: when you press a home screen icon, the shortcut sends your coordinates to NodeRED which returns the prices for the nearest 15 retailers

Any other cool ideas?

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [4 March 2025 21:48 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/5 "2025-03-04T21:48:11Z")

</div>

Well our nearest petrol station is 8 mile away, so close. What distance does the 0.1 represent as a second supplier is 9 miles away and doesn't show up until 0.3?

Good quick flow though, thank you

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 March 2025 22:53 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/6 "2025-03-04T22:53:39Z")

</div>

Latitude is approx 69 miles per degree, longitude varies a lot more so the 69 miles approx at the equator and 0 at the north/south pole  
0.1 is approx 7 mile with latitude approx 5 miles for longitude in the UK, give or take a little.

You could add a separate distance for lat and lon to make it more accurate. Or may be calculate the hypotenuse taking the latitude into account when calculating the longitude. [The Distance Between Two Latitude and Longitude Coordinates](https://www.thoughtco.com/degree-of-latitude-and-longitude-distance-4070616)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 March 2025 23:15 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/7 "2025-03-04T23:15:02Z")

</div>

I upped the distance to 0.5, which returned 363 stations.

Number 1 in the list is, surprisingly, Esso at 139.7/litre for diesel.  
And Number 363 is ...  
Oh I thought it was Esso again, but in fact the ones at the end of the list don't have a price for diesel at all.  
So the Oscar for the most expensive diesel goes to - of course - Hilton Park Services at 172.9/litre

---

<div class="post-metadata">

**Author:** ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)\
**Post date:** [5 March 2025 09:06 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/8 "2025-03-05T09:06:28Z")

</div>

Does this flow compare coordinate values numerically to find the closest? A possible upgrade might be to use the Haversine formula. There's a possibility that a pure numerical comparison will give incorrect results (although the degree to which they are incorrect and the possibility this is true will depend on one's position on the globe). Maybe for simple / geographically close comparisons this method is good enough?

Shame it's not somehow possible to calculate distance between two postcodes without relying on an API like Google Maps... I wonder if there's a NodeRED addon that leverages downloadable roadmaps to do basic route calculation or similar?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [5 March 2025 12:43 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/9 "2025-03-05T12:43:16Z")

</div>

This is very cool. Whenever I see a .json datasource with a map, I think of Grafana [Geomap](https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/geomap/) + [Infinity Datasource](https://grafana.com/grafana/plugins/yesoreyeram-infinity-datasource/?tab=overview). I set one up [here](https://play.grafana.org/d/feex8f7fuwikgc/uk-petrol-prices?orgId=1&from=now-6h&to=now&timezone=utc) and mapped the colors acc. to the E10 price.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70455d425ee13cf250dfca84b5a9d9623ad7f701.jpeg)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 March 2025 14:18 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/10 "2025-03-05T14:18:52Z")

</div>

> [@hazymat](#):
>
> Maybe for simple / geographically close comparisons this method is good enough?

I think so as this is not launching a rocket to mars.

---

<div class="post-metadata">

**Author:** ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)\
**Post date:** [5 March 2025 14:41 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/11 "2025-03-05T14:41:57Z")

</div>

> [@E1cid](#):
>
> not launching a rocket to mars

Whilst that's true, the error could be as much as 1–2 miles in certain places where longitude distances shrink with latitude. Not so much of an issue in rural areas but in cities probably more so...

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 March 2025 15:19 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/12 "2025-03-05T15:19:21Z")

</div>

Yes, but you can limit that to less by adding a distance for lat and lon separately, and adjusting them for your position north or south of the equator. You could also use pythagorasa's theorem and calculate the hypotenuse of the the lat long positions, again adjusting for your position north or south.

My flow is a example of use and shows me all my local stations using 0.1. I do not need it to be over engineered and out by a mile or two i can live with or adjust

---

<div class="post-metadata">

**Author:** ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)\
**Post date:** [5 March 2025 15:36 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/13 "2025-03-05T15:36:31Z")

</div>

I think the joy of it is that there are many different possible solutions. Haversine formula is reasonably basic trig, and the best way to determine distance as the crow flies as it's universal depending on wherever you are on the globe.

That said, it's also reasonably useless compared with google maps, which accounts for actual roads / driving distance 🙂

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 March 2025 15:41 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/14 "2025-03-05T15:41:21Z")

</div>

Then the calculation would need to be done in a function node as JSONata lacks sin and cos and there are npm libraries [haversine - npm](https://www.npmjs.com/package/haversine)

Just arrived home here it is with a haversine function

```auto
[{"id":"fe12ef283c46ba4e","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"distance","v":"10","vt":"num"},{"p":"home","v":"{\"latitude\":50.80153,\"longitude\":0.316918}","vt":"json"},{"p":"fuel","v":"E10","vt":"str"},{"p":"unit","v":"mile","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"https://applegreenstores.com/fuel-prices/data.json\",\"https://fuelprices.asconagroup.co.uk/newfuel.json\",\"https://storelocator.asda.com/fuel_prices_data.json\",\"https://www.bp.com/en_gb/united-kingdom/home/fuelprices/fuel_prices_data.json\",\"https://fuelprices.esso.co.uk/latestdata.json\",\"https://jetlocal.co.uk/fuel_prices_data.json\",\"https://api2.krlmedia.com/integration/live_price/krl\",\"https://www.morrisons.com/fuel-prices/fuel.json\",\"https://moto-way.com/fuel-price/fuel_prices.json\",\"https://fuel.motorfuelgroup.com/fuel_prices_data.json\",\"https://www.rontec-servicestations.co.uk/fuel-prices/data/fuel_prices_data.json\",\"https://api.sainsburys.co.uk/v1/exports/latest/fuel_prices_data.json\",\"https://www.sgnretail.uk/files/data/SGN_daily_fuel_prices.json\",\"https://www.shell.co.uk/fuel-prices-data.html\",\"https://www.tesco.com/fuel_prices/fuel_prices_data.json\"]","payloadType":"json","x":490,"y":6060,"wires":[["ab0d0df2abeee858"]]},{"id":"ab0d0df2abeee858","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":630,"y":6060,"wires":[["1e1b7bed0286ad7c"]]},{"id":"1e1b7bed0286ad7c","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":6060,"wires":[["2ee19cfc3466c7ce"]]},{"id":"2ee19cfc3466c7ce","type":"http request","z":"d1395164b4eec73e","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"},{"keyType":"Accept","keyValue":"","valueType":"application/json","valueValue":""},{"keyType":"Accept-Language","keyValue":"","valueType":"en-GB, en-US, en;q=0.9","valueValue":""}],"x":530,"y":6120,"wires":[["52581137ac93d4de"]]},{"id":"52581137ac93d4de","type":"switch","z":"d1395164b4eec73e","name":"","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"num"}],"checkall":"true","repair":true,"outputs":1,"x":730,"y":6120,"wires":[["bce35881c2b3f73c"]]},{"id":"bce35881c2b3f73c","type":"join","z":"d1395164b4eec73e","name":"","mode":"reduce","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"$append($A, $$.payload.stations)","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":890,"y":6120,"wires":[["6d2511afd6049cfa"]]},{"id":"6d2511afd6049cfa","type":"function","z":"d1395164b4eec73e","name":"function 156","func":"const distance = (msg.distance || 1);\nconst fuel = (msg.fuel ?? \"E10\");\nconst unit = (msg.unit ?? \"mile\");\nconst home = msg.home;\n\nmsg.payload = msg.payload.filter(obj => {\n return haversine(\n home, \n obj.location,\n {unit: unit, threshold: distance}\n ) &&\n obj.prices[fuel]\n}).sort((a,b) => \n a.prices[fuel] - b.prices[fuel]\n);\n\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"haversine","module":"haversine"}],"x":1050,"y":6120,"wires":[["f6cc12f4a74b0d62"]]},{"id":"f6cc12f4a74b0d62","type":"debug","z":"d1395164b4eec73e","name":"debug 2581","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":6060,"wires":[]}]

```

If no fuel of type require then the station is removed also.  
The units can be `km, mile, meter, nmi` default mile, distance has a default of 1, can be a float.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [5 March 2025 20:26 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/15 "2025-03-05T20:26:02Z")

</div>

Figured out why the second nearest petrol station not shown, Tesco do not include all Tesco Express operations.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 March 2025 22:58 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/16 "2025-03-05T22:58:52Z")

</div>

A nice open source alternative routing api to google is [OSRM API Documentation](https://project-osrm.org/docs/v5.5.1/api/#general-options)

The simple correction for the variation in east-west “distance” as you go further north is to multiply by Cosine of the latitude. Eg your 69 miles per degree

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [3 May 2025 19:22 UTC](https://discourse.nodered.org/t/uk-petrol-prices/95796/17 "2025-05-03T19:22:08Z")

</div>

> [@hazymat](#):
>
> but ASDA supermarket publish fuel prices daily for every petrol station in the UK, check it out:
> 
> [https://storelocator.asda.com/fuel\_prices\_data.json](https://storelocator.asda.com/fuel_prices_data.json)

In Germany you can use [https://tankerkoenig.de/](https://tankerkoenig.de/)  
They have an API: [https://creativecommons.tankerkoenig.de/](https://creativecommons.tankerkoenig.de/)  
(seems to be all in german)

I use this API to generate this part of my Dashboard:

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27248ee6a4f6eba3b809e06c4757d98a5352f8df.png)

and additionally provide some "best of [2-6] days" price informations via Telegram group:

> **[Diesel-Bodersweier](https://t.me/diesel_bo)**
>
> Dieselpreise in Bodersweier

There you can preview the messages, which I generate from Node-RED.  
I can provide the flow, if anyone is interested.
