Tesla Powerwall 2 Integration

Tags: #<Tag:0x00007f74529312c8>

Hi, when running the above i get the option to add to the keystore ok, but when i say ‘Y’ i get the following error:

Certificate was added to keystore
keytool error: java.io.FileNotFoundException: /jre/lib/security/cacerts (No such file or directory)

I then tried the command:

sudo keytool -import -trustcacerts -keystore securit -storepass changeit -alias PW2 -import -file cacert.pem

(ie, removed the path for the ‘securit’ comand)

and that said ‘Certificate added to keystore’ ok

Have restarted openhab, but am still getting the same error in the openhab logs ‘unable to find valid certificate’

I have also tried a direct command as suggested in the GIT Powerwall documentation you suggested above, but i get the error:

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html

However, when i issue the curl command with -k it fetches the data from the Powerwall ok.

I’m not quite there yet! Is there a way to check if the cert has been loaded into the keystore?


Just reran the keystore command and i get:

keytool error: java.lang.Exception: Certificate not imported, alias <PW2> already exists

So it must have loaded into the keystore ok.

I think maybe its because the cert is self signed? And i need to tell my keystore to trust certs issued by Tesla?

It was my $JAVA_HOME

mine needs to be:

it was blank, then I stupidly set it to the oracle one, not knowing i was on zulu jvm !


Great! I had a similar issue when I updated Java and $JAVA_HOME was still pointing to the old java version. Glad it’s ok now.

1 Like

Oh one other thing that might help others…

I hadn’t installed the JSON transformation. Once i did that all the powerwall data is appearing on my sitemap :wink:

Thanks Paul - an excellent implementation, pretty neat I think

Hi @PeteW
Are you using the binding or the manual configuration of http.cfg / items file?



I’m using the manual config of http.cfg and an items file

My Sitemap is pretty basic at the moment, but its working pretty well. I’ve also updated my Grafana charts to use the Powerwall info rather than an EmonPi I was using to monitor the house power.

Not much sun today though ;-(

Now i just need to add a feed from my SolaX inverters, so i can include their perfornace in the mix. Sounds like i need to use http.cfg again - which seems pretty easy - they have similar API calls with JSON returns.

Powerwall gives some great stats itself though - so only need the inverter info if i suspect something is going wrong up on my roof!

I’m not able to import as it keytool command isn’t been found. Any help?

sudo: keytool: command not found

Regards, René

What linux distro are you running?

I’m using the latest stable openhab2 distribution (2.4.0) for Raspberry Pie

Installed using openhabian? or ? keytool is a part of java, so should be installed when you installed java.

This might help:


openhabian@openhab:~$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation)

but even executing the two lines from the link without failure message, still shows:

openhabian@openhab:~$ sudo keytool -import -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias PW2 -import -file mycertfile.pem

sudo: keytool: command not found

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.