Powerpal smart energy monitor

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.

[11:28:41][VV][esp32_ble_tracker:648]: Parse Result:
[11:28:41][VV][esp32_ble_tracker:665]:   Address: DD:A3:C1:7F:DA:0B (RANDOM)
[11:28:41][VV][esp32_ble_tracker:667]:   RSSI: -60
[11:28:41][VV][esp32_ble_tracker:668]:   Name: 'Powerpal 0001e9f0'
[11:28:41][VV][esp32_ble_tracker:676]:   Ad Flag: 5
[11:28:41][VV][esp32_ble_tracker:679]:   Service UUID: 0xFCD7
[11:28:41][VV][esp32_ble_tracker:698]: Adv data: 02.01.05.03.03.D7.FC.12.09.50.6F.77.65.72.70.61.6C.20.30.30.30.31.65.39.66.30 (26)

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
cost:
       name: "Powerpal Cost_json"
       unit_of_measurement: "$/kWh"
1 Like

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);'
3 Likes

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 :slight_smile:

Rob

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 have no idea what that error message means, so I would really appeciate some advice on what it means and what I need to do to fix it.

I believe that I am running the latest versions of @muneeb1990 's code and .yaml scripts (powerpal.yaml, configuration.yaml & automations.yaml).

Thanks in anticipation …

Further to my post yesterday, here is a more detailed error report from the log file today:

2023-03-27 13:21:00.264 ERROR (MainThread) [homeassistant.components.rest_command] Client error. Url: https://readings.powerpal.net/api/v1/meter_reading/000222e2. Error: Cannot connect to host readings.powerpal.net:443 ssl:default [Name does not resolve]

2023-03-27 13:22:00.242 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: ‘None’ has no attribute ‘state’ when rendering ‘[ {“cost”:{{ states.sensor.powerpal_cost_json.state }},“is_peak”: false, “pulses”:{{ states.sensor.powerpal_pulses_json.state }}, “timestamp”: {{ as_timestamp(now(),0) | int(0) }} , “watt_hours”: {{ states.sensor.powerpal_watt_hours_json.state}} } ]’

I would love to know what those messages mean and how to fix them … :grinning:

Looks like HA is unable to reach the URL. Have you tried pinging it from the system running HA? Maybe do a ping test to see if it’s reachable.

Here’s the ping result from HA:

and here’s the same ping from my Windows 10 PC:

Does this mean that Powerpal have changed the host details? I don’t understand why I cannot ping that URL … :worried:

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 … :face_with_raised_eyebrow:

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.

That URL is for retrieving the data from Powerpal cloud.

There’s something going on with your device or internet connection as I can ping this URL just fine:

image

When I paste the URL into Chrome like you did, I get the same result as you:

However, if I “ping” that URL, this is what I get:

And I am still getting this error in HA:

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?

I haven’t done more research into this as the current solution seems to be working well for the past 6 months or so. But you’re welcome to dig in.

Haven’t heard anything from Powerpal either.

Thanks for the update. Time to dig in and hopefully finish it this time :grinning_face_with_smiling_eyes:

How do you deal with solar production as powerpal doesn’t deal with that?

That’s an issue for sure but haven’t found a foolproof way to do it yet.

1 Like