Tesla Powerwall 2 Integration

Tags: #<Tag:0x00007efec80be578>

On my Pi (installing from the openhabian image):
openhabian@openHABianPi:~$ which keytool

openhabian@openHABianPi:~$ ls -l /usr/bin/keytool
lrwxrwxrwx 1 root root 25 Oct 17 2018 /usr/bin/keytool -> /etc/alternatives/keytool

openhabian@openHABianPi:~$ ls -l /etc/alternatives/keytool
lrwxrwxrwx 1 root root 46 Oct 17 2018 /etc/alternatives/keytool -> /usr/lib/jvm/zulu-embedded-8armhf/bin/keytool

Perhaps this helps?

ok, small steps achieved:

  1. keytool is correctly linked

    [13:30:19] openhabian@openhab:~$ ls -l /etc/alternatives/keytool
    lrwxrwxrwx 1 root root 67 Nov 3 11:12 /etc/alternatives/keytool -> /opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/bin/keytool

  2. SSL root certificate downloaded and added (throws an exception as PW2 exist already)

    [13:39:37] root@openhab:~# openssl s_client -showcerts -connect </dev/null 2>/dev/null|openssl x509 -outform PEM >mycertfile.pem
    [13:40:13] root@openhab:~# sudo keytool -import -trustcacerts -keystore /opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/jre/lib/security/cacerts -storepass changeit -alias PW2 -import -file mycertfile.pem
    keytool error: java.lang.Exception: Certificate not imported, alias already exists

  3. complete restart
  4. copied code into a tesla.items, same for tesla.things (w corrected IP) and tesla.rules
  5. copied code into http.cfg (w correct IP)
  6. installed the http-binding

… still no data from the PW :frowning_face:
Any idea?

got it… exec binding was missing :see_no_evil:

Hi All,

For those that would like to test the powerwall binding vs setting up exec, etc - I’ve updated http://smedley.id.au/tmp/org.openhab.binding.teslapowerwall-2.5.0-SNAPSHOT.jar

This now doesn’t need the ‘keytool’ hack to add the certificate of the PW2. It will automatically ‘trust’ hostname powerwall

This means that this hostname will need to resolve to the IP of your PW2.

The easiest way to do this is to edit /etc/hosts and add: powerwall

where obviously, is the IP of your powerwall.

Feedback appreciated.



1 Like

Dear Paul,
thank you for this great work! I copied the jar-File into my openhab “addons” folder and restarted the openhab docker container on my Synology NAS.

Then I got the following entries in “openhab.log”:
2019-11-10 13:49:13.776 [WARN ] [org.apache.felix.fileinstall ] - Error while starting bundle: file:/openhab/addons/org.openhab.binding.teslapowerwall-2.5.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.teslapowerwall [216]
Unresolved requirement: Import-Package: com.google.gson; version="[2.8.0,3.0.0)"

at org.eclipse.osgi.container.Module.start(Module.java:444) ~[?:?]
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[?:?]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [10:org.apache.felix.fileinstall:3.6.4]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [10:org.apache.felix.fileinstall:3.6.4]

I not sure weather this is a bug in the binding or I missed something.

Best regards,

Hi @ManfredS sorry - I keep forgetting about the gson requirement. I guess you’re running OH 2.4 still, not one of the 2.5 snapshots?

You can install gson 2.8 by following the instructions at [SOLVED] Manually Upgrade com.google.gson from 2.7.x to 2.8.x in OH 2.4

Or, I can see if I can figure out how to rebuild the binding targeting OH 2.4



Hi Paul,
thank you for your helpful answer. I installed OH 2.5 milestone 4 and finally after configuring the binding (providing local credentials) in Paper UI it is working! Now testing can begin :slight_smile:

Hi @ManfredS,

That’s great to hear! the local credentials are optional, but required to retrieve the operating mode and current reserve level.

On my todo list is to enable changing the operating mode, and changing the reserve settings. I’ll try get to this soon, and hopefully get the binding in a fit state before the release of 2.5 so it can be included.



Hi all,

this binding is working very well for me. No problems at all in the last six days.
The only thing are 16 entries in openhab.log:

[WARN ] [rwall.internal.TeslaPowerwallHandler] - This binding is read only

Thanks a lot, Paul!


Hi @ManfredS,

This should be a debug message, not a warning - sorry about that. I keep meaning to fix it :confused:

Once I add support for changing the operating mode and reserve level, it will go away once and for all - I just need to find time to do that.

I’d like to try and get the binding finalised before the release of 2.5 in mid-December - but not sure that’s going to be possible - perhaps I should clean up the code with the current functionality; and changing mode and reserve can be added down the track?



seems with 2.5M6 Powerwall binding is not working any longer.
Any ideas?

2019-12-07 11:35:23.402 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Convert JSON to Item Type Number': The name 'PW_InstPower_Site' cannot be resolved to an item or type; line 8, column 5, length 17

solved with reboot

Hey Paul, first off thanks for working on this! I am a relative noob to openhab and have setup a raspberry pi 3 following the most basic instructions. I then installed your binding and set it up using the IP address for my powerwall2 gateway which is in my case. I get “Status: OFFLINE - COMMUNICATION_ERROR Tesla Powerwall returned error while invoking” If I go to this address in chrome it returns “Method Not Allowed” as text. Has something changed? Do you have an updated version of your binding? Appreciate any help otherwise will start from scratch…

Cheers, Shane

Hi Shane,

The binding is working for me. I get the same error if I try and access the URL you gave directly in Chrome.

Have you put valid credentials in for login email and password? Perhaps there’s a glitch if these are left blank? If I get a chance tonight, I’ll do some testing without the login/password and make sure the binding doesn’t report errors with this setup - I probably didn’t test that use case thoroughly.

I also need to find some time to allow changing the operating mode and reserve settings from within the binding.



@shaneprobinson I confirmed your error occurs if the username/password aren’t passed to the powerwall. I’ll try fix this ASAP so that it doesn’t try that command if the username/password are blank

Hey Paul,

Thanks for the quick reply. I tried several options:

1.) no credentials
2.) My installer login details
3.) My customer user details.

None seemed to work… All had the same error. For what I am using this for I don’t need to set the reserve level or change settings. I just want to read the battery SOE and site power for hot water proportional heating control. I already have this implemented in my house with a Loxone home automation controller and a seperate stand alone meter. Loxone however refuses to work with the self signed SSL certificate so can’t talk directly to the powerwall gateway which would be ideal. I’m basically using openhab and a raspberry pi as a gateway. Plus its a great chance to learn another platform.

anyways, your help is greatly appreciated and it seems like if we can ignore that authentication in the binding that would be a good option to have to simplify things. Happy to help anyway I can. I’ve just ordered some python books so I can touch up on that side of things as my history is in embedded C and assembler languages.

Cheers, Shane

Hey Shane,

I’ll try fix the code tonight… I’m using the credentials I use for the Tesla app…



try http://smedley.id.au/tmp/org.openhab.binding.teslapowerwall-2.5.4-SNAPSHOT.jar

yup working sweet now. Thanks paul! Now to learn the rest of Openhab… and python… and linux… sigh. Definitely a lot to learn for a noob! I will get there… step by step.

hahah that’s how I started. As an example of what you can do with rules, here’s the rule I have to notify me if there’s a power outage:

rule "Grid down"
  Item TeslaPowerwall_GridStatus changed
   if(TeslaPowerwall_GridStatus.state == "SystemIslandedActive")
       sendBroadcastNotification("Grid is not connected")
   if(TeslaPowerwall_GridStatus.state == "SystemGridConnected")
       sendBroadcastNotification("Grid power restored")

I keep thinking of things when battery state is 100% a well, but never get around to it :slight_smile: