Powerpal smart energy monitor

I was looking for projects on capturing power consumptions and I was about to start on Klaas Schoute’s Home Assistant Glow project, I stumbled upon this thread and lurked for couple of weeks. I decided I’ll hop onto this but I have no experience on esphome (I am a tasmota user with around 6 flashed devices). It took me 5 days to successfully (I think) flash the first esphome with WeekendWarrior1’s external component (wasted time on serial port driver problem and no git on my machines etc). I called mine “powerpalmate”. I could see it in Home Assistant integration tab now and I could see it as enabled. However, I could not see those 3 entities in “Developer Tools/States” - “Powerpal Power”, “Powerpal Total Energy” and “Powerpal Battery”. Am I missing something? How do I know I indeed sucessfully flashed and configured properly in HA? Hope some one could give me some ideas. The following is my powerpalmate.yaml:

esphome:
  name: powerpalmate

esp32:
  board: esp32dev
  framework:
    type: arduino

external_components:
  - source: github://WeekendWarrior1/esphome@powerpal_ble
    components: [ ble_client, powerpal_ble ]

api:

ota:

wifi:
  ssid: "my_wireless_ssid"
  password: "my_password"

  ap:
    ssid: "powerpalmate Fallback Hotspot"
    password: "my_fallback_secret"

  manual_ip:
    static_ip: my_powerpalmate_addr
    gateway: my_gateway
    subnet: my_subnet_mask

esp32_ble_tracker:

ble_client:
  - mac_address: got_it_from_
    id: powerpal

sensor:
  - platform: powerpal_ble
    ble_client_id: powerpal
    power:
      name: "Powerpal Power"
    energy:
      name: "Powerpal Total Energy"
    battery_level:
      name: "Powerpal Battery"
    pairing_code: my_pairing_code
    notification_interval: 1
    pulses_per_kwh: 800

Hi possum,

Your yaml looks good to me.
Perhaps you could add the logger component to your esphome device yaml: Logger Component — ESPHome

logger:
  level: DEBUG

And then however you ran esphome to flash your device (esphome upload powerpalmate.yaml?), you can run it with the logs command instead (esphome logs powerpalmate.yaml), and hopefully you may get greater insight into any issues there are between your esp32 and HA

Good point!
I have figured/planned out the features I need to develop to get the esphome powerpal uploading data to the cloud in an easy to configure manner, and I should have it complete in the coming days.

I have put together a little script that should be able to retrieve your Powerpal device ID and Authorization API key from the Powerpal directly, without having to mess around with the MITM proxy stuff or asking permission from Powerpal directly:

I would really appreciate it if some people could help test it out for me!
Requirements:

  1. Needs to be run on a computer with bluetooth
  2. Should work on Linux/Windows/Mac, but I have only tested it on Linux
  3. Python3.2 or newer installed

Running it:
Clone the repo: git clone https://github.com/WeekendWarrior1/powerpal_ble.git
cd powerpal_ble/auth_extraction
pip install bleak
python3 retrieve_api_key.py

2 Likes

Just managed to set up a Powerpal at my new place and came across this thread. Tried out your PY script to grab the authentication key on my VM running HassOS but it threw this error:

Connected: True
Traceback (most recent call last):
File "/config/powerpalauthkey.py", line 68, in <module>
asyncio. run(main((sys.argv[1] if len(sys.argv) >= 2 else None), (sys.argv[2] if len(
sys argv) 3 else None
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in
run
return loop. run_unt il_complete(main)
File "/usr/lib/python3 .9/asyncio/base-events.py", line 642, in run-until- complete
return future.result ()
File "/config/powerpalauthkey.py", line 31, in main
paired
await client pair(2)
File "/usr/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 479
in pair
assert-reply(reply)
File "/usr/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 23, i
n assert-reply
raise BleakDBusError (reply.error-name, reply.body)
bleak.exc . BleakDBusError: [org.bluez .Error . AuthenticationFailed] Authentication Failed

Not sure what any of it means. I am currently running the passive BLE integration to pull data from my Xiaomi temp/humidity sensors and sensor lights so this might be interfering? Not sure?

Has anyone managed to get direct integration via BLE and a bluetooth dongle working? Not really interested in purchasing a ESP32 to grab the data and cloud-based integration… well prefer not to have to send the data only to pull it back down again via the cloud.

Hi JJW.AU, thanks so much for trying the script for me, and thanks for the error logs. I wonder if this is something I need to address on headless systems, since for me on Gnome I think I had an OS pairing prompt appear. Something for me to investigate. I don’t believe your passive BLE integration was interfering.

In theory, yes, a custom HASS component could likely be put together to connect to a Powerpal now that I have reverse engineered the BLE protocol, but here a few of my thoughts on the matter:

  • Python (and other language) BLE libraries seem to be a bit mediocre, through what seems to be no fault of their own. (It seems building software libraries targetting windows, linux and Mac bluetooth/ble stacks is not easy)
  • It seems it is not recommended to build HASS components that connect to bluetooth devices (the Powerpal doesn’t send it’s measurement data in it’s advertisement packets like the LYWSD03MMC do)
  • To paint a clearer picture of possible issues, the script you ran from your VM is probably a good candidate of a prototype HASS component (uses python BLE to connect + authenticate, write and read values) and it looks like there may be issues around Bluez/Bleak auth.
  • An esp32 with the ESPHome components I have built ‘just works’ for < $10 AU, seems hard to beat
  • At the end of the day (and I hope this doesn’t sound rude), I’m not really interested in debugging people’s OS bluetooth device and driver issues

So whilst I also agree that it would be neater from a data perspective to pull it in directly through HASS instead of using another (albeit cheap and low power) device to retrieve it and pass it on, from a software perspective it seems to be a headache.

Cool makes sense. Given that the ESP32 is so cheap I should probably buy some to play with. The integration with Home Assistant seems easy enough. But using PowerPal seems redundant as you could probably just wire up a LDR to the ESP and script it to count pulses directly?

IMO diy ESP pulse_counter energy meter solutions all have one major failing, powering the ESP device. I’m not a sparky so it’s not legal to do my own 230VAC → 5VDC inside the meter box, and I don’t have a mains socket anywhere near my meter box to place a USB charger.

Powerpal/Emerald conveniently have battery lives of >5 years and are free from the VIC government :slight_smile:

1 Like

True. Didn’t think of that. Not sure how power hungry the ESP32 is but I wonder if it would last a while if run off 3AA batteries or maybe 4 NiMH ? Maybe a small solar panel to top up the batteries too

Unfortunately, ESP’s are nearly always terrible on battery, they just suck so much juice compared to battery-life focus designed MCUs. You can conserve battery by deep sleeping them, but since you need to be counting pulses I don’t think you will be able to sleep it low enough (you could use the esp32 ULP to count the pulses but that’s quite complicated, I think that requires writing some code in assembly?)

I have added powerpal cloud upload functionality to the ESPHome component!
It retrieves your powerpal apikey from the powerpal, and stores 15 measurements before uploading them all at once.

logger:
  level: VERBOSE

# required even if you're not using the powerpal_cloud_uploader
http_request:
  id: powerpal_cloud_uploader

esp32_ble_tracker:

ble_client:
  - mac_address: DF:5C:55:01:02:03
    id: powerpal

sensor:
  - platform: powerpal_ble
    ble_client_id: powerpal
    power:
      name: "Powerpal Power"
    energy:
      name: "Powerpal Total Energy"
    battery_level:
      name: "Powerpal Battery"
    pairing_code: 123123
    notification_interval: 1
    pulses_per_kwh: 1000
    http_request_id: powerpal_cloud_uploader
    cost_per_kwh: 0.1872 #dollars per kWh
#    powerpal_device_id: 0000abcd #optional, component will retrieve from your Powerpal if not set
#    powerpal_apikey: 4a89e298-b17b-43e7-a0c1-fcd1412e98ef #optional, component will retrieve from your Powerpal if not set

Currently it doesn’t support on_peak being toggled, (and is set to false), so perhaps do not use this if you use the peak/not peak functionality of the app.
Best to keep logging on in case anything doesn’t work, thanks.

Thanks @WeekendWarrior1 for the emerald integration. I now have it working and home assistant showing the data.

Have you made any progress on the daily total energy ntp idea? Cheers!

How to do this? I have downloaded the csv but can you tell mw how do I import this file to influxDB and show it in Grafana?

I’m struggling to find my Powerpal’s mac address. It’s not showing up in either esp32_ble_tracker or using the nRF Connect app on my iPhone. In both cases, it is picking up a device called “ElAdv 2107015912”, but I assume that’s a neighbour’s Emerald Advisor rather than my Powerpal (mine does say Powerpal on the bottom). My iPhone and iPad can connect to it, and I have killed both the apps just in case. Does the Powerpal mac always start with “DF:5C:55”? I have none that match that, and I’m standing right beside it. Any ideas?

Hi Michael,

Could you take a quick look on the sticker on the base of your powerpal?
I think the MAC address is documented there.

After a bit of a delay, the Daily Energy Sensor functionality is now complete for both the Emerald and the Powerpal.

You can use it by adding a time component (not 100% required as the components will fall back to the timestamps supplied to them on measurement updates from the devices, but highly recommended because of things like daylight savings), and a daily_energy sensor to your yaml:

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: emerald_ble/powerpal_ble
    ...
    daily_energy:
      name: "Emerald/Powerpal Daily Energy"
    ...
    time_id: homeassistant_time

Haven’t been able to test the Powerpal component very well, so please let me know of any errors or if it fails to reset.

1 Like

Mine only has a sticker with model (PPL-002), manufacturer (PowerPal), serial number and patent number.

Hi Michael,

My only advice then on troubleshooting steps is to triple check that ALL smart devices (eg. including a partner’s device that has also once been configured to use the powerpal) have their bluetooth completely disabled/turned off, and then trying again using the esp32_ble_tracker.

You’re right!!! I had killed the apps, thinking that would be enough, but turning off bluetooth on my iPhone and iPad caused it to show up (no partner :slight_smile: ). It might help others to add this to your readme.

Hi Michael, thanks for your feedback and glad you found the MAC address.
I have added a little note about disabling bluetooth in the READMEs.

1 Like