Home › Guides › Grafana Home Assistant dashboard

Grafana Home Assistant Dashboard: Copy-Paste Setup

This is the companion guide to my video on building a Grafana Home Assistant dashboard. It shows every temperature in the house, the humidity and the power use, and it keeps a whole year of it. Home Assistant, Prometheus and Grafana 13 all run in Docker. Copy each block in order. You start from an empty Grafana and end with a dashboard called Home, with two tabs.

Why Grafana, if Home Assistant already has graphs?

By default, Home Assistant keeps detailed history for only ten days, and its charts show a few sensors at a time. Grafana reads a real time series database. You keep months of data, put any sensors side by side, and zoom to any time range.

What you are building

Home Assistant/api/prometheus→ every 30 s → Prometheusstores 1 year→ Grafana 13port 3000

Home Assistant publishes all its sensors on a Prometheus endpoint. Prometheus collects them every thirty seconds and stores them. Grafana reads Prometheus and draws the dashboard.

What you need

Everything lives in one folder. When you are done, it looks like this (the folder name is up to you, the video uses homelab):

homelab/
├── compose.yaml
├── prometheus.yml
└── ha/
    └── configuration.yaml

Step 1: the compose file

Three services: Home Assistant, Prometheus with one year of retention, and Grafana 13 on port 3000. Prometheus has no port to the outside, because only Grafana needs it.

mkdir -p ~/homelab/ha && cd ~/homelab
nano compose.yaml

Paste this, then save with Ctrl+O and Enter, and exit with Ctrl+X:

services:
  homeassistant:
    image: ghcr.io/home-assistant/home-assistant:stable
    volumes:
      - ./ha:/config
    environment:
      - TZ=Etc/UTC
    ports:
      - "8123:8123"
    restart: unless-stopped

  prometheus:
    image: prom/prometheus:v3.7.3
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus-data:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.retention.time=1y
    restart: unless-stopped

  grafana:
    image: grafana/grafana:13.3.2
    ports:
      - "3000:3000"
    volumes:
      - grafana-data:/var/lib/grafana
    restart: unless-stopped

volumes:
  prometheus-data:
  grafana-data:

Step 2: turn on the Prometheus endpoint in Home Assistant

A single line does it: prometheus: in configuration.yaml. You don't configure anything per device. Every Home Assistant sensor with a unit shows up as a metric on its own: thermostats, smart plugs, the weather.

nano ha/configuration.yaml
default_config:

# Send every sensor to Prometheus (http://homeassistant:8123/api/prometheus)
prometheus:

Already running Home Assistant? Don't replace your file. Just add the prometheus: line to your existing configuration.yaml and restart Home Assistant.

Optional: the demo sensors from the video

The sensors in the video are demo sensors, so the numbers move on their own. If you want to follow along on a fresh Home Assistant with no devices, add this to the same file. It creates three temperatures, one humidity and one power sensor. Skip it if you have real sensors.

# Demo sensors for the video (your own Home Assistant has real ones)
template:
  - trigger:
      - trigger: time_pattern
        seconds: "/30"
    sensor:
      - name: "Living room temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement
        state: "{{ (21.5 + 1.2 * sin(as_timestamp(now()) / 900) + range(-2, 3) | random / 10) | round(1) }}"
      - name: "Bedroom temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement
        state: "{{ (19.0 + 0.8 * sin(as_timestamp(now()) / 700 + 1) + range(-2, 3) | random / 10) | round(1) }}"
      - name: "Outside temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement
        state: "{{ (4.0 + 3.0 * sin(as_timestamp(now()) / 1200 + 2) + range(-3, 4) | random / 10) | round(1) }}"
      - name: "Living room humidity"
        unit_of_measurement: "%"
        device_class: humidity
        state_class: measurement
        state: "{{ (45 + 6 * sin(as_timestamp(now()) / 1000 + 0.5)) | round(0) }}"
      - name: "House power"
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        state: "{{ (350 + 250 * (sin(as_timestamp(now()) / 300) | abs) + range(0, 120) | random) | round(0) }}"

Step 3: the Prometheus scrape job, then start everything

A scrape job tells Prometheus what to read and how often. This one reads Home Assistant at /api/prometheus every 30 seconds. The target is homeassistant:8123: inside Docker, containers reach each other by service name. Leave the token placeholder for now. You make the token in step 4.

nano prometheus.yml
global:
  scrape_interval: 30s

scrape_configs:
  - job_name: homeassistant
    metrics_path: /api/prometheus
    authorization:
      credentials: "PASTE-YOUR-TOKEN-HERE"
    static_configs:
      - targets: ["homeassistant:8123"]

Start the three containers:

docker compose up -d

Tip: first start of Home Assistant. On a brand new Home Assistant, open http://YOUR-SERVER-IP:8123 and click through the onboarding to create your user. This happens before the video starts, so it isn't shown there. If you edit configuration.yaml later, restart Home Assistant with docker compose restart homeassistant.

Home Assistant already runs with network_mode: host? Then Prometheus can't reach it by service name. Use your server's IP instead of homeassistant:8123, for example "192.168.1.10:8123".

Step 4: a long-lived access token

Prometheus needs a token to read that endpoint. In Home Assistant:

  1. Open your profile (your name at the bottom of the sidebar).
  2. Open the Security tab.
  3. At the bottom, under Long-lived access tokens, click Create token.
  4. Name it prometheus and click Create token.
  5. Copy the token now. Home Assistant shows it only once.

Tip: treat the token like a password. Anyone who has it can use your Home Assistant. Don't paste it into screenshots, forum posts or a public Git repository.

Step 5: put the token in prometheus.yml and restart Prometheus

nano prometheus.yml

Replace PASTE-YOUR-TOKEN-HERE with your token. Keep the quotes. The line becomes:

      credentials: "YOUR-LONG-LIVED-TOKEN"

Save with Ctrl+O and Enter, exit with Ctrl+X, and restart Prometheus so it reads the new config:

docker compose restart prometheus

Step 6: add the Prometheus data source in Grafana

Open Grafana at http://YOUR-SERVER-IP:3000. The first login is admin / admin, and then Grafana asks you to set a new password. Pick a real one.

A data source tells Grafana where your data lives. Add Prometheus:

  1. Open Connections → Data sources and click Add data source.
  2. Pick Prometheus.
  3. Set the connection URL to http://prometheus:9090. Same idea as before: the service name from the compose file.
  4. Scroll down and click Save & test.
http://prometheus:9090

You should see this. It means Grafana can read your data:

Successfully queried the Prometheus API.

Step 7: find your sensors in Explore

Before building anything, look at the data. On the data source page, click Explore view. Open the metric drop-down and type homeassistant_sensor. Every kind of sensor is its own metric:

Sensor kindMetric name
Temperature in Celsiushomeassistant_sensor_temperature_celsius
Humidity in percenthomeassistant_sensor_humidity_percent
Power in wattshomeassistant_sensor_power_w

Pick the temperature metric and click Run query. Each room is one line. Its labels tell you which sensor it is: entity, and friendly_name, the name you see in Home Assistant.

Filter with PromQL

Switch the query editor from Builder to Code. After the metric name, add curly braces with a label filter, then run it again. Only that sensor is left:

homeassistant_sensor_temperature_celsius{friendly_name="Outside temperature"}

That's PromQL, Prometheus's query language: a metric name, then label filters in curly braces. Every panel in the dashboard is a query like this. Replace Outside temperature with one of your own sensor names.

Step 8: the temperature panel

Open Dashboards → New → New dashboard. Grafana 13 starts with an auto grid: panels line up and resize by themselves. Click Panel, then Configure visualization.

Switch the query to Code, type the temperature metric and click Run queries. You get one line per room. The default visualization, Time series, is the right one here.

homeassistant_sensor_temperature_celsius

The legend shows every label, which is too long. Under the query, open Options, set Legend to Custom and type the friendly name between double curly braces:

{{friendly_name}}

Then set these in the options pane on the right:

SectionOptionValue
Panel optionsTitleTemperature
Standard optionsUnitCelsius (°C)
Graph stylesLine interpolationSmooth (suits temperatures)
LegendModeTable
LegendValuesMin, Max, Mean

The legend table now tells you how cold and how warm each room got in the selected time range. Click Back to return to the dashboard.

Step 9: a humidity gauge with thresholds

Click Add panel, then Configure visualization. Switch to Code and use the humidity metric:

homeassistant_sensor_humidity_percent
OptionValue
VisualizationGauge
TitleHumidity
UnitPercent (0-100)
ThresholdsBase: green. Change the red step from 80 to 60.

Thresholds color the gauge. Green is the base, and red starts at 80 by default. Change it to 60: above sixty percent humidity, mold likes your walls, so the gauge turns red. Click Back.

Step 10: Grafana 13 tabs

Tabs keep a big dashboard tidy.

  1. Click Group panels → Group into tab. Both panels move into a new tab.
  2. Name the tab Climate. Every tab has its own layout settings, like the auto grid and its Max columns.
  3. Click New tab and name it Energy.
  4. Inside the Energy tab, click Add panel.

Each tab only loads its own panels, so even a huge dashboard stays fast.

Step 11: a stat panel for power

A Stat panel shows one big number, the latest value, with the trend drawn behind it. Click Configure visualization, switch to Code and use the power metric:

homeassistant_sensor_power_w
OptionValue
VisualizationStat
TitlePower
UnitWatt (W)
ThresholdsChange the red step from 80 to 2000.

Why change the threshold? The default red step is 80. For power in watts, that would make the number red almost all the time. The finished dashboard in the video uses 2000 W. Set it to whatever counts as "a lot" in your home.

Click Back.

Step 12: time range and save

  1. Pick a time range at the top, like Last 3 hours. Once your data has built up, try a whole month.
  2. Click Save, name the dashboard Home, and save it.
  3. Click Exit edit.

Drag across a graph to zoom into that moment, and the whole dashboard follows. To zoom back out, use the zoom out button next to the time range.

The finished dashboard at a glance

TabPanelQuerySettings
ClimateTemperature (Time series) homeassistant_sensor_temperature_celsius Legend {{friendly_name}}, unit Celsius, smooth lines, legend table with Min, Max, Mean
ClimateHumidity (Gauge) homeassistant_sensor_humidity_percent Unit percent, green base, red from 60
EnergyPower (Stat) homeassistant_sensor_power_w Unit watt, green base, red from 2000

If the panels say No data

Check what Prometheus says about the scrape:

docker compose logs prometheus
What you seeWhy
A 401 error in the Prometheus log The token is wrong. Make a new one (step 4), paste it again (step 5) and restart Prometheus.
Tip: connection errors to homeassistant:8123 Home Assistant runs with network_mode: host or in another compose project. Use the server's IP in targets.
Tip: Save & test fails in Grafana The data source URL is wrong. It must be http://prometheus:9090, not localhost: inside the Grafana container, localhost is Grafana itself.
Tip: a sensor is missing from the metric list Only sensors with a unit show up as these metrics. Check that the sensor has a unit in Home Assistant.

Watch the video

The whole build on camera, from an empty Grafana to the finished dashboard with tabs, in about seven minutes:

Related

Want dashboards like this for your company?

A home dashboard is three panels. A company has servers, applications and buildings, and needs alerts that fire on the right things. That's what I do: monitoring and observability, through KorFlux. I'm a Grafana Champion. Tell me what you run and I'll tell you how I'd set it up.