Powerpal smart energy monitor

WeekendWarrior1
I have home assistant running on a laptop with bluetooth.
I have a buncg of xiomi humidity sensors connected and integrated into home assistant using
HACS - BLE monitor plugin.
https://github.com/custom-components/ble_monitor
I can connect to powerpal device on the laptop using retrieve_api_key.py script.

I was wondering if it’s possible to integrate this into BLE_Monitor or similar so it uses laptop’s bluetooth rather than an external ESP device.

Quite odd.

  1. Are you certain ALL smart devices that can connect to the Powerpal have BLE disabled?
  2. Have you tried moving closer to the Powerpal?
  3. Or possibly tried a different ESP32?
  4. What version of the Arduino ESP32 core are you using?

Are you using an up-to-date version of ESPHome?
It’s likely you’ll need the latest release.
I use docker to push my code so for me it’s:

docker run --rm -v "${PWD}":/config --net=host -it esphome/esphome:latest run powerpal_ble.yaml

But also more instructions here: Frequently Asked Questions — ESPHome

No need to do this :slight_smile:
The external components from github should be enough

Please see here for a discussion on the topic. Main difference is that the Xiaomi temp/humidity sensors send their data via advertisement packets, and don’t require a constant connection.

WeekendWarrior1 Thanks for all your help.
I’m happy that I’ve proven it’s possible to connect to powerpal using script and Arduino.

I’ll go back to trying to get it to work in ESPhome rather than Arduino and test from there.

I’ve tried a couple of different esp devices (shelly 1plus and Nodemcu32).
All known devices have bluetooth disabled. I’ll check kids phones/ laptops are turned off and try again.

Running latest HA and ESPhome (from web updates anyway). I’ll check via CLI.
I tried Arduino 2.06 as well as 1.86

I’ve checked esphome and home assistant to latest versions.

Validate yaml:

INFO Reading configuration /config/esphome/powerpal-ble.yaml...
INFO Detected timezone 'Australia/Sydney'
INFO Configuration is valid!
substitutions:
  device_name: powerpalble
  friendly_name: powerpalble
  device_ip: 192.168.1.214
esphome:
  name: powerpalble
  build_path: .esphome/build/powerpalble
  platformio_options: {}
  includes: []
  libraries: []
  name_add_mac_suffix: false
esp32:
  board: nodemcu-32s
  framework:
    version: 1.0.6
    source: ~3.10006.0
    platform_version: platformio/espressif32 @ 3.5.0
    type: arduino
  variant: ESP32
external_components:
- source:
    url: https://github.com/WeekendWarrior1/esphome.git
    ref: powerpal_ble
    type: git
  components:
  - ble_client
  - powerpal_ble
  refresh: 1d
wifi:
  fast_connect: true
  manual_ip:
    static_ip: 192.168.1.214
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 0.0.0.0
    dns2: 0.0.0.0
  ap:
    ssid: powerpalble
    password: !secret 'ota-password'
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: LIGHT
  networks:
  - ssid: !secret 'ssid'
    password: !secret 'wifi-password'
    priority: 0.0
  use_address: 192.168.1.214
api:
  password: !secret 'ota-password'
  port: 6053
  reboot_timeout: 15min
ota:
  password: !secret 'ota-password'
  safe_mode: true
  port: 3232
  reboot_timeout: 5min
  num_attempts: 10
logger:
  baud_rate: 115200
  tx_buffer_size: 512
  deassert_rts_dtr: false
  hardware_uart: UART0
  level: DEBUG
  logs: {}
time:
- platform: homeassistant
  id: homeassistant_time
  timezone: AEST-10AEDT,M10.1.0,M4.1.0/3
  update_interval: 15min
esp32_ble_tracker:
  scan_parameters:
    duration: 5min
    interval: 320ms
    window: 30ms
    active: true
ble_client:
- mac_address: D5:D7:12:2C:68:75
  id: powerpal
sensor:
- platform: powerpal_ble
  ble_client_id: powerpal
  power:
    name: Powerpal Power
    disabled_by_default: false
    force_update: false
    unit_of_measurement: W
    accuracy_decimals: 5
    device_class: power
    state_class: measurement
  daily_energy:
    name: Powerpal Daily Energy
    disabled_by_default: false
    force_update: false
    unit_of_measurement: kWh
    accuracy_decimals: 5
    device_class: energy
    state_class: total_increasing
  energy:
    name: Powerpal Total Energy
    disabled_by_default: false
    force_update: false
    unit_of_measurement: kWh
    accuracy_decimals: 5
    device_class: energy
    state_class: total_increasing
  battery_level:
    name: Powerpal Battery
    disabled_by_default: false
    force_update: false
    unit_of_measurement: '%'
    accuracy_decimals: 0
    device_class: battery
    entity_category: diagnostic
  pairing_code: 667124
  notification_interval: 1
  pulses_per_kwh: 800.0
  time_id: homeassistant_time
  powerpal_device_id: 0000d32e
  powerpal_apikey: 1ea7e8b2-4a8f-4e20-8e61-d2120e8c7026

but when I complie:
I get errors and fails to compile:

n file included from src/esphome/components/ble_client/ble_client.cpp:5:0:
src/esphome/components/ble_client/ble_client.h:91:8: error: 'void esphome::ble_client::BLEClient::gap_event_handler(esp_gap_ble_cb_event_t, esp_ble_gap_cb_param_t*)' marked 'override', but does not override
   void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
        ^
*** [/data/powerpalble/.pioenvs/powerpalble/src/esphome/components/ble_client/ble_client.cpp.o] Error 1

Full log:

INFO Detected timezone 'Australia/Sydney'
INFO Generating C++ source...
INFO Core config or version changed, cleaning build files...
INFO Deleting /data/powerpalble/.pioenvs
INFO Compiling app...
Processing powerpalble (board: nodemcu-32s; framework: arduino; platform: platformio/espressif32 @ 3.5.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- <WiFi> 1.0
|-- <ESPmDNS> 1.0
|-- <Update> 1.0
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/api_connection.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/api_frame_helper.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/api_pb2.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/api_pb2_service.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/api_server.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/list_entities.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/proto.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/subscribe_state.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/api/user_services.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/ble_client/ble_client.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/esp32/core.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/esp32/gpio_arduino.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/esp32/gpio_idf.cpp.o
Compiling /data/powerpalble/.pioenvs/powerpalble/src/esphome/components/esp32/preferences.cpp.o
In file included from src/esphome/components/ble_client/ble_client.cpp:5:0:
src/esphome/components/ble_client/ble_client.h:91:8: error: 'void esphome::ble_client::BLEClient::gap_event_handler(esp_gap_ble_cb_event_t, esp_ble_gap_cb_param_t*)' marked 'override', but does not override
   void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
        ^
*** [/data/powerpalble/.pioenvs/powerpalble/src/esphome/components/ble_client/ble_client.cpp.o] Error 1
========================== [FAILED] Took 5.53 seconds ==========================

My yaml file:

substitutions:
  device_name: powerpalble
  friendly_name: "powerpalble"
  device_ip: 192.168.1.214

#################################

esphome:
  name: ${device_name}
#  includes:
#    - powerpal_ble.cpp
#    - powerpal_ble.h  
    
esp32:
  board: nodemcu-32s
  framework:
    type: arduino

external_components:
  - source: github://WeekendWarrior1/esphome@powerpal_ble
    # requires ble_client because I had to add some small features to authenticate properly
    components: [ ble_client, powerpal_ble ]
    
wifi:
  ssid: !secret ssid
  password: !secret wifi-password
  fast_connect: on 
  manual_ip:
    static_ip: ${device_ip}
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "powerpalble"
    password: !secret ap-password
    
api:
  password: !secret api-password

ota:
  password: !secret ota-password

logger:



    
# optional requirement to enable powerpal cloud uploading
#http_request:
#  id: powerpal_cloud_uploader

# optional requirement used with daily energy sensor
time:
  - platform: homeassistant
    id: homeassistant_time

esp32_ble_tracker:

ble_client:
  - mac_address: d5:d7:12:2c:68:75
    id: powerpal

sensor:
  - platform: powerpal_ble
    ble_client_id: powerpal
    power:
      name: "Powerpal Power"
    daily_energy:
      name: "Powerpal Daily Energy"
    energy:
      name: "Powerpal Total Energy"
    battery_level:
      name: "Powerpal Battery"
    pairing_code: 667124
    notification_interval: 1
    pulses_per_kwh: 800
    time_id: homeassistant_time 

# daily energy still works without a time_id, but recommended to include one to properly handle daylight savings, etc.
#    http_request_id: powerpal_cloud_uploader
#    cost_per_kwh: 0.1872 #dollars per kWh
    powerpal_device_id: 0000d32e #optional, component will retrieve from your Powerpal if not set
    powerpal_apikey: 1ea7e8b2-4a8f-4e20-8e61-d2120e8c7026 #optional, component will retrieve from your Powerpal if not set

Any ideas why this wouldn’t compile?

I copied and compiled your yaml on my machine (ubuntu 20.04, ESPHome using docker), docker run --rm -v "${PWD}":/config --net=host -it esphome/esphome:latest compile pencilhead.yaml, and it compiled with no issues.

I am guessing you are using ESPhome through your HASSIO install?
From my experience that seems to lead to countless issues (from what I have seen on the ESPHome discord).
Could you please install ESPHome on a different computer following this guide: Installing ESPHome Manually — ESPHome
And then try compiling again, thanks.

PS.
When running esphome version, I get Version: 2022.5.1

Yes, I was using it through HASSIO.
I’ve installed on another computer and it’s working.
Thanks so much for your assistance and hard work :slight_smile:

1 Like

Small update . I tried to work out why this wouldn’t compile under HASSIO/Home assistant.
It seems that esphome version I was running has been deprecated since March 2022.
There is a new version in HA - Settings / Addons. I had to uninstall old version as I think there are leftover files if installing over the top.

I also had to delete build files from powerpal folder to force update.
Location:
/usr/share/hassio/homeassistant/esphome/.esphome/build/

Compiling within HA is now successful :slight_smile:

I setup WeekendWarrior1/powerpal_ble: Collection of code, tools and documentation for data retrieval over BLE from your Powerpal (github.com) on an M5Stack Atom Lite yesterday, and the whole process was perfectly smooth. It has been running for ~15 hours now without missing a beat. Thank you @WeekendWarrior1 !

2 Likes

Are you able to shed some light on how you got that going please?
I’ve got a spare M5Stack Atom Lite (I got several for my ESPresense setup and ordered one too many), so it’s already been flashed for ESPresense.
Any suggestions on how to get it to a point where I can use this?

Hi Delorean,

You will need to flash ESPHome over ESPresence on your spare esp32.
If you have HASSIO, you can follow this guide: Getting Started with ESPHome and Home Assistant — ESPHome, else you can follow this guide to install it on a local machine: Installing ESPHome Manually — ESPHome

After getting ESPHome installed, you will need to configure the ESPHome yaml (and I am guessing you are trying to connect to a powerpal and not an emerald), so find the project template here: powerpal_ble/powerpal_ble.yaml at 84c460de9b8ea2407cd480e6c43bb83bde49fd64 · WeekendWarrior1/powerpal_ble · GitHub
You will need to update to esp32>board to m5stack-atom and your wifi settings, as well as entering the BLE MAC address of your powerpal, your powerpal pairing code and your number of pulses per kwh.

Instructions on how to get these values can be found here: https://github.com/WeekendWarrior1/powerpal_ble#using-the-esphome-component
When your yaml is all filled out, you use ESPhome to build and flash it to your esp32!
The guides above should cover that, but I am also happy to help if you get stuck.

1 Like

Hey!
Could you tell me where you got your esp32 from? Thanks in advance :slight_smile:

Brilliant, thanks so much. I was concerned that I’d need to install a whole ESPHome solution to use it, but that’s because I didn’t RTFM about what ESPHome exactly is. :slight_smile:

Will give that a go this week.

I’ve just bought another from eBay. Gone up in price. First one was $10aud delivered from a local seller. Second was $11.50 from another seller

This one?

[MZ] ESP32 WiFi/Bluetooth Dev Board ESP-32S ESP-WROOM-32 1pc/5pcs/10pcs | eBay

Yep $11.24 for one delivered
Haven’t gotten it yet

1 Like

Absolute legend, got it going now, thank you!!!

I’ve just written a longer form blog post about how I’ve deployed @WeekendWarrior1’s work here, and some other things we’re doing around energy monitoring in our house.

:zap: Smart Home Energy Monitoring in Melbourne, Australia – Tatham Oddie

12 Likes

Clear & concise article. Thanks have booked marked this for a future build.

Fantastic write-up!

@WeekendWarrior1 Thanks for much for your excellent work here!

I had no problem getting it setup, but I haven’t had any luck pushing data to the cloud. The debug message is (correct serial number removed)
[09:10:04][W][http_request:082]: HTTP Request failed; URL: https://readings.powerpal.net/api/v1/meter_reading/xxxxxxxx; Error: connection refused

Any debugging suggestions? I acknowledge that you no longer have access to a powerpal. I’m happy and able to do some debugging (MITM the app, etc).

Somewhat related question, would it be difficult to setup a different http export? I’d be interested in exporting to pvoutput.