Projects / Home data with InfluxDB and Grafana

Home data with InfluxDB and Grafana

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. Pi 5SSD256

    Boot the Pi from the SSD

    Check with lsblk.

  2. Pi 5

    Install InfluxDB

    Make an org, bucket and tokens.

  3. Pi 5

    Install Grafana

    Add InfluxDB as a source.

  4. Pi 5ESP32

    Flash the ESP32 sketch

    With your placeholders filled in.

  5. Pi 5

    Check data arriving

    In the InfluxDB explorer.

  6. Pi 5

    Build a panel

    Temperature over 24 hours.

  7. Pi 5

    Set retention

    So the disk never fills.

In short

How do you build a home data with InfluxDB and Grafana?

Store months of sensor data in a time-series database and explore it with Grafana dashboards. You need Raspberry Pi 5, SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, NVMe SSD 256 GB (M.2 2230/2242), Raspberry Pi M.2 HAT+, ESP32 DevKit V1 and BME280 Environmental Sensor. It takes 7 steps and about 240 minutes.

Level
Intermediate
Time
About 240 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
BME280 SDA and SCLESP32 GPIO21 and GPIO22I2C (address 0x76 or 0x77)
BME280 VIN and GNDESP32 3V3 and GNDPower
ESP32Your Wi-Fi, same network as the PiSends readings
Pi 5 with M.2 HAT+ and SSDEthernet and powerDatabase and dashboards

Code

A time-series database is built for numbers that arrive with a time stamp, so months of readings stay quick to search, and Grafana turns them into charts. On the Pi 5, boot from the NVMe SSD, which is much more durable than an SD card for constant writing. Install InfluxDB 2 and Grafana from their official apt repositories, and open the InfluxDB page on port 8086 to make an organisation, a bucket called home and, in the bucket's tokens, a token that can only write to it; the ESP32 uses that write-only token, so if someone found it they could not read your data. In Grafana, on port 3000, add InfluxDB as a data source with a read token and make a panel per room with a Flux query for the last 24 hours. Set the bucket's retention, for example 365 days, so the disk never fills. This build uses plain HTTP, which is acceptable on a home network you control; do not open ports 8086 or 3000 to the internet, and change the default passwords at once. Keep the tokens out of any code you share.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// ESP32 writes temperature, humidity and pressure to InfluxDB 2 every 60 seconds over HTTP.
// Libraries: Adafruit BME280 (and Adafruit Unified Sensor). Board: ESP32. Fill in the placeholders; never commit real values.
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
const char* WIFI_NAME = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* INFLUX_URL = "http://YOUR_PI_ADDRESS:8086/api/v2/write?org=YOUR_ORG&bucket=home&precision=s";
const char* INFLUX_TOKEN = "YOUR_WRITE_ONLY_TOKEN";     // make a token that can only write to the home bucket
Adafruit_BME280 bme;
void setup() {
  Serial.begin(115200);
  if (!bme.begin(0x76)) { Serial.println("BME280 not found"); while (true) delay(1000); }
  WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) delay(500);
}
void loop() {
  char line[120];
  snprintf(line, sizeof(line), "room,room=lab temp=%.2f,hum=%.1f,pres=%.1f", bme.readTemperature(), bme.readHumidity(), bme.readPressure() / 100.0);
  HTTPClient http;
  http.begin(INFLUX_URL);
  http.addHeader("Authorization", String("Token ") + INFLUX_TOKEN);
  int code = http.POST(line);                // 204 means written
  Serial.println(code);
  http.end();
  delay(60000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

200

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
ESP32 runningHTTP code 204 on each post
InfluxDB explorerShows new points every minute
Grafana panelSmooth temperature line
After a reboot of the PiData keeps flowing

If it does not work

HTTP code 401

Check the token and the organisation name.

HTTP code 404

Check the bucket name in the URL.

No panel data

Check the time range and the Flux query.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the home data with InfluxDB and Grafana?

Raspberry Pi 5, SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, NVMe SSD 256 GB (M.2 2230/2242), Raspberry Pi M.2 HAT+, ESP32 DevKit V1 and BME280 Environmental Sensor.

How long does the home data with InfluxDB and Grafana take to build?

About 240 minutes for a intermediate maker, in 7 steps.

How do I know the home data with InfluxDB and Grafana works?

ESP32 running: HTTP code 204 on each post. InfluxDB explorer: Shows new points every minute. Grafana panel: Smooth temperature line.

HTTP code 401: what should I check?

Check the token and the organisation name.

HTTP code 404: what should I check?

Check the bucket name in the URL.

No panel data: what should I check?

Check the time range and the Flux query.