The Cost of 24/7: Tracking Home Lab Power with Shelly

catfight73911 pts0 comments

The Hidden Cost of 24/7: Tracking Home Lab Power with Shelly | Veerendra's BlogTable of ContentsIntroduction<br>The Hunt for Data<br>Finding the Right Hardware: Shelly<br>Shelly Device Exporterveerendra2/shelly_device_exporter<br>Dashboard & Configuration

Conclusion

Introduction#<br>As you might know, I manage two home servers for various self-hosted services. I keep everything organized in a GitOps<br>way using ComposeFlux—a tool I built to handle Docker Compose stacks when I<br>got tired of manual updates. (You can read about that journey in<br>GitOps for Homeservers (Part 1)).<br>Recently, I was catching up with a colleague at the office. We were talking about self-hosting, and I mentioned that I<br>run Immich to completely replace Google Photos. He was impressed but then asked the one question<br>I couldn&rsquo;t answer: &ldquo;How much are you actually paying for the electricity to run those servers 24/7?&rdquo;<br>I brushed it off, saying &ldquo;Not much, I think,&rdquo; since one is just a Raspberry Pi 4 and the other is a headless old Lenovo<br>laptop. But that &ldquo;I think&rdquo; started bugging me. I realized I had no idea what the actual footprint of my &ldquo;cheap&rdquo; home lab<br>was.<br>The Hunt for Data#<br>My curiosity took over. Initially, I looked into software-based tools like<br>powertop. While it&rsquo;s great for tuning, it didn&rsquo;t give<br>me the accurate, live, aggregate power usage I wanted.<br>Next, I went to Amazon to find a cheap power plug with a display. My &ldquo;clever&rdquo; plan was to buy one, track the usage for a<br>few days to satisfy my curiosity, and then return it. I ordered a basic<br>Electricity Meter for Socket. I plugged my server power strip into it and<br>saw that it usually sits around 20 Watts . However, when Immich starts its<br>Facial Recognition or video transcoding jobs, that number jumps<br>to 40 Watts .<br>It was a good start, but I&rsquo;m a DevOps engineer—looking at a tiny LCD screen under my desk isn&rsquo;t enough. I wanted those<br>numbers in my Prometheus/Grafana stack.<br>Finding the Right Hardware: Shelly#<br>I needed a &ldquo;smart&rdquo; plug that didn&rsquo;t just have a pretty app, but a documented API. I was skeptical because many &ldquo;smart&rdquo;<br>devices are locked into proprietary clouds with no local access. I don&rsquo;t like workarounds or fragile hacks.<br>I asked Gemini for recommendations and discovered Shelly. Their devices are famous in the DIY<br>community for having full API support and excellent documentation. I sent the basic meter back and ordered a<br>Shelly Plug M Gen3 for about 13 Euros. Best decision ever.<br>Shelly Device Exporter#<br>While Shelly has a cloud app, I prefer keeping my data local. You can disable the cloud access entirely on these<br>devices, which is a huge plus for privacy. However, I still needed a way to get the data into Prometheus.<br>I found a few existing exporters, but they didn&rsquo;t quite fit. One was buggy, and another didn&rsquo;t include the &ldquo;cost&rdquo; logic<br>I wanted. So, I did what any developer would do: I wrote my own.<br>veerendra2/shelly_device_exporter#<br>The Shelly RPC API is fantastic. A simple curl gives you everything you need:<br>curl --digest -u admin:"REDACTED" 'http://192.168.0.10/rpc/Shelly.GetStatus' | jq .<br>"switch:0": {<br>"apower": 15.4,<br>"voltage": 237.6,<br>"freq": 50.0,<br>"current": 0.124,<br>"aenergy": {<br>"total": 10358.259,<br>...<br>},<br>"sys": {<br>"uptime": 2241869,<br>"ram_free": 105616,<br>...

I used the API docs to build out the Go structs and created an exporter that not only tracks power but also calculates<br>the financial cost in real-time.<br>Dashboard & Configuration#<br>The dashboard provides a clear breakdown of current power usage, voltage, and the accumulating cost.

The configuration is straightforward. Since Shelly devices are affordable, I can add more plugs for other appliances<br>later and manage them all through one config:<br>price_per_kwh: 0.3362<br>currency: "EUR"

devices:<br>- name: "home-servers"<br>address: "http://192.168.0.6"<br>username: "admin"<br>password: '{{ env "SHELLY_DEVICE1_PASSWORD" }}'

The price_per_kwh comes straight from my electricity contract. The exporter calculates the shelly_device_aenergy_cost_total metric, making it incredibly easy to visualize exactly how many Euros my home lab is &ldquo;eating&rdquo; each month.<br>To ensure Prometheus scrapes remain blazing fast as I add more plugs, the exporter handles multiple devices concurrently. Under the hood, it spins up Go routines—capped at a pool of 4 parallel workers—to fetch status data from all configured Shelly devices at once, rather than polling them slowly one by one.<br>Conclusion#<br>Turning a casual office question into a full monitoring project might seem like overkill, but the visibility is worth<br>it. I no longer have to guess about the &ldquo;hidden costs&rdquo; of my self-hosting hobby. With the Shelly Plug and a custom<br>exporter, I have a data-driven view of my power consumption—proving that while my home lab isn&rsquo;t free, the peace of mind<br>that comes from local data and GitOps-managed servers is...

shelly rsquo ldquo rdquo power home

Related Articles