-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
105 lines (81 loc) · 3.94 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
So you want your Powerall to charge to 100% or thereabouts during your
off-peak period, or you want to stop your Tesla car charging at the end
of your off-peak period rather than guessing where to set the percentage
slider in the app?
If so, this Python 3 script is for you.
First install TeslaPy (https://github.com/tdorssers/TeslaPy).
$ pip install teslapy
Edit charge-tesla.json to add your details:
{
"email": "your-tesla-email-here",
"enabled_Dory": true,
"enabled_Tatsu": true,
"home_lat": 0,
"home_lon": 0,
"enabled_powerwall": true,
"off_backup_reserve_percent": "15",
"on_backup_reserve_percent": "100"
}
"email": "your-tesla-email-here",
This is your email address, as used for your Tesla account.
"enabled_Dory": true,
"enabled_Tatsu": true,
This controls which of your Tesla cars need to have their charge
stopped. The format is "enabled_<car-name>". If set to true, the
script will tell the car to stop charging, but only if the car is
reported as being near its home location. Multiple cars are
supported; add a line for each.
"home_lat": 0,
"home_lon": 0,
Specify the car's home location in latitude/longitude. The script
will not attempt to stop charging if the car is far from this
postition. Note: the script uses a very rough and ready method
to determine if the car is "home". Some more work is needed here.
"enabled_powerwall": true,
If you have a Powerwall, this enables the script to control the
standby reserve percentage. This is useful if you know tomorrow's
power requirements are unlikely to be predicted correctly by
Tesla's "AI". Set "enabled_powerwall" to true to enable this
functionality.
"off_backup_reserve_percent": "15",
Set the standby reserve percentage. "off_backup_reserve_percent" is
your normal resting standby reserve; used to set the standby
reserve at the end of your off-peak period. Note: value must be
a string.
This is the percentage to set at the start of your off-peak period.
"on_backup_reserve_percent": "100"
Once you've customised the above config file, copy it here:
/usr/local/etc/tesla_api/charge-tesla.json
You will need to provide the Tesla SSO refresh token the first time you
run the script (or whenever Tesla de-auths your token, such as if you
change your Tesla password).
$ ./charge-tesla.py status
Not authorised
Enter SSO refresh token:
I recommend using https://tesla-info.com/tesla-token.php to generate a
refresh token securely. Paste the entire refresh token at the above prompt
and hit return. The token is cached in /usr/loca/etc/tesla_api so this is
usually a one-time thing. You should now see a list of your Tesla products
and their current status.
Copy charge-tesla.py and charge-tesla.sh to /usr/local/sbin/charge-tesla.py.
The shell script arranges for logging to be written to /tmp/charge-tesla.log.
This can be useful to debug failures.
Assuming you have a Linux/MacOS/BSD server running 24/7, arrange for the
script to run via cron(8):
$ crontab -e
If you're using the Octopus Go tariff in the UK, where you have a 4-hour
off-peak period between 0:30am and 4:30am, add the following lines to
the crontab.
#minute hour mday month wday command
# Set the standby reserve to force Powerwall to charge from off-peak
31 0 * * * /usr/local/sbin/charge-tesla.sh on
35 0 * * * /usr/local/sbin/charge-tesla.sh on
40 0 * * * /usr/local/sbin/charge-tesla.sh on
45 0 * * * /usr/local/sbin/charge-tesla.sh on
# Reserve off.
25 4 * * * /usr/local/sbin/charge-tesla.sh off
30 4 * * * /usr/local/sbin/charge-tesla.sh off
35 4 * * * /usr/local/sbin/charge-tesla.sh off
40 4 * * * /usr/local/sbin/charge-tesla.sh off
Note: The script is invoked four times at 5 minute intervals in case of API
failure or network connectivity issues.