Powerpal smart energy monitor

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]

@drew-t excellent work :+1: are you trying to do the Powerpal cloud upload ? I think the data representation in the Powerpal app is pretty good, just a design downfall that the unit relies on a flaky intermittent Bluetooth connection, I get missing chunks of data doing it the official way. I’ve just tried substituting in the “https://readings.powerpal.net/api/v1/meter_reading/”; into the powerpal_ble.h and cleaning / re-compile, will see if that helps.

@compacthack I’ve managed to get Powerpal integrated with Home Assistant via ESP 32 :slight_smile: I used NRF Connect to find the BLE MAC address. Had to use my Android tablet for that as the NRF Connect iOS version was obfuscating the MAC address for some reason. How did you go with the cloud integration?

Hey guys, as I mentioned on Github, I’m not using @WeekendWarrior1’s code for cloud upload as I couldn’t get it to work. What I’m doing instead is uploading the values using a POST request through HA native REST command platform.

EDIT: Use the code from this post instead

Let’s try this again. Here’s what I’ve got in my configuration.yaml. You’ll need to replace device-id and api-key for your own device:

rest_command:
  my_request:
    url: https://readings.powerpal.net/api/v1/meter_reading/<device-id>
    method: POST
    headers:
      authorization: "<you-powerpal-api-key>"
      accept: ""
    payload: >-
       [ {"cost":{{ states.sensor.powerpal_cost_json.state }},"is_peak": false, "pulses":{{ states.sensor.powerpal_pulses_json.state }}, "timestamp": {{ (int(states.sensor.powerpal_timestamp_json.state)//60) * 60 }}, "watt_hours": {{ states.sensor.powerpal_watt_hours_json.state}} } ]
    content_type: 'application/json'
    verify_ssl: true

Next, I’m using an automation to trigger upload everytime the value of timestamp sensor changes which is every 60s.
From automations.yaml:

- alias: Powerpal Cloud Upload
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.powerpal_timestamp_json
  condition: []
  action:
  - service: rest_command.my_request
    data: {}
  mode: single

It’s been working flawlessly for me for the past month or so. Here’s a screenshot of my Powerpal app where you can see the data being uploaded while Bluetooth is disabled:

Happy to help with further questions!

1 Like