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 = poll every 30 minutes = 48 requests/day.
    # The free tier allows 50 requests per DAY, so 48 fits with room to spare.
    scan_interval: 1800
Why scan_interval: 1800? A day has 86,400 seconds; 86,400 Γ· 1,800 = 48 polls per day. The free tier includes 50 requests per day (see the pricing page for current limits), so a 30-minute interval keeps the sensor inside the free cap around the clock. Polling every 15 minutes (900 s) would be 96 requests/day β€” over the free cap, but fine on any paid plan. Commodity benchmarks do not tick second-by-second, so 30-minute polling loses almost nothing.

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). Two sensors at 30-minute polling is 96 requests/day β€” beyond the free tier's 50/day, so either widen the intervals (3600 s each = 48/day total) or use a paid plan. 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.