Powerpal smart energy monitor

Hi guys
First of all, thanks to WeekendWarrior1 for writing “GitHub - WeekendWarrior1/powerpal_ble: Collection of code, tools and documentation for data retrieval over BLE from your Powerpal

I am using esp32. the problem is, it runs and shows

'BLE Advertised Device found: Name: Powerpal 0000f176, Address: ca:cf:f1:3d:77:75, serviceUUID: 59daabcd-12f4-25a6-7d4f-55961dce4205

Attempting to connect to device…

Found our device

Forming a connection to ca:cf:f1:3d:77:75

  • Created client

onConnect

MTU:23

  • Connected to server

Attempting to get battery service…

onSecurityRequest

onAuthenticationComplete

auth_cmpl.success`

After this line, it stops and nothing happens.
The only thing that I need is real-time power consumption.

Thank you for your help.

I am new to Home Assistant and this is my first plea for help …

I thought I would start by getting Powerpal to display in Home Assistant using @mindmelting 's code. To obtain the elusive API, I followed @Dean2706 's instructions, but when I try to configure the patched Powerpal .apk on my Samsung Galaxy S9, I get the error message:

“TypeError: Cannot read property ‘map’ of undefined”

I have no idea what that means, but I assume it is because that .apk is version 1.16.1, but the current version is 1.24.1?

I am preared to try to remove the security using “apk-mitm”, but I don’t know how to obtain the latest .apk package in order to modify it.

Any advice would be greatly appreciated … :grinning:

OK, I should have done this before I posted my “plea for help” … :face_with_raised_eyebrow:

A simple Google search pointed me to APKPure and I was able to download the latest Powerpal.apk from Google Play …

Now to see if I can remove the security restrictions … and finally discover the API.

Just wondering if this got committed? I’m finding the same issue, counter resets to 0 when ESP32 reboots…

Very interesting work :slight_smile:

I’m keen to look more into getting a real time readout…I’ve done some testing with powerpal pro and it appears to be adaptive to whether the power is changing or not. The update rate is extremely fast under changing loads, e.g. I was turning a kettle on and off and seeing the update interval range from ~1-2 seconds with the powerpal app open in foreground on phone (with BLE turned off on phone so it can’t have been directly connected to powerpal unit). Can also see on wireshark the cloud report rate from the pro following this adaptive timing.
With constant load it dropped back to around 30+sec.

This leaves me with a few possible pathways to pursue over the christmas break:

  1. attempt to intercept the powerpal pro cloud reports so they could be consumed directly/locally

  2. figure out how the phone app is able to get such rapid updates via cloud and replicate in the cloud polling home assistant integration, which is what I currently use but currently limited to updates once per 60 seconds (less ideal, prefer local)

  3. The most optimal option: switch to esp32 with the code here and attempt to replicate on BLE whatever the powerpal pro is doing to achieve adaptive real time updates

If anyone has any further info I’m keen to hear it - thanks :slight_smile:

Update:
First, thanks for the work on this - really awesome stuff

The external component ble_client shouldn’t be needed any more, but I haven’t looked deeply enough to be sure. I’m running just powerpal_ble external, with some small changes to be compatible with current beta branch of esphome ble_client:
find and replace in powerpal_ble.cpp:
a) ‘conn_id’ with ‘get_conn_id()’
b) ‘gattc_if’ with ‘get_gattc_if()’
c) ‘remote_bda’ with ‘get_remote_bda()’

With that it’s running happily for the past half hour for me. It had no issue just connecting and working first run :slight_smile:

Will play around more tomorrow or maybe next weekend

1 Like

hello, first of all, thanks for sharing this work. I’m really keen to use this.
However I am having trouble using…I have tried through home assistant and esphome standalone (docker) and same error (attached) - looks like there is a definition conflict during compilation.
This is happening even when using the stock sample powerpal_ble.yaml
Any suggestions? I can work with python but C++ is beyond me :frowning_face:

thanks

1 Like

I have been experiencing the same issue as tlee17, above, on a Mac running HASS in VirtualBox, and on a PC with ESPHome standalone. Same error when compiling to the M5Stack Atomlite, and an M5StackCore. Hope someone can help with this!

When you’re replacing gattc_if with get_gattc_if(), do not change it in this line:

void Powerpal::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,

                                   esp_ble_gattc_cb_param_t *param) {

Hopefully that solves the compilation errors.

I’m also seeing this error and am using a M5Stack Atom Lite as well.
Perhaps @WeekendWarrior1 might have some thoughts?

Use the fixes described in this and this comment. I’m running M5 Atom Lite without any issues.

I’m now seeing the same errors as well, even though I haven’t changed anything for a few weeks (other than updates). @muneeb1990 just to clarify your point, which file are you proposing needs to be edited? Thanks

Check this PR. I have just configured it 2 days ago with the fix. Note that I have to change more source files for it to compile. ESPHome 2022.11.0 compatibility by ashmckenzie · Pull Request #3 · WeekendWarrior1/esphome · GitHub

Hi Guys, just checking if there was any updates on the fail to compile issue since 2022.11.0 ? Bad timing for me I got my Powerpal a couple of weeks ago with plans to integrate into HA, I’m not much of a coder but I’ve tried using @starryalley version of powerpal_ble & ble_client and compiling as a local source and it still fails when it gets to [.pioenvs/powerpal/src/esphome/components/ble_client/automation.cpp.o] and [.pioenvs/powerpal/src/esphome/components/ble_client/ble_client.cpp.o]

There is a good chance that I’m not doing something right !, but it comes back with these.

virtual bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
^
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
^
virtual bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
^

Hey folks, sorry been crazy busy these past few weeks. I finally got around to creating a fork with my changes. More details here. In addition to fixing the compile errors, I’ve also added sensors for timestamp, cost, pulses and watt_hours to use HA REST commands to upload to cloud so you can see your usage in Powerpal app without connecting your phone with the device. This is completely optional though.

This setup is tested and working on ESPHome 2022.11.3.

Bingo @muneeb1990 , You’re a star. compiled with your code, working well. Thanks for your efforts. :+1: Cheers

1 Like

Does anyone know if weekendwarrior’s integration is still working for Powerpal energy monitoring? I’ve tried a number of fixes including the one muneeb1990 posted but am still getting the same error as compathack.

Hi @drew-t I got mine working 7 days back with @muneeb1990 code from above here, I copied his “powerpal_ble” & “http_request” to my pi4 microSD and pointed the .yaml at it to use as a local source to compile but only for components: [powerpal_ble, http_request] not the ble_client, and that worked well, the only thing is I don’t think its pushing to the Powerpal cloud, even after adding my device_id and apikey, but I might have done something wrong my end, hope this helps.

In saying that, I was looking at @muneeb1990 's powerpal_ble.h and I noticed it is referencing an internal ip address as possibly part of the cloud uploading, but I’m only a shade tree coder, so I might be of the mark totally. The powerpal_ble.h code below lines 145 - 150:-

uint8_t stored_measurements_count_{0};
std::vector stored_measurements_;
std::string powerpal_api_root_ = “http://192.168.1.44:3000/”;
std::string powerpal_device_id_; // = “00002bc3”;
std::string powerpal_apikey_; // = “4a89e298-b17b-43e7-a0c1-fcd1412e98ef”;
double energy_cost_;

Where @WeekendWarrior1 's original code refereed to:-

std::string powerpal_api_root_ = “https://readings.powerpal.net/api/v1/meter_reading/”;

1 Like

Thanks @compacthack! I’ve managed to get it to compile by excluding ble_client in the YAML code.

external_components:
  - source:
      type: local
      path: my_components
    components: [powerpal_ble, http_request]