evcc-io / evcc

Sonne tanken ☀️🚘
https://evcc.io
MIT License
3.42k stars 623 forks source link

Tesla Token still expiring #12111

Closed buliwyf42 closed 8 months ago

buliwyf42 commented 8 months ago

Describe the bug

I'm using the latest nightly after the issues with 0.124 but it seems my token expires after some time anyway. I configured it via the UI. I had this several time since yesterday. Writing to the db is possible.

Steps to reproduce

This is how it looks in the UI after entering the correct config saving and validating it an restarting evcc.

SCR-20240206-ruzs

Configuration details

Configured via UI

Log details

Feb  6 13:35:27 evcc evcc[6262]: [db    ] INFO 2024/02/06 13:35:27 using sqlite database: /var/lib/evcc/evcc.db
Feb  6 13:35:27 evcc systemd[1]: ssh@26-192.168.203.61:22-192.168.203.125:65387.service: Deactivated successfully.
Feb  6 13:35:27 evcc systemd[1]: session-4066.scope: Deactivated successfully.
Feb  6 13:35:27 evcc evcc[6262]: [mqtt  ] INFO 2024/02/06 13:35:27 connecting evcc-1141834791 at tcp://mqtt.home.lan:1883
Feb  6 13:35:28 evcc evcc[6262]: [main  ] ERROR 2024/02/06 13:35:28 creating vehicle db:4 failed: cannot create vehicle type 'template': cannot create vehicle type 'tesla-command': token expired
Feb  6 13:35:28 evcc evcc[6262]: [lp-2  ] WARN 2024/02/06 13:35:28 poll mode '{always 30s}' may deplete your battery or lead to API misuse. USE AT YOUR OWN RISK.
Feb  6 13:35:28 evcc evcc[6262]: [site  ] WARN 2024/02/06 13:35:28 vehicle 'Warmwasser' does not support automatic detection
Feb  6 13:35:28 evcc evcc[6262]: [site  ] WARN 2024/02/06 13:35:28 vehicle 'NEO (offline)' does not support automatic detection
Feb  6 13:35:28 evcc evcc[6262]: [site  ] INFO 2024/02/06 13:35:28 site config:

evcc settings get tesla-command
[main  ] INFO 2024/02/06 20:33:31 evcc 0.124.1
[main  ] INFO 2024/02/06 20:33:31 using config file: /etc/evcc.yaml
[db    ] INFO 2024/02/06 20:33:31 using sqlite database: /root/.evcc/evcc.db
[mqtt  ] INFO 2024/02/06 20:33:31 connecting evcc-1003487051 at tcp://mqtt.home.lan:1883
root@evcc:~# evcc configure

What type of operating system are you running?

Linux

Version

evcc version 0.124.1

andig commented 8 months ago

Could you share a fresh token with info@evcc.io?

buliwyf42 commented 8 months ago

Both Token? btw could the culprit be an (old) token in the settings table?

andig commented 8 months ago

Identical to what youve used in the ui

buliwyf42 commented 8 months ago

You have mail.

andig commented 8 months ago

Looks like Token works on first use. If it is not refreshed and evcc restarted while token expires, then code would not use the refresh token from config and instead fail. This is fixed by https://github.com/evcc-io/evcc/pull/12121. Nightly will be updated in 30min.

buliwyf42 commented 8 months ago

Thanks. I still have the issue if I hit the “Edit” button in the Device Configuration that it shows like in the picture above. All the Fields are empty. Not even the name is filled. It looks like the info is not pulled from the db correctly. Is this another Bug?

naltatis commented 8 months ago

@buliwyf42 Yes, this looks like a UI or communication issue. Can you open a new bug with some more details? Browser version and screenshot from the network tab of the browser development tools would help to narrow in on this issue.

andi0b commented 8 months ago

@andig I'm also having issues with Tesla token refresh, next expiry is in 7 hours and I set up collecting logs (running on nightly 0.124.1 (39bb31a1))

Just one question about the token refresh process: Shouldn't the refreshed token be stored somewhere even after the first startup of evcc? I don't know the tesla api, but usually token refresh needs to be done on the most recent token and not on the initial token.

I looked into the sqlite db and couldn't find it there:

sqlite3 "file:./evcc.db?mode=ro"
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
sqlite> select * from settings;
lp1.planEnergy|0
lp1.planTime|0001-01-01T00:00:00Z
bufferSoc|100
smartCostLimit|0.01
lp1.mode|pv
vehicle.a.planTime|0001-01-01T00:00:00Z
vehicle.a.planSoc|0
lp1.limitSoc|0
bufferStartSoc|0
prioritySoc|60
lp1.minCurrent|6
lp1.maxCurrent|32
lp1.phasesConfigured|3
batteryDischargeControl|false
vehicle.b.planTime|2024-02-12T06:00:00Z
vehicle.b.planSoc|70
vehicle.b.limitSoc|70
vehicle.b.minSoc|25

and config.yaml looks like this:

levels:
  tesla-command: trace

vehicles: 
  - name: a
    type: template
    template: tesla-command
    title: A
    mincurrent: 6
    maxcurrent: 16
    accessToken: "ey...."
    refreshToken: "EU_8...."
    vin: L....
    capacity: 60
andig commented 8 months ago

It will only be refreshed if expired. If your yaml access token is still valid, we‘ll use that. You could try placing any expired token there for testing though.

andig commented 8 months ago

Please open new issue, this seems more about ui refresh than token expiry now.