Powerpal smart energy monitor

This guide looks pretty decent: Setting-up mitmproxy on macOS to intercept https requests | by Luis Wu | What I talk about when I talk about iOS development | Medium

1 Like

Ok. Looks like I need to find some downtime for my daughter so I can snatch her iPhone for a while or find an Android equivalent.

Actually I think it has to be the iPhone as the Powerpal app at the moment is only on my Android and if I understand your article correctly I need a second device to intercept the traffic and get the authorisation token

Ok. I think I have this up and running. Whatā€™s the syntax of the authorisation token? I can see a 36 character string (including ā€œ-ā€) as part of a GET request. Is that it?

I presume that youā€™ve just tested it by now, but that sounds correct. It appears to be a UUIDv4 value, but specifically it should be prefixed by "Authorization: ", as itā€™s an HTTP header value.

I thought about going that way, but wanted the whole thing in Home Assistant, so I just implemented this using the rest platform and sensors. One things I havenā€™t managed to work out is how to get all the json data into HA (Iā€™m only looking at the first returned result) and then how to use the resulting data. I might have to look through @forfuncsake code to see what is done there.

Anyway, this is my first attempt directly from within HA. Better solutions appreciated, as Iā€™m relatively new to this.

  - platform: rest
    name: powerpal
    method: GET
    scan_interval: 300
    resource_template: https://readings.powerpal.net/api/v1/meter_reading/<specific device id>?start={{ (as_timestamp(now()) | int) - 300 }}&end={{ (as_timestamp(now()) | int) }}
    headers:
      Authorization: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
      Host: readings.powerpal.net
      accept: application/json
      content-type: application/json
      user-agent: okhttp/3.12.1
    json_attributes_path: "$[0]"
    json_attributes:
      - pulses
      - watt_hours
      - cost
      - is_peak
    value_template: "{{ value_json.timestamp }}"

  - platform: template
    sensors:
      powerpal_pulses:
        friendly_name: "PowerPal Pulses"
        value_template: "{{ state_attr('sensor.powerpal', 'pulses') }}"
      powerpal_watt_hours:
        friendly_name: "PowerPal Watt Hours"
        value_template: "{{ state_attr('sensor.powerpal', 'watt_hours') }}"
      powerpal_cost:
        friendly_name: "PowerPal Cost"
        value_template: "{{ state_attr('sensor.powerpal', 'cost') }}"
      powerpal_is_peak:
        friendly_name: "PowerPal Is peak"
        value_template: "{{ state_attr('sensor.powerpal', 'is_peak') }}"
2 Likes

Iā€™m not sure about getting HA to save and present all of the data points - but if youā€™re happy to look at just one value at a time, you can bucket the results on the server and let it aggregate the total for the 5 min block into a single element.

Just add &sample=5 to the end of the url query string.

1 Like

In saying that, you could just add a few sensors: a 5min, a 60min and a 24 hour. That would give you a reasonable view of your data with the ability to open the app only if you want up to the second readings.

Personally, I just want to save all of the individual data points - I can figure out what to do with them and how to present them later. But once Iā€™ve got them Iā€™m free to update my presentation and historic queries even if the API goes away on us.

1 Like

Is the mitm token different from the token on the data download from the app?

Yes, theyā€™re different. The API token is a UUID value which shouldnā€™t expire and the download link contains a time-limited (24hrs, I believe) JWT.

1 Like

Well yes and no; I managed to get the Powerpal authorisation token but canā€™t find the InfluxDB API key. Put a query onto the community forum. Where did you get the InfluxDB API key from?

Thanks for the samples option in the URL. That allows us to adjust the refresh frequency of the sensor and not send too many requests to powerpal.

HA does capture and save the data. Iā€™m not sure how though to convert and save the data so it is meaningful.

So once youā€™ve set up your InfluxDB instance (Iā€™m just using a docker container), open the web interface for it and browse to Data ā†’ Tokens, you will either find an existing admin token there, or you can generate one.

I may be wrong, I couldnā€™t find that data menu in the add-on version of influx. I donā€™t think you can generate the token. Except perhaps via the cli somehow. There is an option to use the token in the connection config. I just couldnā€™t fine where/how to generate it.

Same situation as @HasQT
When I open the web interface all I see is this

What youā€™re saying corresponds with an answer I got on the InfluxDB forum (View API tokens in InfluxDB | InfluxDB OSS 2.0 Documentation) but I canā€™t see this data menu.

1 Like

Based on what you said earlier I understand youā€™re more inclined to use InfluxDB as the data store (as opposed to HA) and then use Home Assistant to access this data for presentation, processing etc.

Have you seen this InfluxDB - Home Assistant? Looks like itā€™s possible to use data from InfluxDB and populate sensor states in Home Assistant

I came in with the intention of viewing/using my Powerpal data in HA, a quick google search led me to believe that InfluxDB was the DB of choice for such thingsā€¦ so thatā€™s why I picked it :slight_smile:
From a quick look at those docs, it says that the add-on version doesnā€™t enforce auth. The client docs say that you can use an empty string for a server without auth (GitHub - influxdata/influxdb-client-go: InfluxDB 2 Go Client)

so if you never set up auth, you could try connecting with an empty API token (just donā€™t set the env var).

Iā€™m hoping to try this out too. At the moment, Iā€™m using the InfluxDB addon in HA. Referring to your blog, where would I type those commands? These are one off export/imports right? Do I have to keep running it to load data into influxdb?

Yes, youā€™d need to set it up to run on your preferred schedule (daily, hourly, every 5 min) to fetch the latest data and update the influxDB bucket. As far as where - as documented, youā€™d run that in a terminal (Mac, linux) or command prompt (windows) on a computer thatā€™s set up for go development.
If I find some more time, Iā€™ll see about putting together a release with compiled binaries so you donā€™t need go.

1 Like

Thanks mate. Much appreciated.

If anyone is interested, they have a patent for the device that lays out its application logic, might be useful to read

Itā€™s here: IP Australia: AusPat Disclaimer
Just open the specification.
The flowchart on the last page seems to describe the device logic.

Iā€™m interested in getting the data from mine too, as itā€™s clearly a closed system and the constant ads in app and lockdown of reports bugs me a lot.

1 Like