Powerwall battery - measuring flow in and out

I had a Tesla Powerwall 2 installed yesterday, to complement my solar PV panels & EV car - all rather exciting. The Powerwall can store ~13.5kWh usable, with a max charge rate & max discharge rate of ~5.5kW. Unlike the solar panels I’m not sure it will ever be financially worthwhile, but it’ll be both interesting and fun to experiment.

I would like to be able to measure the amount of power that goes in to the battery separately from the amount that comes out - not just a net figure. Is this possible with a single CT sensor and if so what feed processes should I use?

If it is not possible, perhaps I could put one CT on the L wire and only allow it to measure flow in one direction, and another CT on the N wire & only allow it to measure flow in the other direction. But again, what would be the best processes to use?

Using 2 CTs would be second best as it would require a new emonTx, c/w ESP8266 etc etc.


Unless you have an earth fault, the current in the line and neutral (both are classed as “live” wires) is the same but, at any instant, flowing in opposite directions. So you will, or should in a proper installation, measure the same current in each.

If you’re talking about emonCMS, you do of course have the processes “Allow positive”, “Reset to zero”, “+ input” and “Allow negative”. Used in that order on the current/power input, you’re almost there. First “Allow positive” lets through only the positive power, you can then accumulate that to energy if you wish, and “Log to feed”, then “Reset to zero” to wipe the slate clean, retrieve the starting value with “+ input”, and do the same but with “Allow negative” to block the positive values you’ve already dealt with and allow only the negative values for accumulating & logging, etc.

If you want both charging and discharging to be positive numbers, either do “- input” and then “Allow positive” again, or do “×” with -1 as the operator after you’ve done the “Allow negative”.

All this pre-supposes you have the a.c. adapter input and you know the direction of power flow.

Many thanks indeed @Robert.Wall - extremely helpful. I think I have done as you described, but when I come to Save the processes I get an error message :persevere:

I’m afraid I can’t help - it saves for me (but then I’m using an old emonCMS).

Is it one particular process line that is causing the problem? You will need to gradually reduce the list to see if it is. Could be a bug (@TrystanLea).

Oops, no - it was my bad; clicking twice on Save creates an error, and I hadn’t realised I had done it. But all is now good.

But this brings me on to … "Is there a way of knowing how much energy is stored in a battery at any one time? Either in kWh or % "? The Tesla app gives a %age, but I’m not aware of any method of retrieving this info & inserting it in too emonCMS.

Similar setup here, just logging at the moment before developing further into some automation.

Julian / @haffle - you may well be way ahead of me but the Powerwall 2 local api allows certain data to be accessed - SOC is one of those that doesn’t require any authentication. try;

http://{your PW2 ip add} /api/system_status/soe

Shouldn’t need a JSON decoder, its a simple response on the lines of;


I’m assuming this, and other data accessible via the PW2 api could be captured into emoncms via a new device template, but i haven’t got around to doing that yet. if/when i do, i will share!

Hi Chris / @burble61 - thanks for that - perfect. Does your “teg-” SSID still broadcast on your wifi? My Powerwall last connected to my router ~10 days ago, and I can no longer see it; strange, as it reports through to the iOS app fine.

@haffle - just checked & yes its still broadcasting. Although its also provided with a wired connection as our property has loads of metal (vs timber) strut work - which has caused issues elsewhere.

The installers said the PW2 (actually the comms unit in the backup box) has no problem working with wifi & hardwired LAN both active - although if it did have, stopping it and restarting it usually had the desired effect (and you could also go into the wizard at its IP address & reset thing from there). Not had a need to yet.

Way off topic, but had my first experience of Tesla support after the PW2 didnt seem to switch from “Self Consumption” to “Advanced Time Based Control” as set via the app. Not quite the premium service I was anticipating!

Hi Chris / @burble61; what I can’t understand is that even when standing next to both the PW2 and the Gateway, no “TEG” type wifi is being broadcast, so I don’t know how I can even access it to re-run the wizard. But the equipment must be connected to the www somehow as I can see the % full and power flows within the Tesla app - both on the LAN or via 3G.

I have set mine to Time Based Control, but TBH I have yet to understand how it decides to charge up during off peak times (even though I have entered the details); it is a bit of a law unto itself (in typical Mr Musk fashion!).

I believe it has GSM built in and drops back to that if no local connectivity available.

Am I right in assuming you don’t have a (wired) LAN connection to it?

Yes i’m having the same issues. Its AI in Time Based Control might be great for predictable loads/weather situations but in the UK its a little less effective!

1 Like

apologies forgot to add feel free to PM me @haffle to save us hijacking this thread!

1 Like

… the Powerwall 2 local api allows certain data to be accessed - SOC is one of those that doesn’t require any authentication. try;
http://{your PW2 ip add} /api/system_status/soe
Shouldn’t need a JSON decoder, its a simple response on the lines of;

I can now access my Tesla Powerwall2 SoC via a local url - see screenshot below. Does anyone know how I can integrate this “response” in to emonCMS / &/or a guide for how to do it? Ideally I’d like to a) show (near) instant state of charge, and b) be able to record the data so that I can graph it over time.

FWIW, I have no idea how I might use JSON (if it is required). :dizzy_face:


The response is indeed in JSON format.
But… this sounds like it’s a candidate for NodeRed.
Brian should be able to shed some light on this one.


I was looking at two possible approaches @haffle - one, as suggested by @Bill.Thomson, is the NodeRed one, and that will be the ultimate goal as I integrate more automation. Short term, was looking at establishing a chron task to get the information you show via a curl request, then publish it to MQTT with the emon base topic - documentation advises that the emoncms mqtt input subscribes to this and posts any data to “Emoncms Inputs” with codename & keynote taken from the mqtt topic and sub-topic.

Looking to test in in the next few days, will post on how i get on.

I’d be inclined to use Node-Red to issue the API call then pass it on either by MQTT or by using the emoncms NR Node.

It is the simplest way.

If I did it in a script, I’d be inclined to use the Emoncms HTTP API rather than MQTT.

Well it will show you what it is ‘now’ every time you sample it. In reality EmonCMS works well at the 10s sample rate but will go quicker. I’d suggest the value will not change that quickly.

1 Like

@borpin thanks for those steers : I hadn’t considered Emoncms HTTP API - still on a learning curve on re the full extent of OEM capabilities as i’m sure you have realised.

Will of course share developments…

Hi, I’ve been away but would now like to sort out the monitoring of my new Powerwall - and I would appreciate some assistance re: Inputs and Feeds.

This diagram shows the layout of the mains wiring, and also the location of the four CTs attached to an emonTx (c/w ESP wifi widget). The “Gateway” is the control box that automatically diverts power to/from the Powerwall as required.

For H1, H2 & H4 I have Log to Feed and Power to kWh

For H3 I would like to be able to record kWh going IN to the Powerwall as well as recording kWh going OUT of the Powerwall - and thereafter combine the net result with H1, H2, H3 & H4 to give an overall Log to Feed and Power to kWh

But what would be the best processes to use for measuring & recording kWh IN and OUT of the Powerwall. This is what I currently have … but it doesn’t seem to be working…

Many thanks, Julian
PS I am happy to accept the slight inaccuracy of assuming that H1 + H2 + H3 + H4 is the same as my total import figure.

The only comment I’ve got, arising from timing considerations, is you replace the “+input” with a “+feed” - the feed you’d need to use being the nett power, logged before the first “allow positive”.

Thanks @Robert.Wall; just to confirm / clarify, that I should replace the +input H3-Powerwall (which is the data from CT H3 before anything is done to it) with +feed H3-Powerwall? I will give that a try, albeit not entirely sure what this will do :grinning:

With the processes shown below, I think that I am recording
a) the amount of kW going IN to the Powerwall (H3-Powerwall_pos_kWh), then recording
b) the NET flow in/out of the Powerwall (I should probably add a H4-Powerwall_kWh here), then recording
c) NET less OUT (H3-Powerwall_neg_kWh)

(JAAMOI, what is the difference between an input and a feed in this scenario?)