Tesla Powerwall 2 Integration

Tonight my PW software was upgraded to 20.49.
Still not working with installeraccess.

As I wrote, you need a local customer account on the powerwall…

That helped! Works like a charm!
Up to now there was no local customer account on my powerwall.
At
https://www.tesla.com/de_de/support/energy/powerwall/own/monitoring-from-home-network
I found a description to add a local customer account. If your Powerwall is already in your local network (in my case 192.168.178.80) you can access it directly without signing in to the Wifi of your Powerwall.

1 Like

Operationg mode is actually set to self_consumption. This is the only mode I can see in the Android app up to now. Do you think it might be possible to switch this to another mode?
What sort of modes are availalble?

In Germany the solar power you are allowed to export to the grid is restricted to 70% of your maximum solar power. On good days my PW at noon is charged 100%, so I cannot sell 30% of my produced afterwards. It would be nice if I could time-restrict the charging power to charge only at certain times (when xolar power exceeds 70% of the kWp) or to restrict the charging power to overcome this deficiency.

I have plans to investigate changing modes - and reserve levels - I just need some free time.

The API (based on an older firmware) is at GitHub - vloschiavo/powerwall2: Tesla Powerwall 2 - Local Gateway API documentation

The available modes are:

  1. self_consumption
  2. backup
  3. autonomous (aka Time of Use (TOU) as reported by dlieu on the teslamotorsclub.com forums)
  4. scheduler aka Aggregation - This seems like it is not supported now.

ok… so with a ‘customer’ account, trying to change the reserve setting results in:
{“code”:403,“error”:“Unable to POST to resource”,“message”:“User does not have adequate access rights”}

Seems an ‘installer’ account would be required in order to change mode/reserver

Is this compatible with OH 2.4?

Hi,

Up to now I have used the curl and manual items method to poll my powerwall. Since 18th of Feb, an authentication is required even for local access. So I want to change to your binding. I am on 3.1m1. Any chance you will upload a version for it? 3.0.2 does not seem to be installable in 3.1m1.

Thanks
Lars

Ps: a local pw customer account is sufficient. I had to change the module for my Magic Mirror too…

Hi - the current build seems to work here with 3.1-M1 on one of my installs.

I’ll try build a 3.1 version in the next few days.
Cheers,

Paul

Sorry - no - and I don’t have any plans to backport it…

1 Like

On my OH i solved the issue of the authentication (after powerwall2 firmware version 20.49.0) this way:

thing

Thing exec:command:pw_aggregates [command=“/etc/custom_scripts/pw2_get_meters_aggregates.sh”, interval=5, timeout=5]
Thing exec:command:pw_soe [command=“/etc/custom_scripts/pw2_get_soe.sh”, interval=15, timeout=5]

items

String PWSoe_JSON “[%s]” {channel=“exec:command:pw_soe:output”}
Number PW_StateofCharge “State of Charge [%.1f %%]” (gPowerwall, gInfluxDefault)

String PWAggregates_JSON “[%s]” {channel=“exec:command:pw_aggregates:output”}
Number PW_InstPower_Site “InstPower Site [%.1f W]” (gPowerwall, gInfluxDefault)
Number PW_InstPower_Battery “InstPower Battery [%.1f W]” (gPowerwall, gInfluxDefault)
Number PW_InstPower_Load “InstPower Load [%.1f W]” (gPowerwall, gInfluxDefault)
Number PW_InstPower_Solar “InstPower Solar [%.1f W]” (gPowerwall, gInfluxDefault)

exec.whitelist

curl https://teg/api/meters/aggregates -k
curl https://teg/api/system_status/soe -k
/etc/custom_scripts/pw2_login.sh
/etc/custom_scripts/pw2_get_soe.sh
/etc/custom_scripts/pw2_get_meters_aggregates.sh

rules

rule “Convert JSON to Item Type Number”
when
Item PWSoe_JSON changed
then
PW_StateofCharge.postUpdate( transform(“JSONPATH”, “$.percentage”, PWSoe_JSON.state.toString) )
end

rule “Convert JSON to Item Type Number”
when
Item PWAggregates_JSON changed
then
PW_InstPower_Site.postUpdate( transform(“JSONPATH”, “$.site.instant_power”, PWAggregates_JSON.state.toString) )
PW_InstPower_Battery.postUpdate( transform(“JSONPATH”, “$.battery.instant_power”, PWAggregates_JSON.state.toString) )
PW_InstPower_Load.postUpdate( transform(“JSONPATH”, “$.load.instant_power”, PWAggregates_JSON.state.toString) )
PW_InstPower_Solar.postUpdate( transform(“JSONPATH”, “$.solar.instant_power”, PWAggregates_JSON.state.toString) )
end

rule “Powerwall2 Login”
when
Time cron “0 0/50 * * * ?”
then
executeCommandLine(“/etc/custom_scripts/pw2_login.sh”)
end

And last my custom scripts:

/etc/custom_scripts/pw2_login.sh

#!/bin/bash

curl --cookie-jar /etc/custom_scripts/pw2cookies.txt -H “Content-Type: application/json” -d ‘{“username”:“customer”,“password”:“XXXXX”,“email”:“XXXXX”,“force_sm_off”:false}’ -k https://teg/api/login/Basic >/dev/null0

Where:
password: last 5 characters of the serial of you PW2 (visible from Tesla APP)
email: the one used on the Tesla APP

/etc/custom_scripts/pw2_get_soe.sh

#!/bin/bash

curl -b /etc/custom_scripts/pw2cookies.txt -k https://teg/api/system_status/soe

/etc/custom_scripts/pw2_get_meters_aggregates.sh

#!/bin/bash

curl -b /share/CACHEDEV1_DATA/.custom_scripts/pw2cookies.txt -k https://teg/api/meters/aggregates

This way every 50 minutes i ask a new login cookie to the Powerwall2 and I save it for further requests (soe and aggregates), then parse all the information received and I also save them in a influxDB for later use with Grafana

Here some items used in the sitemap:

Hope this can help!
Simone

2 Likes

As I’M still on OH2.5.x I applied same solution as Simone but using the script provided by [Vince Loschiavo] powerwall2/powerwallstats.sh at master · vloschiavo/powerwall2 · GitHub. The script takes care of the cookie update once it’s invalid. I’m using a local customer account on my powerwall.

Works perfect.

1 Like

I upgraded OH to 3.1.0.M3
TeslaPowerwall did not initialize.
I renamed the old jar in /usr/share/openhab/addons/
org.openhab.binding.teslapowerwall-3.0.2-SNAPSHOT
to
org.openhab.binding.teslapowerwall-3.1.0-SNAPSHOT
and it works.

Hi Christian,

I can’t reproduce this - I’m also running 3.1.0.M3 and haven’t had to rename the binding…

Cheers,

Paul

hi @Paul_Smedley , could you pls link the last version of your .jar for Tesla Powerwall2?
thanks

https://smedley.id.au/tmp/org.openhab.binding.teslapowerwall-3.0.2-SNAPSHOT.jar is still the latest…

Many thanks, I’m using its and it is a good job !!

Hi, I would like to add Thing for Tesla battery via configuration files, while I’m doing q new fresh installation with all thing and items only on files…sorry but I don’t undertsant the rith syntax for decalre a powerwall thing, I thing it could be something like this :
Thing teslapowerwall:teslapowerwall:Tesla_Powerwall “Tesla Powerwall 2” [hostname=“192…”]
Could you explane me syntax for thing and items ??
Thanks

I am using openHAB 3.1.0.M3 and copied the file into
/usr/share/openhab/addons
Afterward I could add the powerwall as item in the UI reachable under IP:8080 at
Einstellungen - things.

I just download the binding but I get the following error

[org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.teslapowerwall-3.0.2-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.teslapowerwall [319]

I am on openHAB 3.1.0 Build #2397

any help?

Regards
Lorenzo