Tesla Powerwall 2 Integration

The site_id is a numeric number.

If you run the curl command I posted, it will show you the site’s associated with your account.

I’ll try and work on the code today to let you leave site_id blank.

https://smedley.id.au/tmp/org.openhab.binding.teslapowerwallcontrol-3.3.0-SNAPSHOT.jar is refreshed - it should be possible to leave the Site ID blank now - it works for me at least :wink:

Works for me too :grinning:

I have to find out why the items in (local) teslapowerwall show power in units of kW and the (cloud based) teslapowerwallcontrol show them in W.

1 Like

Woohoo! I think the difference just comes down to my mood when I coded it. I can made the cloud version do kW too.

I’m nearly there with the ability to change the reserve, for some reason, I’m getting:

2022-02-04 19:12:07.518 [DEBUG] [nternal.TeslaPowerwallControlHandler] - Setting reserve to: 12
2022-02-04 19:12:07.520 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - payload = {"backup_reserve_percent":'12'}
2022-02-04 19:12:07.521 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - Calling url: https://owner-api.teslamotors.com/api/1/energy_sites/140608504302/backup
2022-02-04 19:12:07.707 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - response to reserve change = {"error":"invalid JSON: unexpected character (after backup_reserve_percent) at line 1, column 27 [parse.c:769] in '{\"backup_reserve_percent\":'12'}"}

ie my nicely formatted JSON is getting \ added to it and an extra "} and I have no idea why.

Soooo close!

double post ? double answer:
You get back \ and extra leading and trailing {} to make the server return JSON comatible.
Did you try to replace ’ by " in your server request ‘12’ => “12” ?

The Tesla server doesn’t like double quotes - only single quotes…

Actually, it can handle no quotes as well…

so:

        String payload = "{\"backup_reserve_percent\":" + newreserve + "}";

results in:

2022-02-05 07:26:01.342 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - payload = {"backup_reserve_percent":9}
2022-02-05 07:26:01.343 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - Calling url: https://owner-api.teslamotors.com/api/1/energy_sites/140608504xxx/backup
2022-02-05 07:26:01.675 [DEBUG] [rnal.TeslaPowerwallControlWebTargets] - response to reserve change = {"response":{"code":201,"message":"Updated"}}

Seems I just needed a night to sleep on it :slight_smile:

Apologies for any inconvenience, but I’ve renamed the binding to TeslaPowerwallCloud to make it clearer what the differences are to my TeslaPowerwall binding. I may also consider renaming TeslaPowerwall to TeslaPowerwallLocal in the future.

New download link is https://smedley.id.au/tmp/org.openhab.binding.teslapowerwallcloud-3.3.0-SNAPSHOT.jar

I’ll commit this change to my github shortly, and will aim to support toggling Storm Mode, and changing Operating mode before the end of this weekend.

Update:
I got distracted today, and added several mode channels instead of adding support for toggling operating mode and storm mode.

New channels:

  • Site Name
  • Firmware version
  • Grid Services Status (ie is the PW2 participating in a VPP event)
  • Grid Services Power (ie how much power is the PW2 sending/receiving from the VPP event)
  • Storm Mode Status (ie has Tesla activated storm mode)
  • Island Status (Not 100% sure what this one is :P)

Update 2:
I’ve worked out how to (via curl) change Operating Mode and Storm mode, so this should be trivial to support. Will aim to implement this on Sunday.

Update 3:
Looks like Island mode can be used to go off grid - so I’ll need to change it from read-only and work out how to use it.

New jar is working here, too. Units are still W.

1 Like

…is there any example how to integrate/ startup? Using VSC and avoid the OH frontend

I’ll look at changing units to kW in the morning my time.

.jar refreshed - units now in kW

.jar updated again - toggling Storm Watch mode and Changing Operating Mode should be working now.

Still TODO:

  • Work out how to check the expiry date of the supplied token, to allow a rule to remind the user when it’s getting close to expiry
  • Work out how to change island status to allow toggling on/off grid
  • Check return codes of API calls and handle them better
  • Update the README.md to better explain what this does and how to use it
  • ??? not sure but I’m sure there’s other things :slight_smile:

Units now in kW :+1:

1 Like

Thanks for confirming!

Where can i find the token. i do not have an android device but an ios device.

I don’t have an IOS device but I believe ‎Auth app for Tesla on the App Store should do the trick

1 Like

Hello

yes it seemed to work, thank you.
But i had no success with the CURL command you provided.
I left it empty and the thing goes online.

I have to test creating items yet.

I got it working and implemented items for the power as well as the SOC.
The soc does not give a correct value.
Currently the PW is charged 6 % according to the app and the channel returns 0.8382.

how do i interpret this?
i thought 1 = 100 %

That’s strange. The percent-charged channel matches the app here, and has done for the two months since I created the binding. Here it returns the actual percentage - 98 for me right now :slight_smile:

Ok.
It’s currently at 100 %, in reality the pw2 is at 22 % soc. but i recognized the Thing got offline reporting a communication error with the api:

TeslaPowerwallCloudcontroller returned error while invoking https://owner-api.teslamotors.com/api/1/products

i checked the token in the app and it is still the same.
strange …

I do need to try and improve the error reporting. Having said that, the only time I got an offline error report was when my token expired. I did see this (https://forums.whirlpool.net.au/go?https%3A%2F%2Fgithub.com%2Ftimdorr%2Ftesla-api%2Fissues%2F548) yesterday - it’s not clear to me (yet) if this affects the binding. I haven’t figured out how to check how long until the token expires using the Tesla API.

Edit: I’m wondering if the token you generated is one of the new ones that only lasts for 8 hours?