mindmelting / hass-powerpal

Home Assistant custom integration to fetch data from Powerpal
MIT License
44 stars 11 forks source link

add python script to retrieve apikey over BLE #12

Closed WeekendWarrior1 closed 2 years ago

WeekendWarrior1 commented 2 years ago

After reverse engineering the Powerpal BLE comms I didn't think to bother with any of the REST API because that had been covered pretty well by a couple of other github projects.

But on coming back to it I realised that there was one step that is still a bit of a pain and mystery, retrieving the apikey! (though I believe now you can maybe apply for it, this is probably still more convenient)

The Apikey is actually stored locally on the Powerpal, behind the 'UUID' (59DA0009-12F4-25A6-7D4F-55961DCE4205) characteristic.

This is a super simple python script to retrieve it, and only requires the Powerpal MAC address (can easily be found by scanning for bluetooth devices), and the pairing code given to you with your Powerpal (can also be found within the Powerpal Application)

I don't currently have access to a Powerpal to test this on, so would really appreciate if you could give it a go and let me know if it works (it's also possible the data that comes back might need to have it's bytes reversed)

Can run by adding your mac and pairing key as arguments, or by changing them in the script: python3 utils/retrieve_api_key.py "12:34:56:78:90:AB" 123123

WeekendWarrior1 commented 2 years ago

PS. https://github.com/WeekendWarrior1/powerpal_ble has info on the BLE reverse engineering and an ESPHome configuration if you want to retrieve data without using an always on phone/tablet (or Powerpal Pro wifi gateway) and the Powerpal Cloud

WeekendWarrior1 commented 2 years ago

Closing as probably doesn't make sense in this repo. One can find the python auth retrieval script here: https://github.com/WeekendWarrior1/powerpal_ble/tree/main/auth_extraction And some documentation on manually decoding the auth and device BLE values here: https://github.com/WeekendWarrior1/powerpal_ble#powerpal-api-key-and-device-id

mindmelting commented 2 years ago

Super! Sorry just saw this - this is really useful...

Let me give it a go and link to your repo in the README