So I managed to pull Powerpal data into HomeAssistant today after a bit of tinkering.
Shout out to some of the links already in this thread that helped me in the right direction.
Also other people have mentioned using mitmproxy and an Apple device to get your Auth Key which you will need. I tried on an Android device but couldnt get it to work due to certificate pinning. I tried reversing the APK to remove any SSL security stuff but proved to be just too hard. You’ll need to find an Apple device that’s at least iOS 10.
Anyway without further ado the sensor code,
*** Please alter the values marked with XXXX, or else this will not work ***
The first set of XXXXX is your serial number. Easiest way is look at the bluetooth device you’re connected to. It’ll be “Powerpal XXXXXXXX” that’s your serial number.
The Authorization code can be obtained using mitmproxy as above, this is not the same thing as your pairing code or any password you may have setup. It generated and only available from decrypting the app traffic
# Sensors for PowerPal
- platform: rest
name: powerpal
method: GET
scan_interval: 60
resource: https://readings.powerpal.net/api/v1/device/XXXXXXXX
headers:
authorization: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
accept: application/json
accept-encoding: br, gzip, deflate
accept-language: en-au
content-type: application/json
user-agent: Powerpal/1912 CFNetwork/894 Darwin/17.4.0
value_template: "OK"
json_attributes:
- total_watt_hours
- last_reading_watt_hours
- platform: template
sensors:
powerpal_output_actual:
friendly_name: "Powerpal Current Power Usage"
value_template: "{{ states.sensor.powerpal.attributes.last_reading_watt_hours | int * 60 }}"
unit_of_measurement: 'W'
device_class: power
powerpal_output_total:
friendly_name: "Powerpal Total Power Usage"
value_template: "{{ states.sensor.powerpal.attributes.total_watt_hours | float / 1000 }}"
unit_of_measurement: 'kWh'
device_class: energy
And this goes in your customize.yaml or configuration depending where you keep customizations
It is necessary to have the sensors show up in the new Energy part of HomeAssistant.
customize_glob:
sensor.powerpal_output_actual:
state_class: measurement
sensor.powerpal_output_total:
state_class: total_increasing
Now for a little explanation. This calls the v1/device Powerpal API endpoint. It returns several JSON formatted values of which the last_reading and total are what we require.
The rest sensor does the work, but as the response is > 255 characters we generate a dummy response “OK” for the main state, and shove the other values we actually require into other entity attributes.
Now using HomeAssistant’s templating we create 2 more sensors that have to be massaged into the right format for Energy module to use.
I divide the usage total by 1000 to get kWh which is more useful, and required in the format.
For the current usage I multiply the last_reading by 60 to get an instantaneous power usage. A reading is capture by Powerpal every 1min, and given it’s in Watt/hours multiplying this by 60 gets us the usage in Watts.
It’s not 100% accurate but it’s good enough. I dabbled with getting results from the v1/meter_readings endpoint to retrieve multiple readings and averaging them but for the extra complexity it didnt provide much value.
This instantaneous value isn’t used by the Energy module that only uses totals, but I grabbed it as it’s handy to display current usage on a widget.
For the HA Energy module I used a fixed value for cost per kWh as mine is a fixed cost per kWh. Powerpal does return a last_reading_cost so in theory you should be able to grab that and use it to create another sensor for cost which can use to calculate cost. If many people need it I can take a look, although given the above template most could work it out I suspect. the JSON attr is “last_reading_cost” and if you * 60 you’ll get AU$ per hour of actual cost used (I think).
Can I also request if you’re using this please don’t hammer their API more than every 60s. As the official app only uploads every 60s there’s no point doing it more often, and you’ll probably just piss Powerpal off and this unofficial method will be shut down.
Happy to answer anything if I can about what I found tinkering with the APIs (yes you can upload your own garbage data if you really want to). The Meter Reading API is quirky and really isn’t of much use for HomeAssistant unless you’d like to know and store more accurate historical data.
Hope this helps someone.