How to build your own DIY Energy Monitor

Rob Hammond
4 min readOct 14, 2022

--

Two smart meters — one Chameleon IHD as provided by my electricity supplier, and a truly smart meter on the right
My new DIY smart meter (right) vs the closed system, poor quality and out-of-date smart meter on the left

I wrote previously how I created a replacement for my rubbish Smart Meter with a Raspberry Pi.

This post explains how you can do the same, using the open source homeAnalytics software.

HomeAnalytics is like Google Analytics for your home; it’s a lightweight app that runs on your local network using a SQLite database for data storage. You can read more about its capabilities for supporting a DIY Energy Monitor here.

Step 1: Prepare your Raspberry Pi

I had a Raspberry Pi 3 lying around waiting for a purpose for years, so this was the equipment I went with — older models may also work but as yet are untested.

I used the Raspberry Pi Imager to do a clean install of Pi OS Bullseye (64-bit); the homeAnalytics database driver requires a 64-bit OS so that part is important.

Step 2: Purchase a small display

WaveShare touchscreen — cheap but decent size & quality for the price

I bought a 5" Capacitive Touch Display from Pi Hut for £40, but in theory you could buy any screen of any size. An e-ink display could also be used with some adaptation, or even any old monitor or TV you have spare.

Having a touch screen is useful as it enables you to scroll through the screen as it cycles through different information screens.

Step 3: Attach your display to your Pi

This was pretty easy with the Waveshare screen by following the instructions on their website.

Step 4: Install homeAnalytics to your Pi

Once you have your display up and running, SSH into your Pi or open the Terminal app and install the Github Client:

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh

Clone this project into a suitable directory, ie /var/www/homeanalytics

mkdir /var/www
cd /var/www
git clone https://github.com/robhammond/home-analytics.git
cd home-analytics

Install Node.js

The web UI is powered by Express.js, so you will need to install Node and the dependencies:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
cd /var/www/home-analytics/app/web
npm i

Initialize SQLite DB

Next, initialize the Prisma.io database client and build the database tables by running:

npx prisma generate
npx prisma migrate deploy
npx prisma db seed

Install Python dependencies

cd /var/www/home-analytics/app/tasks
pip3 install -r ./requirements.txt

Set the database path as an environment variable:

echo "export HA_DB_URL=/var/www/home-analytics/db/prod.db" >> ~/.profile

Then restart your shell session so the env variable is loaded for the next steps.

Load crontab

Set up the cron tasks — adapt the example-crontab.txt to your project paths and copy the content into the crontab editor (crontab -e)

Step 5: Start the web UI

Run the Web UI in the background using PM2

sudo npm install -g pm2
pm2 start "cd /var/www/home-analytics/app/web/; npm run dev"
pm2 save

You should now be able to access your installation on your local network at the Pi’s IP address, for example http://10.0.0.5:3000 (run hostname -I on the Pi terminal to find it).

Add your details to the web UI

Navigate to your Pi server and go through the setup options, entering:

  • Your electricity supplier details, including standing charges and on/off-peak rates
  • Your n3rgy connection details — this is a bit of a pain but instructions can be found here

Step 6: Start your always-on display

The always-on display makes use of Chrome’s ‘kiosk mode’.

To set this up, log into your Pi directly or via VNC (the Chrome command will fail via SSH), and launch the Terminal app.

First of all, disable screensaver and power-saving settings:

sudo nano /etc/xdg/lxsession/LXDE/autostart

Comment out the line:

@xscreensaver -no-splash

And add these lines:

@xset s off
@xset -dpms
@xset s noblank

You may need to disable screen blanking in raspi-config too:

sudo raspi-config

Navigate to Display Options, find Screen Blanking and turn it off. You will need to restart your Pi for changes to take effect.

Finally run the following command from a VNC terminal window to launch a full screen instance of Chrome:

chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:3000/pi &

You can then exit the VNC session.

Conclusion

🥳 You should be good to go with your new smarter, smart energy monitor.

As it is only recently released open source software, there may be a few issues you encounter along the way — please raise an issue or comment below if you do!

--

--

Rob Hammond

PS Director, EMEA at BrightEdge. Technologist, SEO, renewable energy enthusiast