Community
OpenEnergyMonitor

Community

Powerwall API help

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).

Ha! Amazing! Yes I’ve switched to utf-8 string and we’re now cooking!

Many many thanks for your help!

I think if you switch it back to JSON and bypass the JSON node it should work (and be cleaner).

no Bother.

1 Like

However, in the emoncms list I don’t have any of the group headings (site/solar/etc.), so it’s going to be hard figuring out which input is what…

Hmm. First inject I ran sent all four json groups to emoncms, but now I’m only getting one of them. I need to do some (paid) work now, but I’ll have another look later.

I’d leave it as UTF and the JSON node in then. You know that works.

1 Like

The split node outputs 4 separate chunks of json, which the change node happily handles. But, only one of these is being sent to emoncms.

One likely sticking point is that the labels (site, solar) are stripped from the json. I presume that means emoncms thinks it’s getting 4 pulses of the same data? The json labels are lost through the split node.

Here’s my flow (reasonably sure without api key):

[{"id":"6f4bec9.6832c94","type":"tab","label":"Flow 2"},{"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":503,"y":247,"wires":[["9daec9b2.76ac4"]]},{"id":"2aa0a68.a63aeda","type":"http request","z":"6f4bec9.6832c94","name":"aggregates","method":"GET","ret":"txt","url":"https://192.168.1.220/api/meters/aggregates","tls":"2ef5995c.70f58e","x":278,"y":88,"wires":[["d932ec4b.4c18f"]]},{"id":"9daec9b2.76ac4","type":"emoncms","z":"6f4bec9.6832c94","name":"emoncms","emonServer":"5243d6fc.b657f","nodegroup":"","datatype":"fulljson","x":689,"y":170,"wires":[]},{"id":"d932ec4b.4c18f","type":"json","z":"6f4bec9.6832c94","name":"","x":261.5,"y":224,"wires":[["fbb0563f.73c548"]]},{"id":"87b0265e.c74658","type":"inject","z":"6f4bec9.6832c94","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":112.5,"y":149,"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"}]

You need to connect a debug node out of the change node. On running, you should see an output for each section with a msg.nodegroup set to Powerwall-<section name>

You can see this being set in the change node
image

"Powerwall-" & msg.parts.key

A debug node on the split function, will confirm that the `msg.parts.key’ element exists in the msg object.

Sometimes the best option is indeed, if it works, dont “fix” it :wink:

1 Like

@Bill.Thomson - a bit late for that… For some reason since removing the json node and adding it back in again something has broken. If only node-red had version control baked in… I’m not used to a lack of safety net!

Looking at the output from the split node (or change node), it seems I’m losing the msg.parts.key, as nothing is labelled:


However the labels are there in the json output:

You need to change this to whole message object (edit the node)

image

so it looks like this

image

[edit]
I wonder if the data format (not the JSON structure) from the actual powerwall is the problem. I see the data being shown as an object rather than a string.

image

Can you stick a debug on the output from the HTTP request node as well please.

Here’s the output from the split. The message key is attached near the end.


Here’s the output from the http request (node should output to utf8):

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.