Smart home

Visualizing Hourly Electricity Prices in Home Assistant Using AMS Reader and ApexCharts

If you have ever tried to visualize future electricity prices in Home Assistant, you already know the pain. There are spinning cards, unknown states, and charts that simply refuse to show.

Advertisements

In this post, I’ll walk through a robust and actually working solution for visualizing hourly future power prices using:

  • An AMS reader as the data source
  • Home Assistant
  • apexcharts-card for visualization

Along the way, we’ll also look at the reasons why AMS-based pricing offers advantages over Nordpool’s 15‑minute price model. This is especially true when it comes to dashboards and automations.


Why AMS Reader for Power Prices?

Many Home Assistant users rely on the Nordpool integration for electricity prices. That works well, but it comes with a few downsides:

  • Prices are often exposed as 15‑minute intervals
  • This means 96 data points per day
  • Visualizations become noisy
  • Automations need extra logic to group prices into hours

An AMS (Advanced Metering System) reader, on the other hand, often exposes prices as clean hourly values:

  • One price per hour
  • Simple naming: price0 = now, price1 = next hour, etc.
  • Perfect match for how most people think about electricity prices

In my setup, the AMS reader exposes sensors like:

sensor.ams_ba4a_prices0

sensor.ams_ba4a_prices1

sensor.ams_ba4a_prices34

That gives us 35 hours of future prices, already aligned to whole hours. Perfect.


The Visualization Challenge

At first glance, this sounds easy:

“Just put the sensors in a graph card.”

Unfortunately, most graph cards in Home Assistant expect historical time series, not future values. That leads to common problems:

  • Cards stuck in a permanent loading state
  • Missing bars or lines
  • unknown values breaking the entire chart

After a lot of experimentation, the solution turned out to be ApexCharts + data_generator.


The Key Idea: Generate the Time Series Yourself

Instead of relying on Home Assistant’s history database, we:

  1. Read the current state of each AMS price sensor
  2. Assign it a future timestamp (now + N hours)
  3. Feed the resulting [timestamp, value] pairs directly to ApexCharts

This bypasses all the usual problems with future data.


The ApexCharts Configuration

Here is the full working card configuration used in my dashboard:

type: custom:apexcharts-card
header:
  show: true
  title: AMS Price Forecast
  show_states: false
graph_span: 35h
span:
  start: hour
now:
  show: false
series:
  - entity: sensor.ams_ba4a_prices0
    name: Price
    type: column
    curve: stepline
    float_precision: 3
    data_generator: |
      const prices = [];
      const now = new Date();
      now.setMinutes(0, 0, 0);
      for (let i = 0; i <= 34; i++) {
        const entityId = `sensor.ams_ba4a_prices${i}`;
        const stateObj = hass.states[entityId];
        if (stateObj && stateObj.state !== 'unavailable') {
          const value = parseFloat(stateObj.state);
          const time = now.getTime() + i * 3600000;
          prices.push([time, Number(value.toFixed(3))]);
        }
      }
      return prices;
yaxis:
  - min: 0
    apex_config:
      labels:
        show: true
        formatter: |
          EVAL:function (value) {
            return value.toFixed(3);  
          }
apex_config:
  tooltip:
    "y":
      formatter: |
        EVAL:function (value) {
          return value.toFixed(3) + " kr"; 
        }
  plotOptions:
    bar:
      columnWidth: 60%
      colors:
        ranges:
          - from: 0
            to: 0.6
            color: "#4caf50"
          - from: 0.6
            to: 1.1
            color: "#ff9800"
          - from: 1.1
            to: 100
            color: "#f44336"

What This Gives You

✔ 35 future hours in a single chart
✔ Clean hourly resolution
✔ Color‑coded prices (cheap / medium / expensive)
✔ Correct timestamps on the X‑axis
✔ No spinners, no unknown, no hacks

And yes — it updates instantly when the AMS reader updates.


Why This Beats 15‑Minute Nordpool Charts

Using AMS hourly prices simplifies everything:

  • Dashboards are easier to read
  • Automations become trivial (“cheapest hour”, not “cheapest 15‑minute block”)
  • Visuals match how electricity is billed and understood

Nordpool data is great. However, if your AMS reader already provides hourly prices, you should absolutely take advantage of it.


Final Thoughts

This setup looks simple on the dashboard. However, under the hood, it solves several tricky Home Assistant limitations. These limitations are related to future data.

If you’re running an AMS reader and want a rock‑solid power price forecast chart, use this approach. It has proven to be stable. It is also flexible.

Happy hacking — and may your kilowatt‑hours always be cheap ⚡😄


Some of the links in this article are "affiliate links", a link with a special tracking code. This means if you click on an affiliate link and purchase the item, we will receive an affiliate commission. The price of the item is the same whether it is an affiliate link or not. Regardless, we only recommend products or services we believe will add value to our readers. By using the affiliate links, you are helping support our Website, and we genuinely appreciate your support.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.