Add support for Tesla Powerwall

Does anyone know if when StormWatch mode is enabled, what we set reserve and Operations mode wise doesn’t matter? That it will ignore our settings unless we turn off StormWatch mode. My worry was that StormWatch mode engages, and then when I dynamically set the mode and charge in an auotmation, it would interfere with StormWatch. But from memory I think it doesn’t matter what the other settings are for Op mode or charge level. It will ignore it if a StormWatch is engaged (which is what I want). Other way around this would be in the automation detect if StormWatch is active (if it is do nothing), but I see no way to detect StormWatch mode.

Thanks to all who’ve posted info on getting this working so far!

I’m very new to HA, but working my way through gradually.

I think i’ve got the integration setup, i’ve put the json file in the config root and all appears to be correct, however, i’m getting the below after rebooting HA.

2022-07-25 11:40:04 WARNING (SyncWorker_2) [homeassistant.loader] We found a custom integration tesla_gateway which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2022-07-25 11:40:09 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tesla Gateway for tesla_gateway

AttributeError: module ‘custom_components.tesla_gateway’ has no attribute ‘async_setup_entry’

Does anyone have any ideas on this please?

Thanks you for that I got mine working like a dream.
If some one could help.
I want to set an automation at 10 pm each night to set the reserve value to what ever is left in the battery. So I can use it later the next morning.
Basically the action is what I can’t work out
action:
Set
Tesla Gateway: set_reserve
backup_reserve_percent:
to equal
Get Value of
sensor.powerwall_charge
( be nice to set the value (sensor.powerwall_charge - 5))

I do something similar.

alias: Battery SOC Forecast
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.soc_batt_forecast
condition: []
action:
  - service: tesla_gateway.set_reserve
    data:
      backup_reserve_percent: "{{states('sensor.soc_batt_forecast')|int(0)-5}}"
mode: single
1 Like

Thank you works a charm.
I am going to save every last cent I can of my power bill.

Have a look at EMHASS add-on: An energy management optimization add-on for Home Assistant OS and supervised, it is a bit complex to setup but it takes power optimisation to the next level, including solar, battery and variable buy/sell prices.

Would anyone be willing and able to create this file for me? I’m not a Linux user and find that a bit daunting to be honest, plus I don’ t have a machine to do it on and don’t fancy messing with my RPi 4 as its running my HA server.
From what I understand about the process you would only need my e-mail address for the Tesla Account?
But I would be eternally grateful if anyone can assist, please DM me for details.

P.S. I finally got my PW installed this week after waiting for 12 months for delivery, I have the automations from @BruceH5200 so I’m just short of this file to get the integration to work. Currently after installing the tesla_custom integration and using the SS Token the integration fails to set up. Which I’m hoping is just because of these changes that are required and the file generated in step 4) above…image

I could do it, but to do so, I would need your Tesla email and password, which I’m not sure you would want to give to me.

It looks like this…

{"[email protected]": {"url": "https://auth.tesla.com/", "sso": {"access_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "refresh_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "id_token": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "expires_in": 28800, "token_type": "Bearer", "expires_at": 1664517664.5438943}}}

If you can find something to generate your keys, you could insert them into that file.

Maybe you could run the code from a command line within your home assistant instance ?

Hi Bruce,

OK I can try that, what is the line that I enter? I tried just “python3 -m pip install teslapy” and “sudo python3 -m pip install teslapy” but both are bad commands:
image

if you could help me with the required commands then I will try to do via the HA consul. Does this file have to be regenerated every time the Tesla Token expires? If so then I really do need to know how to do it for myself.

I have removed that post for the other Rpi as it may be easier as Bruce had said to run the terminal commands on my HA machine where all the other information and files are available. However I cant run any commands as ‘sudo’ is not available. I tried to research this but when people asked the same question, “How to run terminal commands in HA” they never seemed to get the actual answer from anyone.

Is it anything to do with my type of installation and is there any work around that if it is?

image

I’ve tried setting this up - followed all the commands, it looks like it’s working however a get a battery is none in the logs (see image)

Any ideas?

I can’t fully remember what I did but I did this all from a Microsoft Windows computer. You can download TeslaPly and Python3 from the internet. You will also need to update manifest.json with the version of TeslaPly you download. I will be setting up HA for my father-in-law in the next couple of months so if no one else has done it then I will document and post the whole process down once I have worked it all out again.

Is this error coming up when you try and run an automation you created?

Ive set this up on multiple locations to try and get it to work (including Windows etc)

This happens when i call the service - says the call is successful - however this is what i get int he log - no matter what i call - i get an error which suggests i dont have a PowerWall Battery.

I would first check the configuration of the action in your automation.

As an example my Set to 50% Powerwall Reserve automation is configured to call a service. Configuration of the example action is below.

Service
Tesla Gateway: set_operation

Service Data
service: tesla_gateway.set_operation
data: null
real_mode: self_consumption
backup_reserve_percent: 50

Yeah ive tried these - but still getting the same - shows as sucessfull but then the logs say otherwise?


I am sure I remember having similar issues. Try using this configuration.

action:
  - service: tesla_gateway.set_operation
    data:
      service: tesla_gateway.set_operation
      data: null
      real_mode: self_consumption
      backup_reserve_percent: 50

Ive just given that another go - shows as successfull - but again when i check the logs - i get the same error “Battery object is None”

I just cant seem to get to the bottom of it.

Did you want to drop your init.py manifest.json and services.yaml config in here and I can check against mine to see if there are any differences?