Community
OpenEnergyMonitor

Community

Powerwall API help

Did you search the community? Several folk have done just this.

Thank you Trystan and Brian for your responses.
I had read other posts on the subject, but I couldn’t find a solution other than suggestions to use Node Red or Emoncms HTTP API or MQTT - which at the moment are beyond me!
However, given the current enforced time at home, and the very helpful guidance in your replies, I am going to teach myself how to do it !
Thanks Again
Chris

2 Likes

@haffle, did you get a Node-Red flow for pulling the data off your Powerwall?

@cbn1, if you have a spare Pi, then that is best for Node-Red. I’m not keen on mixing things on the emonPi; it can have unexpected consequences. (I changed the thread title).

@miker, did you get it to work, I presume so. - How to add a CA cert to access a powerwall?

Hi @borpin - yes I did, and it works well.

The code I used, having been helped by @miker on this forum, is

[{"id":"3ceb5e73.2f9352","type":"http request","z":"30189346.6b7acc","name":"charge","method":"GET","ret":"obj","paytoqs":false,"url":"https://192.168.REDACTED.REDACTED/api/system_status/soe","tls":"e5ec1e65.f66b1","persist":false,"proxy":"","authType":"","x":410,"y":260,"wires":[["40a510f1.be352"]]},{"id":"40a510f1.be352","type":"json","z":"30189346.6b7acc","name":"","property":"payload","action":"str","pretty":false,"x":590,"y":260,"wires":[[]]},{"id":"e5ec1e65.f66b1","type":"tls-config","z":"","name":"TLS configuration","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

… but I have typed REDACTED four times in that - the first two are the Powerwall local IP and the second two are the emonPi local IP. Hopefully there is no other personal info in the code!

It grabs data once every 10 seconds, and forwards it to my emonCMS dashboard.

FWIW, I have a dedicated Raspberry Pi Zero W for doing the Node-RED, and again it is working well.

Julian

1 Like

Thanks. Did you remove the API key from the emoncms node?

I reformatted above - you can use a single back tick inline but for bulk, 3 backticks on a line before and 3 on a line after will format it as above :grin:.

@borpin I didn’t, but 99% sure it isn’t in there. I did look, and whilst it is needed in one of the Nodes, for some reason it didn’t seem to get included in the code “Export”. (Thanks for the reformatting - I didn’t know how to do that).

@cbn1 - if you want to use the emonCMS battery icon for showing the Powerwall SoC, you might want to edit the code a bit so that it displays 10 “chunks” instead of just the 5. Trystan was very helpful and showed me how to do it in this thread. Dashboard battery graphic - granularity

1 Like

beer_cheer thumbsup

2 Likes

There’s no direct security issues with a 192.168.xxx.xxx IP address.
Your external IP address is the one you want to “protect.” i.e. the one you get from your ISP.

2 Likes

@cbn1 - with the risk of the blind leading the blind, if I can help please PM me; I am only just getting to grips with Node-RED, but others on here have been very helpful so it would be good if I could reciprocate a bit.

FWIW, I set Node-RED up on a Pi Zero W, but any Pi will work. In the first instance I followed the guide on https://nodered.org/docs/getting-started/raspberrypi and then if you import the code I posted earlier it should get you going. It can be very frustrating until it works, but then it is very rewarding when it does! :grinning:

(Obviously the Node-RED Pi will need to be working 24/7 for the SoC to get transferred to emonCMS).

(I’m on a roll…)

On the other thread @miker posted this link to some other data available from the powerwall. If you want to import this date to emonCMS with Node-Red, you can use this flow

image

[{"id":"7f4081b4.f1515","type":"json","z":"88bc3298.02488","name":"","property":"payload","action":"","pretty":false,"x":330,"y":280,"wires":[["3aa9261a.7ecb9a"]]},{"id":"3aa9261a.7ecb9a","type":"split","z":"88bc3298.02488","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":220,"wires":[["172e9f57.ec0c81"]]},{"id":"172e9f57.ec0c81","type":"change","z":"88bc3298.02488","name":"","rules":[{"t":"move","p":"payload.last_communication_time","pt":"msg","to":"time","tot":"msg"},{"t":"set","p":"nodegroup","pt":"msg","to":"\"Powerwall-\" & msg.parts.key","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":280,"wires":[[]]}]

You need to add the hhtp request and inject to the code posted above, plus add the emoncms node but it will inject data like this:

3 Likes

Thank you all!
I do have another Pi and was just dusting it off and updating it when I realised your messages were flooding in!
I will try Node Red on it and use the code examples above - sounds like the answer is there thanks to the efforts of others.
I will also try Trystan’s basic Python option - I assume that might be more suitable to run on the emonPi, as it seems a bit excessive to run another Pi 24/7 just to do this function.
Thanks @haffle for your offer of help - I may well take you up on it!

1 Like

You then find lots of other uses for Node-Red… :grinning:.

1 Like

@borpin I’ve tried your solution above, but am still getting “format error, json value is not numeric” when I set emoncms to “simple json”. When I set emoncms to “valid json object” I get “input in not a valid json object”. Any help greatly appreciated!

Strictly a WAG, but is jsonata misspelled? i.e. is it supposed to be jsondata?

Thanks Bill. I’ve made this change, but still get the error. Unless I get other advice I’m going to try and figure out how to retain only the bits I’m interested in. Hoping that I lose the broken bit.

Does your emonCMS config look like this (node group empty)?

image

Can you attach a debug node

  1. after the json node
  2. after the change node

and post the data output here please.

Is the data from the API exactly as you posed in that link above? Any variation and it will not work - I don’t have a Powerwall :sob:.

(sorry I missed your reply).

Thanks Brian, sorry I didn’t mean to sound so demanding.

The battery has been amazing, obviously a big spend and as a household we deliberated whether it was worth it. Here’s the summary of performance/use since install (basically the beginning of March):


The storage takes away most of the need to try and use solar when it’s sunny, so we’re very pleased.

Back to scraping data…

I did have a node set, but this is now removed. Error still there.

Here’s the debug message from the json node (annoyingly truncated, I don’t know how to solve that):

{"site":{"last_communication_time":"2020-03-31T19:39:08.090236114+01:00","instant_power":0,"instant_reactive_power":-682,"instant_apparent_power":682,"frequency":0,"energy_exported":14364,"energy_imported":71113,"instant_average_voltage":70.49158111670735,"instant_total_current":0,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"battery":{"last_communication_time":"2020-03-31T19:39:08.090389106+01:00","instant_power":270,"instant_reactive_power":-10,"instant_apparent_power":270.1851217221259,"frequency":49.928,"energy_exported":191160,"energy_imported":222770,"instant_average_voltage":244.70000000000002,"instant_total_current":-6.800000000000001,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"load":{"last_communication_time":"2020-03-31T19:39:08.090236114+01:00","instant_power":267.7692634613927,"instant_reactive_power":-609.903039936396,"instant_apparent_power":666.0946603736693,"frequency":0,"energy_exported":0,"energy_imported":253848,"in ....

Here’s the debug output from the change node (again truncated):

{"site":{"last_communication_time":"2020-03-31T19:45:06.490250637+01:00","instant_power":19,"instant_reactive_power":-700,"instant_apparent_power":700.2578096672681,"frequency":0,"energy_exported":14364,"energy_imported":71113,"instant_average_voltage":70.29816877652883,"instant_total_current":0,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"battery":{"last_communication_time":"2020-03-31T19:45:06.490578495+01:00","instant_power":960,"instant_reactive_power":10,"instant_apparent_power":960.0520819205591,"frequency":49.884,"energy_exported":191250,"energy_imported":222770,"instant_average_voltage":243.9,"instant_total_current":-24.1,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"load":{"last_communication_time":"2020-03-31T19:45:06.490250637+01:00","instant_power":964.1517270526933,"instant_reactive_power":-615.300164446345,"instant_apparent_power":1143.7582109634843,"frequency":0,"energy_exported":0,"energy_imported":253938,"instant_avera ....

Here’s the json from my powerwall, looks like I have an additional timeout in each section:

{"site":{"last_communication_time":"2020-03-31T19:38:34.590497891+01:00","instant_power":-6,"instant_reactive_power":-693,"instant_apparent_power":693.0259735392318,"frequency":0,"energy_exported":14364,"energy_imported":71112,"instant_average_voltage":71.13243991550785,"instant_total_current":0,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"battery":{"last_communication_time":"2020-03-31T19:38:34.590378522+01:00","instant_power":280,"instant_reactive_power":-20,"instant_apparent_power":280.713376952364,"frequency":49.908,"energy_exported":191160,"energy_imported":222770,"instant_average_voltage":246.9,"instant_total_current":-7,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"load":{"last_communication_time":"2020-03-31T19:38:34.590238779+01:00","instant_power":281.87446053912123,"instant_reactive_power":-622.6192551458452,"instant_apparent_power":683.4529598901358,"frequency":0,"energy_exported":0,"energy_imported":253847,"instant_average_voltage":71.13243991550785,"instant_total_current":3.9626710523909465,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000},"solar":{"last_communication_time":"2020-03-31T19:38:34.590238779+01:00","instant_power":-7,"instant_reactive_power":88,"instant_apparent_power":88.2779700718135,"frequency":0,"energy_exported":229541,"energy_imported":832,"instant_average_voltage":141.56628600529623,"instant_total_current":0,"i_a_current":0,"i_b_current":0,"i_c_current":0,"timeout":1500000000}}

I think I’m only interested in the instant_power variable from each of the four sets (although the site data will hopefully match what my emonpi is capturing via its CT clip.

To copy the data out click here.

image

You also need to change the debug node to be the complete message object -

image

However, there must be something wrong with the change node as it should start not start

image

The debug output from the change node should look like

image

Note the last_communication_time has gone and been moved into the msg.time element.

It does look like this?

I’ve switched my debug output to complete message object, even so I don’t get that nice formatting or option to export:

This is my flow without the emoncms node:

[{"id":"6f4bec9.6832c94","type":"tab","label":"Flow 2"},{"id":"a79716f8.3613c8","type":"json","z":"6f4bec9.6832c94","name":"","x":234,"y":215,"wires":[["fbb0563f.73c548"]]},{"id":"fbb0563f.73c548","type":"split","z":"6f4bec9.6832c94","name":"","splt":"\\n","x":394,"y":155,"wires":[["dfdea58c.83c7f8"]]},{"id":"dfdea58c.83c7f8","type":"change","z":"6f4bec9.6832c94","name":"","rules":[{"t":"move","p":"payload.last_communication_time","pt":"msg","to":"time","tot":"msg"},{"t":"set","p":"nodegroup","pt":"msg","to":"\"Powerwall-\" & msg.parts.key","tot":"jsondata"}],"action":"","property":"","from":"","to":"","reg":false,"x":484,"y":215,"wires":[["6609eda3.fe66ac"]]},{"id":"2aa0a68.a63aeda","type":"http request","z":"6f4bec9.6832c94","name":"aggregates","method":"GET","ret":"obj","url":"https://192.168.1.220/api/meters/aggregates","tls":"2ef5995c.70f58e","x":278,"y":88,"wires":[["a79716f8.3613c8"]]},{"id":"5a5dc131.1728d","type":"inject","z":"6f4bec9.6832c94","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":105,"y":42,"wires":[["2aa0a68.a63aeda"]]},{"id":"6609eda3.fe66ac","type":"debug","z":"6f4bec9.6832c94","name":"","active":true,"console":"false","complete":"true","x":497.5,"y":306,"wires":[]},{"id":"2ef5995c.70f58e","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"./data/powerwall.pem","verifyservercert":false}]

In the HTTP request node, what format for the return?

image

If JSON, you are then converting it to a string with the JSON node! Doh!

Leave it as JSON and take out the JSON node (or change to UTF-8).