Just to help others on the same journey - got my ESP32 working to pull data from my Powerpal over the weekend and have a few learnings:
I had compile issues too so followed @starryalley version of powerpal_ble. I also removed ble_client from the components declaration towards the top of the YAML. Once I’d done that then it all compiled smoothly
Next, I had heaps of trouble finding the Mac address of my powerpal. I tried running the esp32_ble_tracker and the iphone apps etc. I even let ble_tracker run with logging level set at VERY_VERBOSE and pulled those logs into a spreadsheet to make a list of every bluetooth device in range. I had 31 unique Mac addresses to go through. At up to 5 minute compile time, that equals a huge time suck. What makes this difficult is that I didn’t know whether the Powerpal was broadcasting a name, and I had a heap of devices reporting an empty name field - so I had to just go through the list (in order of RSSI) and try each once. In the end, I turned off as many bluetooth devices as I could find and ran the scanner - and I can confirm that Powerpal IS reporting a name. So here’s the scan result that I got - after that everything was super-easy.
I was interested that the RSSI was so low! But also that the Mac address is Random (meaning it may change at some point in the future and I need to watch for data drop outs).
Lastly, I had to change the sensor definition in the yaml to include a unit of measurement, this means you can use the data in the Home Assistant Energy Dashboard. My cost sensor now looks like this
Hello everyone - I’ve recently made some changes to enable Daily Energy values to persist through reboots. Copy the powerpal_ble folder from here into my_components folder under config>esphome.
Updated yaml:
esphome:
name: "esp32-powerpal"
on_boot:
then:
- lambda: |-
powerpal_ble_powerpal->daily_pulses_ = id(powerpal_daily_pulses_backup) ;
esp32:
board: esp32dev
external_components:
- source:
type: local
path: my_components
components: [powerpal_ble]
# Enable logging
logger:
level: VERY_VERBOSE
logs:
esp32_ble_tracker: WARN
# Enable Home Assistant API
api:
ota:
#esp32_ble_tracker:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# optional requirement used with daily energy sensor
time:
- platform: homeassistant
id: homeassistant_time
esp32_ble_tracker:
ble_client:
- mac_address: XX:XX:XX:XX:XX:XX
id: powerpal
#http_request:
#id: powerpal_cloud_uploader
switch:
- platform: restart
name: "Powerpal Monitor Reboot"
globals:
- id: powerpal_daily_pulses_backup
type: int
restore_value: true
sensor:
- platform: powerpal_ble
ble_client_id: powerpal
power:
name: "Powerpal Power"
daily_energy:
name: "Powerpal Daily Energy"
daily_pulses:
name: "Powerpal Daily Pulses"
energy:
name: "Powerpal Total Energy"
battery_level:
name: "Powerpal Battery"
watt_hours:
name: "Powerpal Watt Hours_json"
cost:
name: "Powerpal Cost_json"
timestamp:
name: "Powerpal Timestamp_json"
pulses:
name: "Powerpal Pulses_json"
pairing_code: 123456
notification_interval: 1
pulses_per_kwh: 1000
#http_request_id: powerpal_cloud_uploader
time_id: homeassistant_time # daily energy still works without a time_id, but recommended to include one to properly handle daylight savings, etc.
cost_per_kwh: x.xxx #dollars per kWh
- platform: homeassistant
id: ha_daily_pulses
entity_id: sensor.powerpal_daily_pulses
on_value:
then:
- globals.set:
id: powerpal_daily_pulses_backup
value: !lambda 'return int(x);'
Thanks everyone for the pointers and @muneeb1990 for the code - got mine running nicely.
I ended up purchasing a pack of the M5Stack Atom Lites, and now have spares sitting here in NSW, Australia if anyone’s interested - currently listed on ebay. Feel free to DM me if you want one (selling for ~ $20 per unit plus postage), just covering costs getting them to Australia
I am about 99% of the way there, except that I don’t think the upload to the Powerpal cloud is working correctly. I checked the logs and this error appears:
I’m using the same URL (obviously with a different device ID) and it’s working. Can you double check the device ID or check using a different internet connection? Like mobile data.
If by the “device ID” you mean the serial number of the Powerpal unit, then ‘000242e5’ is correct. I also tried the ping test from my laptop connected to the internet via the hotspot from my phone, with the same result - “Ping request could not find host”. This is weird …
Do I have to be registered with the Powerpal Beta program (which I have not been accepted to join, because they claim that it is full) to use that URL?
Nope, I’m not aware of any such requirements. Maybe try connecting Powerpal with your phone to see if the app gets updated. Sorry, can’t help much as this seems to be unrelated to HA.
Prior to using HA to gather electricity usage data from the Powerpal device, I was using a spare phone to connect via Bluetooth to the Powerpal and upload the data to their cloud. That enabled me to use the Powerpal App on any other smart device anywhere, and that worked fine.
I have just recently powered off the spare phone and replaced it with an ESP32 programmed with your code to get the Powerpal data into HA, and that all works fine, except that the data now does not get uploaded to the Powerpal cloud.
I just did a test:-
I powered off the ESP32 and powered on the spare phone again and it connected to the Powerpal device. From my active phone or my tablet I could view all the Powerpal electricity data, and they were both up to date.
I then replaced the spare phone with the ESP32 and I could see all the current data in HA. But from my active phone or my tablet, I could only view data up to the point where I powered of the spare phone. None of the data collected by the ESP32 and visible in HA, is visible in the apps on my phone or on my tablet.
It looks like the URL that the app in my smart phone uses to read the data from the cloud is somehow different (apart from the device ID) to the URL that you are using. How did you determine the correct URL to use and is there a way that I can discover the URL that the Powerpal App on my phone uses?
You will have to run a MITM proxy to intercept the requests being made by the Powerpal app. This will allow you to see the URL it’s using to upload to cloud.
Unfortunately, mitmproxy doesn’t work with apps on an Android phone without first stripping all the security stuff out of the app, so I might have to skip that bit. Or try to get hold of an iPhone …
I also noticed back in this post that another Powerpal cloud URL is https://readings.powerpal.net/api/v1/device/XXXXXXXX, so maybe there are several in use. I just have to figure out what mine is.
I really appreciate your patience and advice so far, and rather than waste anymore of your time, I think I will just remove the cloud upload process from HA …
This project totally fell by the wayside but I’m ready to get back onto this. Given this is almost two years is there a somewhat elegant solution (there was talk of an API by Powerpal) or do we still have to use the rest platform and get the authorisation key via mitmproxy to read the data from readings.powerpal.net or build a pulse counter?