Powerpal smart energy monitor

@markcs I am using your solution to get data from the PowerPal meter_reading API endpoint. I noticed the data is only kept in windows of 15 minutes. I was able to get a reading every minute so far using the following

resource_template: https://readings.powerpal.net/api/v1/meter_reading/<device_id>?start={{ (as_timestamp(now()) - 960) | int }}&end={{ (as_timestamp(now()) - 900) | int }}&sample=1

This gives a single entry for the 1 minute window. The only problem is that it’s 15 minutes in the past. When using HA graphs it shows it 15 minutes in the future so I have used Grafana/mariadb to create the graph below using the timestamp from the powerpal data. Thank’s for the info btw.

I also added an extra sensor for Watts based on pulses, but I am not 100% sure it is correct.

  - platform: rest
    name: PowerPal History
    method: GET
    scan_interval: 60
    resource_template: https://readings.powerpal.net/api/v1/meter_reading/XXXXXXXX?start={{ (as_timestamp(now()) - 960) | int }}&end={{ (as_timestamp(now()) - 900) | int }}&sample=1
    headers:
      Authorization: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
      Host: readings.powerpal.net
      accept: application/json
      content-type: application/json
      user-agent: okhttp/3.12.1
    json_attributes:
      - timestamp
      - pulses
      - watt_hours
      - cost
      - is_peak
    value_template: "{% if value_json[0] is defined %}{{ value_json[0].timestamp | timestamp_custom('%Y-%m-%d %H:%M:%S') }}{% endif %}"

  - platform: template
    sensors:
      powerpal_timestamp:
        friendly_name: "PowerPal Timestamp"
        value_template: "{{ state_attr('sensor.powerpal_history', 'timestamp') | int }}"
      powerpal_pulses:
        friendly_name: "PowerPal Pulses"
        value_template: "{{ state_attr('sensor.powerpal_history', 'pulses') | int }}"
        unit_of_measurement: "Pulses"
      powerpal_watt_hours:
        friendly_name: "PowerPal Watt Hours"
        value_template: "{{ state_attr('sensor.powerpal_history', 'watt_hours') | int }}"
        unit_of_measurement: "Wh"
      powerpal_watts:
        friendly_name: "PowerPal Watts"
        value_template: "{{ ((state_attr('sensor.powerpal_history', 'pulses') | int * 1000) / 60) | round(1) }}"
        unit_of_measurement: "W"
      powerpal_cost:
        friendly_name: "PowerPal Cost"
        value_template: "${{ state_attr('sensor.powerpal_history', 'cost') | float }}"
        unit_of_measurement: ""

Here’s the SQL I used to push the graph data back 15 minutes using grafana/mariadb. The negative number I used (-39580) is more then 15 minutes in my query as he mariadb instance I am using has a different timezone to the powerpal timestamp.

SELECT
  FROM_UNIXTIME(JSON_EXTRACT(attributes,"$.timestamp")-39580) as "time",
  "PowerPal (1min)" AS "metric",
  CAST(JSON_EXTRACT(attributes,"$.watt_hours") AS FLOAT) * 60 as "value"
FROM states
WHERE JSON_EXTRACT(attributes,"$.watt_hours") != ""
AND JSON_EXTRACT(attributes,"$.timestamp") BETWEEN SUBSTR($__from,1,10) AND SUBSTR($__to,1,10)
1 Like

Not that that’s ever stopped me :wink:

IMPORTANT NOTICE
Connecting third party applications to Powerpal directly over BLE is not (and will never be) supported due to potential data security risks. Any attempt to connect to Powerpal directly over BLE and retrieve data may trigger anti-tamper measures which would render your Powerpal inoperable, as well as voiding the warranty.

Today I received an email from PowerPal regarding the beta testing program for their wifi based hub.
I’ve since registered, has anyone else received the same email?

1 Like

I did too, make sure you read the T&C’s of the program if you get accepted regarding posting to forums and social websites.

Cheers.

3 Likes

Yes and I have received the Pro and API access. Do we know if anyone is going to create an integration now that the API is available?

You realise Home Assistant is open source software right?
Creating an integration is up to anyone willing to do it, not some central entity.

MindMelting posted an integration back in October

I see no reason why that wouldn’t be updated to support the new API if there’s any changes.

1 Like

Obviously you missed the point of my comment which was asking if anyone was already actively looking into this… but as usual typical Internet.

1 Like

Thanks for this, I didn’t realize it already existed! Previously powerpal mentioned the API was only available commercially :slight_smile:

Took your comment at face value, and you didn’t ask that.
Maybe make sure your question is actually represents what you’re interested in knowing! :slight_smile:

Question… I have powerpal app on a galaxy tablet. Used the app to set up the pro which now has a green light on it. How do I then connect my phone to it so I can have app on both phone and tablet? Every time i try and connect my phone, it asks to connect to bluetooth but can’t because I already have the tablet connected to it. Confusing as.

Hi I’ve just installed the pro and hass-powerpal, but dont get the live consumption, presumably due to this error on the Energy page

Last reset missing

The following entities have state class ‘measurement’ but ‘last_reset’ is missing:

  • sensor.powerpal_live_consumption

any ideas on how to solve?

I don’t think the dashboard accommodates live consumption. You want the kwh measure for the dashboard. You can break out individual components as detailed below and create your own view. That could the include live consumption. I use a gauge card separately to the dashboard.

type: gauge
min: 0
needle: true
severity:
  green: 0
  yellow: 1000
  red: 3000
max: 10000
entity: sensor.powerpal_live_consumption

You may beable to add in the last reset via a customisation glob… Except I think you would have to be pulling down more of the sensors.

It only allows connection to one device, plus the app must always be running. I’d stick with the tablet because you would probably take your phone with you when you leave the house which would result in no data for the period you’re gone.

1 Like

For anyone interested I have reverse engineered and documented the Powerpal BLE API, and put together a simple sketch for an ESP32 to connect and print out Powerpal energy updates:

I have also reverse engineered the Emerald Electricity Advisor BLE API (and the Emerald Cloud API):

Next steps are to create esphome components for them both (Powerpal will likely come first as it’s authentication process is simpler)

4 Likes

I have finished the Powerpal ESPHome component:

It’s not PR’d to ESPhome yet, but you can use it via external_components like this:

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 ]

# 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: DF:5C:55:00:00:00
    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: 123123
    notification_interval: 1 # every 1 minute
    pulses_per_kwh: 1000
    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: 0000abcd #optional, component will retrieve from your Powerpal if not set
#    powerpal_apikey: 4a89e298-b17b-43e7-a0c1-fcd1412e98ef #optional, component will retrieve from your Powerpal if not set

What it looks like in Home Assistant:
image
(Powerpal Total Energy is used to integrate the usage into the HA Energy Dashboard)

The component still needs a bit of a cleanup and extra features but I hope some people find it useful.

A little bit more documentation is in the readme:

3 Likes

I have now also finished the Emerald Electricity Advisor ESPHome component if anyone has one of these instead of the Powerpal:

Just like the Powerpal component, it’s not PR’d to ESPhome yet, but you can use it via external_components like this:

external_components:
external_components:
  - source: github://WeekendWarrior1/esphome@emerald_ble
    # requires ble_client and ble_tracker because I had to add some small features to authenticate properly
    components: [ ble_client, esp32_ble_tracker, emerald_ble ]

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

esp32_ble_tracker:

ble_client:
  - mac_address: 30:1B:97:01:02:03
    id: emerald_advisor

sensor:
  - platform: emerald_ble
    ble_client_id: emerald_advisor
    power:
      name: "Emerald Power"
    daily_energy:
      name: "Emerald Daily Energy"
    energy:
      name: "Emerald Total Energy"
    battery_level:
      name: "Emerald Battery"
    pairing_code: 123123
    pulses_per_kwh: 1000
    time_id: homeassistant_time # daily energy still works without a time_id, but recommended to include one to properly handle daylight savings, etc.

What it looks like in Home Assistant:
image

(Like above, Emerald Total Energy is used to integrate the usage into the HA Energy Dashboard)
Also like above, the component still needs a bit of a cleanup and extra features but I hope some people find it useful.
A little bit more documentation is in the readme:

I am not very familiar with ESPHome. But I do have an ESP32. Can I install this?

I tried my hand at this and get the following error.

Whoops sorry, there was a bug in the change I made to the power units.
Please try again with the same yaml