Powerwall API help

Can you try the HTTP request and output JSON. It is a format issue I think.

[edit]
It needs to look like that image I posted where the object collapses. An alternative approach might be 2 JSON nodes.

It still looks like an object:

Ok. Try running that output through the JSON node.

[edit]

But a string object. It need to look like this…
image

json node doesn’t make a difference, nor does adding two. Tried with http as utf8 and json.

node-red version I’ve got is 0.15.3 - it’s bundled with my emonpi version.

Ah one of the older EmonPis - we don’t bundle it any more as it caused some issues.

Current version of NR (that I am using) is v1.0.4 - that is bound to be the problem.

Do you have any other machine you could run NR on? Upgrading was a PITA at that time.

I do have a synology nas, which can be coached into running node-red. I’d prefer not to use that.

I’d rather not break/brick my emonpi. I’m guessing you recommend a pi zero?

Unless there’s a way to parse the string for the 4 instant_power values?

I wonder if feeding it through a JSON node after the split will help. Not sure why it will not convert the string to an object, but it is doing the split.

In your split node is there this option?

image

You might be able to do so within a function - bit more complex and I can’t easily help as my source data is different and my NR will act different. I’d perhaps try using JSON within the HTTP Request node, then passing the data through a function and doing a JSON conversion inside that. It might be more successful.

something like

var newmsg = {};

newmsg.payload = JSON.parse(msg.payload);

return newmsg;

might do the trick.

Looking back, the split might actually be working and there may be a part of the returned msg object containing which bit of the message each ‘split’ bit is.

All you need to do then is pass the output from the split through a function node, replace the “Last_communication_time” with “time” and set the msg.nodegroup to the value of the split part.

I’m pretty sure the split is working too, but and the key is being written to a parts set. But I’m not having much luck accessing it!
Screenshot from 2020-04-02 17-58-02

HA!

Having a Boris Grishenko moment.

(Massive HT to @borpin for all the help).

So, by changing the change node - it works! I dropped the Powerwall group and set it to msg instead of string.
Screenshot from 2020-04-02 18-15-55

Flow below:

[{"id":"6f4bec9.6832c94","type":"tab","label":"Flow 2"},{"id":"fbb0563f.73c548","type":"split","z":"6f4bec9.6832c94","name":"","splt":"\\n","x":436,"y":151,"wires":[["a7db7a95.7f59f"]]},{"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":[["fbb0563f.73c548"]]},{"id":"9daec9b2.76ac4","type":"emoncms","z":"6f4bec9.6832c94","name":"emoncms","emonServer":"5243d6fc.b657f","nodegroup":"","datatype":"fulljson","x":813,"y":174,"wires":[]},{"id":"a7db7a95.7f59f","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":"parts.key","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":638,"y":94,"wires":[["9daec9b2.76ac4"]]},{"id":"53d70381.4a29a4","type":"inject","z":"6f4bec9.6832c94","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"x":105,"y":35,"wires":[["2aa0a68.a63aeda"]]},{"id":"2ef5995c.70f58e","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"./data/powerwall.pem","verifyservercert":false},{"id":"5243d6fc.b657f","type":"emoncms-server","z":"","server":"http://192.168.1.161/emoncms","name":"emonpi"}]

Now I can log my use, powerwall and solar without needing to fit CT clips inside my breaker box (thanks installers for hiding all the single core wiring - in their defence I didn’t ask them to leave any out for me).

3 Likes

Hi @miker; I copied & Imported your flow, but having changed the url in the aggregates node to match my network, & adding my emonPi details in the emoncms node I am getting two errors.

In the aggregates node unable_to_verify_leaf_signature
In the emoncms node API Failed RC=200

Are these easily resolved?

TIA

PS Might it be because I told it to use an emoncms “node” of pw2 without actually setting one up?

Because the data sent is not valid - i.e. it includes the error text.

Did you search before asking the question? The answer is often there.

@haffle you may not need to CA cert. I never tested it without, but there is an option to ignore the CA cert, even when the CA cert is enabled.

The powerwall cert is self signed, so it’s not secure at all. Personally I don’t understand why Tesla bothered!

1 Like

Thanks @miker - I managed to get it to work in the end. :+1:

Good stuff!

Hello, to all the Powerwall API Helpers – I would appreciate some help / guidance please.

We have a Powerwall2 so I’ve been attempting to distil the earlier information for my set up which is different on several counts:
a) I’m using a desktop PC running Linux Mint 19.1 Cinnamon 64-bit instead of a Rpi.
b) I’m using emoncms.org instead of a local version.
My objective is to to see the battery state of charge on the dashboard along with the existing power use graphics for the house.

Progress to date (after a lot of reading along with a lot more trial and error): Node-red has been successfully installed via the command line. I’m able to access and use http://127.0.0.1:1880/ and the required emoncms flow nodes have been installed.

My flow initially comprised: ‘timestamp’ Node wired to a ‘http request’ Node which is wired to a ‘debug’ Node. The verify server certificate option associated with the ‘Edit http request node’ (Edit tis-config node) was not ticked and the ‘Return’ was set up as ‘a parsed JASON object’. At this point I feel things are working OK as the debug message provides ‘msg:payload : object’ with the battery charge every 10 seconds.

An ‘emoncms’ Node was added as the next stage and wired to receive data from the ‘http request’ Node. A ping to the emoncms.org server provided its IP address. This was used for setting up the ‘Edit Emoncms-server Node’ along with the Emoncms API key (read).

Whilst the debug message continues to provide the battery charge every 10 seconds another message now appears from ‘node : emoncms’. Changing the ‘Data Type to: ‘Legacy Processing’ / ‘Valid JSON Object’ / ‘Simple JSON’ does not eliminate this error message:
30/06/2020, 16:28:55node: Emoncms
msg : Object
{ topic: “http response”, payload: “<!doctype html>↵↵↵…”, _msgid: “1f11b4ba.72c53b”, statusCode: 200, headers: object … }

N.B. This is the text message which has appeared beneath the emoncms Node: API Failed RC=406

All offers to help will be gratefully received. But, that said, please remember it will be necessary to provide such help, or requests for additional information, in ‘BBC Bite Size Chunks’ due to my inexperience.

TIA Michael

Don’t use the IP address - just use emoncms.org.

JSON object, not the bloke.

So you need to copy the error msg object and paste the whole thing. It should appear in the debug sidebar. If not put a Catch-all node in your flow and connect it to a debug node.

image

Also put a debug note on the flow passing data to the emoncms node to see what you are passing in the payload.

If you mouse over the messages on the right, you will see ‘copy value’.
image

When you paste the values here put 3 backticks (top left of keyboard) on a line before and 3 on a line after.

```
code
```

Thanks for taking the time to help.

Done.

Finger trouble when writing - it is correct in the ‘Return’

{"topic":"http response","payload":"<!doctype html>\n<html>\n<head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Emoncms - emoncms.org input post</title>\n    <link rel=\"shortcut icon\" href=\"http://109.169.55.159/Theme/basic/favicon.png\" />\n    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\">\n    <link rel=\"apple-touch-startup-image\" href=\"http://109.169.55.159/Theme/basic/ios_load.png\">\n    <link rel=\"apple-touch-icon\" href=\"http://109.169.55.159/Theme/basic/logo_normal.png\">\n\n    <link href=\"http://109.169.55.159/Lib/bootstrap/css/bootstrap.min.css\" rel=\"stylesheet\">\n    <link href=\"http://109.169.55.159/Lib/bootstrap/css/bootstrap-responsive.min.css\" rel=\"stylesheet\">\n    <link href=\"http://109.169.55.159/Theme/basic/emoncms-base.css?v=11\" rel=\"stylesheet\">\n    <link href=\"http://109.169.55.159/Theme/basic/emon-blue.css?v=11\" rel=\"...","_msgid":"ed1bf0de.95e75","statusCode":200,"headers":{"cache-control":"no-store","content-type":"application/json","date":"Tue, 30 Jun 2020 20:40:59 GMT","content-length":"32","connection":"close","x-node-red-request-node":"6aa730ac"},"responseUrl":"https://192.168.1.13/api/system_status/soe","redirectList":[],"urlsent":"http:/109.169.55.159/emoncms.org/input/post?fulljson={\"percentage\":49.77711738484398}&node=0&apikey=xxx…….xxx","rc":406,"warning":"ERROR: API Call Failed"}
msg.payload : Object
{ percentage: 49.508243118941486 }

I’m not sure that emoncms.org handles JSON (@TrystanLea).

If you change to legacy processing and make the payload you send to the emoncms node just the number, it might work.

I never tested it with emoncms.org to be honest. I should.

Yes it does, only state of charge figures and no error messages.
Thanks again for your help.

1 Like