- 📫 How to reach me:
- 😄 Pronouns: he/him
bogosj / tesla Goto Github PK
View Code? Open in Web Editor NEWThis project forked from jsgoecke/tesla
Provides a wrapper around the API to easily query and command a Telsa car.
License: Other
This project forked from jsgoecke/tesla
Provides a wrapper around the API to easily query and command a Telsa car.
License: Other
Hi, as the unofficial Tesla API commands are being deprecated, is there any chance to create a code based on Tessie API. They as a company are allowed to use the official Tesla API and provide for their costumers an API of their one, which is quite good as it doesn’t wake up the car to check status and uses the last one known. It only wakes for commands. Please check https://developer.tessie.com
thanks!
Refs evcc-io/evcc#11846
Seems we still haven't done so- shouldn't we?
cmd/login
dumps the OAuth2 token to stdout at current. It would be nice to have the option to support writing directly to a file as redirection won't work.
In evcc-io/evcc#10802 I've done some prototyping with vehicle-commands library. Basically, same requests as with this module are executed against fleet-api endpoints. Option 1 would be to switch this module to use the new endpoints.
What does not work is sending commands- these must now be signed. This can be achieved by using the new API or by running a Tesla-provided proxy that converts REST API to signed commands.
That said I will experiment some with which changes would need to be made to connect to arbitrary endpoint urls for simple requests or commands. Especially the response definitions are not part of the vehicle-commands library and still super helpful.
evcc-io/evcc#5826 (reply in thread) has an interesting discussion on how to remote control a powerwall. Access is via Tesla api credentials that we have. It would be nice to provide read-only and potentially write access to the broader Tesla api beyond vehicles.
The streaming API seems to require basic auth rather than bearer token:
https://github.com/bogosj/tesla/blob/main/stream.go#L38
Original code:
https://github.com/jsgoecke/tesla/blob/e02ebd220e5a4158d790d7ed857f937f7f53439e/stream.go#L38
Currently, the basic auth is overridden by the oauth transport. Is that what we need here?
UDPATE seems we need to store the non-oauth client somewhere and use that here, reverting to the original code above. I'll try to prepare something.
Currently I use the library by creating a http.Client outside of the library and manually creating a struct: https://github.com/bogosj/go-tesla-go/blob/0734ca75a1aaca030779f96ebdee98c1483b03e0/setup.go#L100-L108
This is done by using https://github.com/uhthomas/tesla/blob/master/cmd/login/main.go, saving the resulting JSON dictionary to disk and reading those files back.
This was done in bogosj/go-tesla-go@0734ca7
It seems sub-optimal to rely on another binary to bootstrap usage. We could bring uthomas' code into this project and create a method to persist the result of a login to a single token file, but there are likely other options worth considering.
i.e. path.Join(u.Path, "vehicles", strconv.FormatUint(id, 10), "vehicle_data")
Are other login methods other that captcha supported? I was looking at the Ruby gem and it doesn't appear to be a hard auth requirement.
For use with https://evcc.io it would be nice to add the original vehicle images to the gui- does anyone now how to get them from the api?
Whenever calling the v.OpenTrunk("front") or v.OpenTrunk("rear") functions, I get an error 400 Bad Request. Was the API moved or were the names changed?
switch trunk {
case "rear":
case "front":
err := v.OpenTrunk(strings.ToLower(trunk))
if err != nil {
handleError(err, m, "There was an error opening your trunk. Contact @rudi9719 for more information with code %+v")
return
}
default:
k.SendMessageByConvID(m.ConvID, "You must supply front or rear.")
return
}
Hey,
I can succesfully login and retrieve vehicle information, but as soon as I want to send a command like start charging or lock doors, I get "403 Forbidden".
I created the access_token and refresh_token via the iOS App "Auth for Tesla".
Do I need something else?
Example Code:
c, err := tesla.NewClient(ctx, tesla.WithTokenFile(tokenPath))
if err != nil {
return err
}
vehicles, err := c.Vehicles()
if err != nil {
return err
}
for i, v := range vehicles {
if i > 0 {
fmt.Println("----")
}
wakeup, err := v.Wakeup()
if err != nil {
fmt.Println("Wake up err")
fmt.Println(err)
}
fmt.Println(wakeup)
fmt.Printf("ID: %x\n", v.ID)
fmt.Printf("Name %s\n", v.DisplayName)
enabled, err := v.MobileEnabled()
fmt.Println(enabled) <--- True
if err != nil {
fmt.Println("mobile enabled err")
fmt.Println(err)
}
err = v.LockDoors() <--- 403 Forbidden
if err != nil {
return err
}
Thanks for your help!
Couple of bug fixes plus the charging amps?
Code in client.go is lacking comments on exported members. Somehow we weren't yelled at about this. We should have been.
I've noticed this in my logfile today:
[tesla ] TRACE 2022/03/18 09:28:55 POST https://auth.tesla.com/oauth2/v3/token
[tesla ] TRACE 2022/03/18 09:28:55 grant_type=refresh_token&refresh_token=***
--
{"error":"unauthorized_client","error_description":"Unauthorized client","error_uri":"https://auth.tesla.com/error/reference/240b1ae2-..."}
[tesla ] TRACE 2022/03/18 09:28:55 POST https://auth.tesla.com/oauth2/v3/token
[tesla ] TRACE 2022/03/18 09:28:56 client_id=ownerapi&grant_type=refresh_token&refresh_token=***
--
{"access_token":"eyJhbGciO...","expires_in":28800,"token_type":"Bearer"}
it seems as if we're trying to refresh the token twice, first time with missing clientid=ownerapi
though I couldn't immediately find it.
Any ideas?
Hi guys, are we planning anything to address the new captcha madness? Guess we need an interface to let consumer allow to display the captcha or feed it to a solver service?
Was writing a bot and accidentally logged out. Now I can't seem to log back in using my old code, or the cmd/login example.
╭─rudi@imogene ~/tesla/cmd/login ‹main›
╰─➤ go run . -o tesla.token
Username: [email protected]
Password: ************************************************************
2021/07/10 11:06:37 list devices: do: Get "https://auth.tesla.com/oauth2/v3/authorize/mfa/factors?transaction_id=[redacted]": net/http: timeout awaiting response headers
exit status 1
Position seems to have changed:
"drive_state": {
"active_route_latitude": 53,
"active_route_longitude": 8,
"active_route_traffic_minutes_delay": 0,
"power": 3,
"shift_state": null,
"speed": null,
"timestamp": 1700314839825
}
Hi,
With the API changes coming would you like to take ownership going forward with https://github.com/evcc-io/tesla-proxy-client?
Given the new data I get from my car, it looks like the DriveState field names has changed:
"drive_state":{
"active_route_latitude":123.456,
"active_route_longitude":123.456,
"active_route_traffic_minutes_delay":0.0,
"power":0,
"shift_state":null,
"speed":null,
"timestamp":123456789
}
May it be possible to update the API?
Not sure if this is my mistake but it seems as if the tesla API might have changed its timestamp format:
{
"response": {
"battery_heater_on": false,
"battery_level": 57,
"battery_range": 186.49,
"charge_current_request": 6,
"charge_current_request_max": 6,
"charge_enable_request": true,
"charge_energy_added": 0.1,
"charge_limit_soc": 90,
"charge_limit_soc_max": 100,
"charge_limit_soc_min": 50,
"charge_limit_soc_std": 90,
"charge_miles_added_ideal": 0.5,
"charge_miles_added_rated": 0.5,
"charge_port_cold_weather_mode": false,
"charge_port_door_open": true,
"charge_port_latch": "Engaged",
"charge_rate": 4.8,
"charge_to_max_range": false,
"charger_actual_current": 6,
"charger_phases": 1,
"charger_pilot_current": 6,
"charger_power": 1,
"charger_voltage": 220,
"charging_state": "Charging",
"conn_charge_cable": "IEC",
"est_battery_range": 135.85,
"fast_charger_brand": "<invalid>",
"fast_charger_present": false,
"fast_charger_type": "<invalid>",
"ideal_battery_range": 186.49,
"managed_charging_active": false,
"managed_charging_start_time": null,
"managed_charging_user_canceled": false,
"max_range_charge_counter": 1,
"minutes_to_full_charge": 4080,
"not_enough_power_to_heat": null,
"scheduled_charging_pending": false,
"scheduled_charging_start_time": null,
"time_to_full_charge": 68.0,
"timestamp": 1614069716042,
"trip_charging": false,
"usable_battery_level": 55,
"user_charge_enable_request": null
}
}
parsing time "1614069715531" as ""2006-01-02T15:04:05Z07:00"": cannot parse "1614069715531" as """
Looks like unix timestamp (millis?) instead of formatted time. Can anyone confirm?
Follow-up to #44
I'm assuming this is due to some new change to the CAPCHA?
go run .
Username: <username>
Password: *****
2021/09/05 22:06:09 list devices: do: Get "https://auth.tesla.com/oauth2/v3/authorize/mfa/factors?transaction_id=Y2LsCGiQ": net/http: timeout awaiting response headers
exit status 1
See golang/go#59835
When I try to run the login command, I get a 403 error. Is this just me or is there an issue with the API itself?
Username: [email protected]
Password: ******************
2022/07/01 13:45:07 unexpected status code 403
exit status 1
Hi!
So, it looks like Tesla has updated their WAF again. After some experimenting, I've managed to get something working.
The changes are:
Accept
with */*
Accept-Encoding
with gzip, deflate, br
User-Agent
header every 6 hoursReceiving the following error when calling
vehicleState, err := vehicle.VehicleState()
if err != nil {
fmt.Printf("Unable to get Vehicle State: %+v\n", err)
return
}
Unable to get Vehicle State: json: cannot unmarshal number 50.0 into Go struct field .response.speed_limit_mode.min_limit_mph of type int
Hi, I see the drive state changes have been applied (see #111 for context).
I do encounter some issues using these active_route parameters to determinate the car is Home or not:
So giving the above, is there any way to get the Actual Location (used to work before) from the owner api that this library uses ?
The previous location values does not seem to get update anymore.
Whenever we receive a non-200 response, the response JSON is ignored and any contained error swallowed:
HTTP/2.0 408 Request Timeout
Content-Length: 106
Cache-Control: no-cache, no-store, private, s-max-age=0
Content-Type: application/json; charset=utf-8
Date: Fri, 30 Dec 2022 15:46:15 GMT
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Accept
X-Content-Type-Options: nosniff
X-Envoy-Upstream-Cluster: owner-api
X-Envoy-Upstream-Service-Time: 35
X-Frame-Options: DENY
X-Request-Id: 607ca386-1396-48f4-8846-26ae6d5cf866
X-Txid: 443ce41d67afee316399a80eefb2243d
X-Xss-Protection: 1; mode=block
{"response":null,"error":"vehicle unavailable: {:error=>\"vehicle unavailable:\"}","error_description":""}
Will only ever return the HTTP 408 although the code seems to suggest that we're actually decoding the error (which itself is json encoded as string...).
The call against the products endpoint gives mixed responses if non-energy products like vehicles are present in the same account as e.g. a powerwall. The unmarshalling of the response fails on this response, as the product.id field varies between numeric (for vehicles) and string (for energy products).
When I upgrade to latest version, I do not get an update:
❯ go get -v github.com/bogosj/tesla@latest
go.mod
remains at:
github.com/bogosj/tesla v0.0.0-20210425155839-8493aa0dee71
I'm wondering if that's due to the tag being 1.0
instead of 1.0.0
which would be correct semver?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.