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
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') }}"
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.
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.
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.
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.
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
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.
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.