Building a Home Assistant Integration for Elmeasure smart meters

Reverse engineering a private Android API so I could finally see my prepaid electricity data inside Home Assistant.

Home Assistant Reverse Engineering Android API Analysis Open Source
⭐ View on GitHub

The Why?

After moving into a new apartment, I found that all my electricity information was only available through the ElNetPPS v3 app (and MyGate). Since the apartments in my community use Elmeasure smart meters, I could check my prepaid balance, live power consumption, and daily energy usage, but only by opening those apps.

Elmeasure Smart Meter

I already use Home Assistant as the central dashboard for my smart home, bringing together everything from lights and sensors to cameras and automations. Having to open a separate app just to check my electricity usage felt out of place, so I decided to bring that data into Home Assistant alongside everything else.

What I wanted

The challenge was that Elmeasure doesn't provide a public API or an official Home Assistant integration. If I wanted the data, I'd have to understand how the Android app communicated with the backend and recreate that myself.

The Investigation Begins

This wasn't a single breakthrough. It was a series of small discoveries that gradually revealed how the Android app communicated with the backend. Every answer raised a new question, and each question led to another clue.

πŸ“¦ Digging Into the APK

I started by decompiling the Android application to inspect its Java/Kotlin code. My goal wasn't to modify the app, but to analyze its Activities, network layer, API client, authentication, and encryption routines to answer a few simple questions:

  • Where are requests sent?
  • How does authentication work?
  • Is encryption used?
  • Which endpoints exist, and what parameters are mandatory?

πŸ” Mapping the API

While browsing the decompiled code, I identified all the API calls. The application communicates with a backend server using HTTP POST requests. I mapped each endpoint to its specific purpose:

Endpoint (POST)Purpose
/api/Dashboard/loginAuthenticate user
/api/Dashboard/GetDashboardDetailsMain dashboard information
/api/Dashboard/GetLiveUpdatesLive power consumption
/api/Dashboard/GetEnergyDashboardHistorical daily energy

πŸ“‘ Watching the Network

Static code analysis only tells part of the story, so I captured live network traffic using PCAPdroid. The capture was used to verify the request URLs, HTTP headers, Content-Type, Authorization header, payload format, and server responses. This confirmed my reconstructed requests matched the app's real behavior.

Packet capture of the Android app using PCAPdroid

πŸ” Recreating Authentication

The login request wasn't transmitted as plain JSON. The application builds a JSON payload, encrypts it using AES, encodes the encrypted bytes, and only then sends it to the server.

Once I understood this, I reproduced it in a standalone Python client. I discovered the login response returns significantly more than just an AuthToken it also returns FlatId, UserID, UserName, FlatName, and more. The token is then used for every future request.

Home Assistant Elmeasure Dashboard showing live power and balance

Making Sense of the Data

Once the Python prototype was authenticating and polling the API, I had to figure out how to parse the responses in a way that made sense for Home Assistant.

Determining the Power Source (Grid vs. DG)

One interesting observation from the GetLiveUpdates endpoint is that the API only exposes a single live power value (PresentLoad), along with a string indicating the current Supply source.

To make dashboarding easier in Home Assistant, the integration uses this logic to split the data into dedicated sensors:

Parsing Historical Energy

While analyzing the network traffic, I noticed the official app makes calls to the GetEnergyDashboard endpoint differently depending on the user's view. It natively changes the Input parameter to fetch either weekly or monthly historical data:

energy_data = call_api(
    token,
    "GetEnergyDashboard",
    {
        "EndDate": "",
        "MeterID": meter_id,
        "Input": 30,  # App passes 7 for weekly data, 30 for monthly data
        "StartDate": ""
    }
)

The response provides an array of daily totals, each containing EB (Grid), DG, and Solar values. While fetching a full month of history is great for standalone scripts, the Home Assistant integration specifically targets and extracts the latest day's values to feed Home Assistant's native "Today Energy Used" statistics.

Integration Architecture

With the API understood and the data logic mapped, converting the prototype into a proper Home Assistant integration became the final step. I implemented Config Flows for easy setup and an ElmeasureCoordinator to manage periodic polling across the endpoints.

                    Home Assistant
                           β”‚
                      Config Flow
                           β”‚
                        Username
                        Password
                        API URL
                           β”‚
                           β–Ό
                    Login Request
                           β”‚
                    Authentication
                           β”‚
                           β–Ό
                  ElmeasureCoordinator
                           β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                  β”‚                  β”‚
        β–Ό                  β–Ό                  β–Ό
GetDashboardDetails  GetLiveUpdates  GetEnergyDashboard
        β”‚                  β”‚                  β”‚
        β–Ό                  β–Ό                  β–Ό
   Dashboard          Live Sensors      Daily Sensors
                           β”‚
                           β–Ό
                 Home Assistant Entities

The Final Result

The integration now exposes everything I originally wanted natively inside Home Assistant, without requiring the official Android application.

Home Assistant Entities created from Elmeasure Integration

Supported Features

Learnings

Open Source

I decided to open source the integration so anyone using Elmeasure can bring the same data into Home Assistant without repeating the reverse engineering work.

View the Project on GitHub