Forums

Rest Interface for Powerwall 2 Energy Gateway

Rest Interface for Powerwall 2 Energy Gateway

Hi,

I had a Powerwall 2 with backup installed about 2 weeks ago and the performance is better than expected - many thanks for such a well engineered product (it was well worth the extended 7 month delay :-))

The Energy Gateway has been set to a static IP address on a wired LAN connected network in my home. The basic graphic display provided by a browser to the gateway shows minimal data on the graphic. I'd like to collect historical performance data to enable me to analyse performance characteristics over time so my question is:

Does the Energy Gateway have a RESTful interface which I can use to gather internal data relating to performance statistics?

If not, is there another way I can collect this information for long term storage and analysis?

With my SolarBridge Micro-Inverter Solar panels, at the time, the Company advised a RESTful interface was scheduled for future firmware releases but in Nov-2014, SolarBridge was bought out by SunPower and this interface was never provided. None-the-less, I have cobbled some programming code together that allows me to extract the data available via the SolarBridge Power Manager Web Interface and this suits my needs so I'm wondering if Powerwall 2 does not have (or will not get) a RESTful interface, is there a way I can gather this data?

Thanks in advance,

Harry E.
harrye@kroola.net

zubinanary | September 22, 2017

I don't think you can download data from the gateway itself. The data is fed from the Tesla NOC to the Tesla app. I'm curious if they have similar APIs like the vehicles but just for the Powerwall so you can download the data from their NOC.

The only reason why I think there's no interface on the gateway. I accidentally powered off my entire wifi network at home for a few hours, and only realized it when Tesla app could not connect to my Powerwall. When I brought up my wifi network again, everything was find, but the Tesla app has no data for the duration of the wifi outage...

harrye | September 23, 2017

Thanks, this is also why I'd like to be able to get data directly from the Energy Gateway device.

:-)

sashton | September 23, 2017

Yes these are the addresses I use:-

Tesla Gateway - http://"Gateway address"/api/meters/aggregates
Vera - http://"Vera Address"/data_request?id=sdata&output=json
Fronius - http://"Fronius address"/solar_api/v1/GetPowerFlowRealtimeData.fcgi

I am no programmer so I use a low power PC running Windows 10 and script the collection using Powershell and store the data in a round robin database - RRDtool. I then use the tool to create regular graphs.
Examples here for power from the PV/storage, Solar thermal (Consolar - no REST so had to hack their Serial interface) , Vera for temperatures and Nest data, weather from public services via another REST call, river levels and flood predictions from the UK environment agency (REST again).
I'm an amateur with spare time on my hands and sure that a more competent programmer could produce a more resilient and polished result. I can provide the PS scripts as a starter templates if required.
https://www.bowmill.net
Realtime data using SteelSeries gauges here https://www.bowmill.net/rad3.htm ... not happy with the animation so far but is a work in progress.

sashton | September 23, 2017

NB If you do browse to my website you may find it VERY slow to respond. On a good day ADSL uploads are <1Mb and I am currently backing up all my pics to a cloud service. The initial backup will take most of the bandwidth and will run for at least another week.

harrye | September 23, 2017

Sashton,

You are a star! For a non-programmer your work is exceptional; perhaps you think the underlying code is a little messy :0:-) but the presentation is first class!!

This is exactly what I was looking for in the absence of a clearly defined set of API's. Reviewing your dashboard displays it seems you have already decoded the various parameter/value pairs. Would you mind sharing?

Alas, I had a typo in my original e-mail address it should be "harrye@karoola.net".

I too am using a low-power CPU (a Raspberry Pi 3 Model B in fact because it includes Bluetooth and WiFi all on-board so all I need is to provide it with power and it can then be used as both data collector and controller using an attached 433 MHz transmitted to control compatible device relay modules).

Currently, I send my SolarBridge Micro-Inverter data to http://pvoutput.org; The data is collected accumulated and provides nice summaries (https://pvoutput.org/list.jsp?userid=35050). I can use this data cross-referenced with the Energy Gateway to provide data as to best-use so I can optimise my independence from the grid.

Many thanks for the pointer and quick response - very much appreciated!!!

Kind regards,

Harry E.
harrye@karoola.net

sashton | September 24, 2017

@Harry Sent a copy of the PS script and a few comments. Do mail me if it doesn't arrive sashton@gmail.com
The JSON format and names they use a pretty self-explanatory and will probably make more sense to you than my script! I just downloaded the JSON file once and popped it into one of the many public JSON formatters on the web to make it easier to read. I use RRDtool https://oss.oetiker.ch/rrdtool because I can just regularly throw data at it and not care about aggregation or space management - it's ideal for this sort of thing.

gbuchan | October 4, 2017

@sashton hi - great work - I to am no programmer - Could you also send me a copy of your PS scripts?, I am trying to achieve something similar in terms of approximate State of Charge, also working on plotting diverted spare solar via Immersun units to immersion heaters. buchan.gjb@gmail.com

sashton | October 5, 2017

@gbuchan I have some spare time at the weekend so I'll knock up one that retrieves the basic info and paste it under this topic.

I went to the UK Solar and Storage trade fair at the NEC yesterday (no sign of Tesla but all the other major battery and inverter mfrs. were there) and there was a stand promoting smart car chargers similar to the Mennekes Amtron EVSE, but a lot cheaper - and on the back wall I saw this:- http://myenergi.uk/product/eddi/ , which I think is a newer version of the Immersun and they were planning a programmable interface to it later this year
... may be worth a look.

sashton | October 6, 2017

I prepared a complete set of instructions for setting up PS, reading the data, examples of creating a simple RRD database and creating a graph from it.
Sadly the forums spam filter triggered when I came to post it all :(

mbird | October 8, 2017

@sashton it sounds as if you are doing a great service by discovering and decoding the data. A pity that Tesla do not provide the tools. I do hope you are able to find a way of sharing the information with us!

mbird | October 8, 2017

The MyEnergi team (formerly developed Immersun) have developed the EDDI (for using spare PV output to immersion heater) and the Zappi (EV Charge point). They can communicate and decide which device should take priority. Overall there needs to be an industry standard for this, is it going to be EEBus?

Has anyone heard when the Powerwall2 will get the ability to charge from off peak grid power? I heard that an update in Jan will provide this...

harrye | October 9, 2017

Thanks to "sashton", here are some useful Energy Gateway URI's to get a basline of what's happening:

ENERGY_Gateway="IP_AddressOfYourGateway";

BATTERY_SOC="http://${ENERGY_GateWay}/api/system_status/soe"; # Battery StateOfEnergy [SoC]

METER_Stats="http://${ENERGY_GateWay}/api/meters/aggregates"; # Gateway Current Sensor Data for 4 Basic States plus Interbattey State?

GATEWAY_State="http://${ENERGY_GateWay}/api/sitemaster"; # Gateway Connection Status and Uptime in Seconds

A starting point to help makes it easier to parse:

bSoC=$(wget -o /dev/null -O - ${BATTERY_SOC} | python -mjson.tool | awk '{if (NF == 2) print $2}');

wget -o /dev/null -O - ${METER_Stats} | python -mjson.tool | \
awk -v bSOC="${bSoC}" '
BEGIN {
RS = "},";
FS = ",";
ORS = "\n";
Format = "Csv";
Header = "true";
}
{}
END {}

Cheers,

Harry E.
===

sashton | October 9, 2017

@harry you're a star! I was going round the houses to calculate an approximate SoC. Far better to ask for it directly from the gw. I'll update my PS script using this and post it here in an hour or so.

sashton | October 9, 2017

A PS version:- (just change the URI to match your GW address)
do{

$Thismin = Get-Date -format HHmm

$tesladata = Invoke-WebRequest -Uri 'http://192.168.0.111/api/meters/aggregates' | ConvertFrom-Json
$socdata = Invoke-WebRequest -Uri 'http://192.168.0.111/api/system_status/soe' | ConvertFrom-Json

$solarpower = $tesladata.solar.instant_power
$batteryload = $tesladata.battery.instant_power
$homeuse = $tesladata.load.instant_power
$griduse = $tesladata.site.instant_power

$soc = $socdata.percentage
$soc = [math]::Round($soc,2)

$batteryload = [math]::Round($batteryload,2)

$ssolarpowerk = $solarpower/1000
$ssolarpowerk = [math]::Round($ssolarpower,2)

$homeusek = $homeuse / 1000
$homeusek = [math]::Round($homeusek,2)

$gridusek = $griduse / 1000
$gridusek = [math]::Round($gridusek,2)

Write-Host ("$Thismin battery $batteryloadk $soc% Solar $ssolarpowerk home $homeusek grid $gridusek ")

Start-Sleep 30
} While ($loop_forever='true')

bj.sheppard | October 11, 2017

@sashton - found a typo in your script - $ssolarpowerk = [math]::Round($ssolarpower,2) should be $ssolarpowerk = [math]::Round($ssolarpowerk,2) with the k missing from the last $ssolarpowerk in the math round function.

sashton | October 12, 2017

Ty BJ. I chopped the script down from a larger one to demonstrate the principle and should have checked it better :)

gnichols | October 14, 2017

@sashton - line missing from script also defining @batteryloadk. But thanks for the terrific guidance here.
Greg

sashton | October 16, 2017

As a continuation to the above I have cobbled together a sample which takes this principle one stage further.
It includes a script which gets the SoC from the gateway, writes the value to a RRD file and an example graph that can be created from the RRD.
http://www.bowmill.net/examples/example.zip

Unpack it to c:\example or change the paths in the script.

createsocrrd.bat will create an rrd db called soc.rrd with one variable socpct
readsoc.ps1 needs to be modified to your GW address and will write the soc value to soc.rrd
and after running the PS for a while ...
graphit.bat will run rrdtool graph and (hopefully) create soc.png – a 4 hr graph of the soc value.

It uses RRDtool https://oss.oetiker.ch/rrdtool/ Full details of parameters can be found on his site.

If this is your first time running PS scripts on your Windows machine you may have to modify the default execution policy - running Powershell ISE as an admin task and entering Set-ExecutionPolicy RemoteSigned should be sufficient but here Google is your friend.

bj.sheppard | October 17, 2017

@sashton, that's fantastic. I had a look at RRD on the weekend, but having never used it, didn't follow through because I thought the learning curve would be too high. You've eliminated it, and given me enough info to have a look at logging some of the other data to look at energy losses within the powerwall (e.g. log energy imported, exported, state of charge, etc. and work out what sort of round trip losses I'm getting.

fk | December 6, 2017

http://${ENERGY_GateWay}//api/meters/aggregates returns a JSON structure. Could you please help me decrypt the object?
site
battery
load
solar
busway
frequency
some are obvious, like load (i.e. the house), solar (i.e. the panels), battery (i.e. the Powerwall 2). But what about "busway", "frequency" and "site"?

Each object has the same structure, could you please explain the meaning of those I marked with a *?
last_communication_time
* instant_power
* instant_reactive_power
* instant_apparent_power
frequency
energy_exported
energy_imported
instant_average_voltage
instant_total_current
* i_a_current
* i_b_current
* i_c_current

I am working on reading from the PowerWall2 in order to turn on/off devices (in an grid-off scenario).

Of course, if there is a document published by Tesla, please let me know the URL.

Thank you!

harrye | December 7, 2017

@fk, from what seem apparent: site = grid. As for busway and frequency I'm "guessing" that "busway" is for multiple PW-2's and potentially "frequency" is also for similar.

Given I have only one PW-2 it's evident I see no data from these but I'd hazard a guess that along with the i_{a,b,c}_current name/values these would be for three phase. So if this is true, the busway and frequency readings may fit into this category as well. I've never seen any data for these in my installation. (I'm still on v1.6.0 of the EG firmware and have been for 3 months since the installation).

The "reactive" and "apparent" readings would be more valid for capacitive loads and I'd also hazard a "guess" these are used as [calculated] average values to derive the "instant_power" - the primary value(s) to consider in typical consumer [like us] calculations.

If you have or are developing and are willing to share any code then I'm happy to help or contribute if I can :-)

Feel free to contact me privately if you like.

HTH,

Cheers,

Harry E.
===

sashton | December 7, 2017

@fk I was about to reply but Harry got in there first!
I too only have one PWII and the frequency and busway sections of the returned data are empty so would probably go with his explanation on that score.
I have a rather softer goal in that I would like to :-
1) Maximise my solar use
2) Shift my loads to a) times when the battery is full and failing that b) to times when cheap rate electricity is available.
3) When the disconnect gateway is available in the UK, to be able to manage the loads when islanded.

So far I switch and measure general loads via Vera and the three inverters I have installed here. I manage the white goods (washer, dryer and dishwasher) loads via the Home Connect API - may only be of use to those with Bosch appliances.

Currently I have a very crude method for managing the car charging load which has resulted in many contactors failing, probably due to me driving them well beyond their expected duty cycle. I have recently bought a Zappi car charger which has some of the functions I need built-in e.g. only charging the car when an export threshold is exceeded. They have promised an API(requiring a hub interface) in the new year which, hopefully, will allow some more granular level of charge control.

I would welcome any suggestions for sharing ideas as I often waste hours trying to get a particular API to work to later discover someone has published instructions but has filed them away in a basement behind a sign saying Beware of the Leopard - apologies to those who have not yet read the Hitchhikers guide.

Happy to set up an alternative forum, with facilities for sharing files, if you and Harry think that will help.

fk | December 7, 2017

@harrye and @shaston thank you, busway and frequency are zero for me, and I also only have one battery.

In my case the Grid is down (and will be until the utility recovers from hurricane Maria) so site should be all zeroes. It is near zero for all variables except energy_exported/energy_imported wth ~300. If either one of you is connected to the grid, do you see values that seem to indicate you are selling or buying power?

The i_{a,b,c}_current is always zero everywhere, so I am wondering what they are used for (if three phases, shouldn't at least i_a_current have something? Perhaps not important.

As for intant_power vs. instant_reactive_power instant_apparent_power I saw the following article: https://www.allaboutcircuits.com/textbook/alternating-current/chpt-11/tr...
Would you agree that from our energy management perspective, "apparent" is what we care about?

That leaves me to figure out the direction of the power flow. Comparing to the Tesla app: battery.instant_apparent_power = 3447... charging. load.instant_apparent_power = 613... yes, but it is taking it from the solar panels, not the battery.

Yes, I will contribute back. My goal is to create (basic and documented) Python code to manage loads based on instant readings from the PowerWall.

fk | December 7, 2017

OK I have Python 3 initial code that works, tested on both Windows and Android (QPython3). Includes:
Grid power, Solar output, House load, Battery (+/- with comments on the state), % battery with est. time to full.
Looking for volunteers to suggest (or better make) enhancements -- please email fk at tadah dot vi

eml2 | December 7, 2017

I have 2 Powerwalls but the readings in busway and frequency are all zeros as well.

fk | December 8, 2017

Are there other APIs available besides those?
http://${ENERGY_GateWay}/api/meters/aggregates
http://${ENERGY_GateWay}/api/system_status/soe
I would be interested in the events/logs -- like when the PW switches off the Solar panels (battery full or too much power coming in in an Off-grid scenario).

harrye | December 8, 2017

@eleung1, Am I correct in that your two powerwalls are in parallel and are providing only single phase power? I speculate the busway and frequency stanzas are for 3 phase and are used by the internal firmware for load balance and phase synchronisation in 3 phase but am happy to hear from someone that actually knows :-)

@fk, I gathered the following URI's by wire sniffing and examining some of the downloaded/running code for v1.6.0 and would like to do same on later versions when I have them as I believe the more recent versions of EG firmware have more features inbuilt.

BatterySOC = "/api/system_status/soe";
MeterAggregates = "/api/meters/aggregates";
CustomerRegistration = "/api/customer/registration";
PowerWalls = "/api/powerwalls";
ConnectionStatus = "/api/sitemaster";
Version = "/api/status";

I don't know of any others that describe your outline and would welcome someone who can find/post them. The items you mention can be calculated/derived. For example, if the grid goes down, the site:instant_average_voltage would be zero.

The battery full and load less than solar results in the site:instant_power value going negative indicating solar energy is being exported to the grid. Same applies to the battery; if it is discharging (positive) and charging (negative).

I have also noted that at times with no sun, the grid/site value fluctuate somewhere between +/- 10 and I'm guessing this aspect is the EG performing internal tests to see what the grid is doing so I intended to allow some variations in code calculations that compensate for these minor values.

What do you mean by "too much coming in"?

Cheers,

Harry E.
===

fk | December 9, 2017

@harry thank you for the other URLs. By "too much coming in" I meant that in an Off Grid situation, if the solar output - house_load > 5 kW, the PowerWall will shut down the solar array. Same thing if the battery is full.
The PowerWall then waits 5 minutes before trying again -- requiring to either add some load or hope a cloud goes by.
So I am still hoping to find some sort of "events" API, so that I could tell when the PowerWall is shutting down the solar.
Thank you for the explanations, the calculations work to figure out if the JSON indicates which direction the battery is working (to the house or receiving from the solar).

daveblackuk | January 19, 2018

Does anyone know if there is an endpoint on the PW2 to start/stop the powerwall (it is available on the U/I in 1.10.2)

I would like to stop my powerwall during off peak rate times (economy 7 here in UK) and when I am charging my EV - so the PW2/PV is then only used to power my house during peak charging periods.

sashton | January 19, 2018

If there is a method for what you require I have not found it yet.
I too am UK based with E7 and have found a simple solution to the problem.
I added a 100A connector block to the feed and spurred off the charger before the Tesla CT so the car charging wasn't seen as a load.
Crude but effective.
Last summer I had excess PV so clipped the CT in
so it saw all the loads but in September I moved it so it no longer saw my wife's charger (it is an old Podpoint with no user control at all). My Charger is a Zappi so it senses export, PWII and E7 circuits going live so is a little better behaved.

daveblackuk | January 21, 2018

Thanks, I probably need to sniff the browser when I issue a shutdown command to PW2 from the UI to see what it calls

We moved the load clamp onto the spur for the house but got very strange readings off the clamp (we have an efergy clamp on that spur so could monitor. However a dedicated spur for the Rolec may be required "ahead of the clap". Di

How are you finding the Zappi, are you using it with a Tesla EV ?

sashton | January 21, 2018

Zappi appears to work well. Only had it for three months now but no problems so far. They promised hardware to allow a managing API but their delivery date appears to be slipping....now where have I heard that before ..hmm.
Chevy Volt and Golf GTE. The Golf is a stopgap until the M3 turns up or any equivalent (2019 Leaf / Bolt etc.) I tried a MS but its just too big. I have difficulty enough getting the Volt into our local charge bays.
I thought of using the button to stop the battery at midnight and start it again at 07:00 but the subsequent message it posted got me worrying that it wasn't meant to be controlled that way.

jackkorber | January 29, 2018

@fk how do you calculate the estimated time to full? Can you share the script?

donleonard1945 | February 2, 2018

I have 2 tesla 2 batteries on self-powered system and my batteries show that they are at 40%, our home is using 0.4KW and our solar panels are producing 0.3KW. Why isn't the home pulling 0.1KW from the batteries? nothing is coming from the batteries it is pulling 0.1KW from the grid instead. Any suggestion as to why it is not pulling from the battariies?

jwood | February 4, 2018

It isn't a local interface, but the App (web) interface works! (Hooked up here: https://forums.tesla.com/forum/forums/mqtt-bridge)

sashton | February 5, 2018

Just a bit wary of passing my credentials to a public broker. I'll pass for the moment.

cwied | February 17, 2018

You can set the operation mode and reserve percentage using the local API used by the wizard if you want. To do it, you need to authenticate using /api/login/Basic and then use the token that's returned as a bearer token in the request.

The endpoint is /api/operation and take JSON post data such as the following: {"backup_reserve_percent": 100, "mode":"self_consumption"}

This just queues the change up. To commit it, do a GET of /api/config/completed.

I just received my Powerwalls and my app hasn't been provisioned yet, so I've just been playing with the local API so far.

cwied | February 17, 2018

One other thing I forgot to mention: it looks like the stop and start buttons from the local web UI just generate a GET to /api/sitemaster/stop and /api/sitemaster/start, respectively. No credentials seem to be needed, so if all you're trying to automate is stopping the powerwall, it seems relatively straightforward. The drawback of course is that a stopped gateway won't do any monitoring.

sashton | February 18, 2018

Thanks for that info CW. I will try it out this week. The lack of monitoring data isn't a problem for me as the Fronius Datamanager duplicates all of the measurements apart from the battery data and that should not change much with the system in a stopped state.

jwood | February 18, 2018

To the folks above, this currently just uses the same web interface that the app itself does.

That said, CW, awesome! I'll happily convert things over - how are you authenticating? An example CURL would be awesome, and I can take it form there :)

Cheers,

jwood | February 18, 2018

Nevermind, found it - however what JSON keys are you putting in the post data? Which username password works for you?

cwied | February 18, 2018

Same as for the wizard. Username appears to be ignored (probably just logged), password is S + serial number of the gateway.

curl -i -X POST \
-d \
'{"username":"", "password":"SXXXXXXXXXXX", "force_sm_off":false}' \
'http://gateway-ip-address/api/login/Basic'

cwied | February 18, 2018

One other note: unlike how I understand the server interface works, using the local API the changes seem to happen right away (after the config/done call).

jwood | February 19, 2018

Works perfectly, thank you! I'll be updating my bridge and such ASAP :)

cwied | February 19, 2018

One other warning: hitting some of the endpoints (even just with a GET) seems to turn off the gateway, so it’s a good idea to send a config/done or start soon after.

karlmitchell | March 9, 2018

I've been using bash scripts with curl and jq to set up some automation. What I find odd is that, when I set the backup_reserve_percent to a number, it always seems to come out very slightly lower on the Tesla app. 65 becomes 63, etc. Any idea why that is?

karlmitchell | March 12, 2018

Also, has anyone figured out a way to check if the Powerwall is working off-grid, due to a powercut? I've been working on automating a system for optimizing TOU schemes, based on bash scripts and systemd timers, but I should probably put in a trap to prevent it from occurring during grid disconnect events.

If anyone's interested, at 6am it goes into backup mode, when peak time starts it goes into self_consumption mode with a 25% reserve, and when peak time ends it goes into self_consumption mode with a more conservative reserve (currently 80%, but I'll try to automate with weather forecasts in the future).

vloschiavo | April 4, 2018

karlmitchell: Yes, You can poll this URL and get the current grid status:
/api/system_status/grid_status

This is the response from the powerwall gateway when the grid is up:
{grid_status:"SystemGridConnected"}

I haven't seen the response when the grid is down, but I simply poll the gateway every 60 seconds and look for a response that is NOT "SystemGridConnected".

Here's a link to the documentation I'm putting together.
https://github.com/vloschiavo/powerwall2

pv135 | April 5, 2018

Thanks I've been looking for this for a very long time.

I get the following when I test
{"grid_status":"SystemGridConnected"} when the grid is up and
{"grid_status":"SystemIslandedActive"} when the grid id down and
{"grid_status":"SystemTransitionToGrid"} when grid is restored but not yet in sync.

pv135 | April 5, 2018

now I can set my reserve with the help from people here does anyone know how to read what the current reserve is?

Pages