Gas Pricing Plus Oil

Everyone loves it with the price of fuel right now! :slight_smile:

Can someone please post the text of a complete working sensor?
I am missing something between resource and select, I believe.

Thank you

An example was posted by myself further up the thread.

Not sure what else you need besides that, that is a scrape sensor.

Thank you so much for putting this together! Really made things easy to setup.

1 Like

I’m getting the following error in validation when I try to add this to my configuration.yaml

Invalid config for [sensor.scrape]: string value is None for dictionary value @ data['select']. Got None. (See ?, line ?).
Invalid config for [sensor.scrape]: string value is None for dictionary value @ data['select']. Got None. (See ?, line ?).

Any thoughts?

I use a split config setup and do not add stuff like this to my config file so I’m not much help.

Leveraging your config file you will most likely need to add it like this.

sensor:
  - platform: scrape
    resource: "https://oilprice.com/oil-price-charts/#WTI-Crude"
    name: Oil Per Barrel
    select: '#pagecontent > div.siteContainer.oilprices > div.oilprices__centercolumn'
    scan_interval: 3600

Please read the scrape integration documentation.

Thanks for that demo code - my select didn’t have the ’ ’ around the content. That did the trick!

For you information, a specific integration has been build to get similar fuel and oil data for several countries in Europe: Belgium, France, Luxembourg, Netherlands, Italy and Germany: https://github.com/myTselection/Carbu_com
Maybe some of the setup of this integration can be re-used to build something similar for other countries. On request I may also be able to further extend that extension to cover extra countries.

If you have time to extend for U.S. I’m sure others would appreciate very much. I do not currently have the time to invest.

I could take a look into it. Any good site available with daily actual prices?

Only one I know of that usually stays up to date. https://www.gasbuddy.com/

I’ve tried to integrate it, but it seems protected with cloudflare human control now. so far, I didn’t find a workaround…

Hey guys, I’m having trouble getting this sensor to work. I’m not getting any errors, but the entity is not populating:

sensor:
  - platform: scrape
    resource: "https://www.gasbuddy.com/station/34888"
    name: Costco Gas
    select: '#root > div > div.Page-module__content___196kn.Page-module__padded___3hQ0U > div > div > div:nth-child(2) > div.grid__column___nhz7X.grid__desktop10___2T18R > div:nth-child(1) > div.grid__column___nhz7X.grid__desktop8___38Y4U > div:nth-child(3) > div > div.GasPriceCollection-module__collectionContainer___29Ngz > div:nth-child(2) > div:nth-child(1) > span'
    scan_interval: 3600
1 Like

Got it! Looking at the post above linking to the “scrape” documentation the code should be the following:

scrape:
  resource: https://www.gasbuddy.com/station/34888
  scan_interval: 3600
  sensor:
    - name: Costco Gas
      select: "#root > div > div.Page-module__content___196kn.Page-module__padded___3hQ0U > div > div > div:nth-child(2) > div.grid__column___nhz7X.grid__desktop10___2T18R > div:nth-child(1) > div.grid__column___nhz7X.grid__desktop8___38Y4U > div:nth-child(3) > div > div.GasPriceCollection-module__collectionContainer___29Ngz > div:nth-child(2) > div:nth-child(1) > span"
1 Like

And your Costco fuel is so much higher than ours. Gotta love Cali :wink:

Yeah… I wish I lived elsewhere, but I’m currently stuck here. Once I have kids and they are about to go into public school, we may seriously consider moving out of state if we can’t get them in private school/home school.

The golden handcuffs. I get paid too well for my job, but I’m bored, and earning a state pension.

Now back on topic, I took the same inputs and applied to to the price per barrel of oil above. That sensor won’t scrape data. Anyone have that working? Or preferably both working and an example?

I want to create a chart trend and have it alert me on trend shifts so I know when it’s a good time to get gas or not. Gas price is usually a week or 2 behind oil pricing. If oil is trending down but gas is still trending up I want the trend senor to say “don’t buy” if both are trending up it’ll say “trending up” if both are trending down it’ll say “trending down” and if oil is trending up but gas isn’t trending up yet, it’ll say “buy” and send me a notification.

If you need it, this is the integration for Gas prices in Portugal:

For oil I use:

https://oilprice.com/oil-price-charts/#WTI-Crude

#pagecontent > div.siteContainer.oilprices > div.oilprices__centercolumn > table:nth-child(1) > tbody.row_holder > tr:nth-child(1) > td.last_price

Hopefully that helps.

What’s the YAML you are using to create/update the sensor. That’s what I have mine set to.

scrape:
  - resource: https://www.gasbuddy.com/station/34888
    scan_interval: 3600
    sensor:
      - name: Costco Gas
        select: "#root > div > div.Page-module__content___196kn.Page-module__padded___3hQ0U > div > div > div:nth-child(2) > div.grid__column___nhz7X.grid__desktop10___2T18R > div:nth-child(1) > div.grid__column___nhz7X.grid__desktop8___38Y4U > div:nth-child(3) > div > div.GasPriceCollection-module__collectionContainer___29Ngz > div:nth-child(2) > div:nth-child(1) > span"
  - resource: https://oilprice.com/oil-price-charts/#WTI-Crude
    scan_interval: 3600
    sensor:
      - name: Oil Per Barrel
        select: "#pagecontent > div.siteContainer.oilprices > div.oilprices__centercolumn > table:nth-child(1) > tbody.row_holder > tr:nth-child(1) > td.last_price"