Home Assistant Integration

Oil & Gas PricesOn Your Dashboard

Turn Brent, WTI, Henry Hub, diesel, or heating-oil prices into native Home Assistant sensors with one copy-paste REST sensor β€” no custom component, no HACS install, and a polling interval that stays inside the free tier.

1. Add the REST sensor

Home Assistant's built-in rest sensor platform calls the API on a schedule and stores the price as a sensor state. Paste this into configuration.yaml, replace YOUR_API_KEY, and restart Home Assistant (or reload YAML from Developer Tools):

# configuration.yaml
sensor:
  - platform: rest
    name: Brent Crude Price
    unique_id: oilpriceapi_brent_crude
    resource: https://api.oilpriceapi.com/v1/prices/latest?by_code=BRENT_CRUDE_USD
    method: GET
    headers:
      Authorization: Token YOUR_API_KEY
    # The API returns {"status":"success","data":{"price":...,"currency":"USD",
    # "code":"BRENT_CRUDE_USD","created_at":"...","type":"spot_price"}}
    value_template: "{{ value_json.data.price }}"
    json_attributes_path: "$.data"
    json_attributes:
      - code
      - currency
      - created_at
      - type
    unit_of_measurement: "USD"
    # 1800 s = 48 requests/day.
    # 48 requests per day
    # stays within the Free allowance of 50 requests per day.
    scan_interval: 1800
Why scan_interval: 1800? A day has 86,400 seconds, so this makes 48 polls per day and 48 requests per day. The Free tier includes 50 requests per day (see the pricing page for current limits), so the generated interval stays inside the declared window. Faster polling may require a paid plan.

2. Keep the key in secrets.yaml

Home Assistant supports !secret references so credentials never live in the main config file:

# Better: keep the key out of configuration.yaml.
# secrets.yaml
oilpriceapi_auth: Token YOUR_API_KEY

# configuration.yaml
sensor:
  - platform: rest
    name: Brent Crude Price
    resource: https://api.oilpriceapi.com/v1/prices/latest?by_code=BRENT_CRUDE_USD
    headers:
      Authorization: !secret oilpriceapi_auth
    value_template: "{{ value_json.data.price }}"
    unit_of_measurement: "USD"
    scan_interval: 1800

3. Show it on a Lovelace card

Once the sensor has a state, any card can display it. A sensor card gives you the current value plus a trend line:

# Lovelace: a sensor card with a 24 h trend line
type: sensor
entity: sensor.brent_crude_price
name: Brent Crude
graph: line
detail: 2
hours_to_show: 24
# Or several prices in one entities card
type: entities
title: Energy Prices
entities:
  - entity: sensor.brent_crude_price
    name: Brent Crude (USD/bbl)
  - entity: sensor.henry_hub_price
    name: Henry Hub Natural Gas

To track a second commodity, add another REST sensor with a different by_code (for example NATURAL_GAS_USD for Henry Hub, or WTI_USD for WTI). For two sensors, use a scan interval of at least 3600 seconds on each sensor. That produces 48 combined requests per day, within the 50 requests per day Free allowance. The code guide lists valid commodity codes.

Ideas: automate on price moves

  • Notify your phone when heating oil drops below your refill threshold.
  • Show diesel or gasoline benchmarks next to your EV charging dashboard.
  • Log prices to Home Assistant's long-term statistics and compare against your actual utility bills.