iainbullock / tesla-http-proxy-docker

Apache License 2.0
32 stars 10 forks source link

refresh token not in the data folder - where to get it? - all the rest works #56

Closed frankrox closed 1 month ago

frankrox commented 1 month ago

thanks for docker! I have an issue which I hope someone could solve:

Everything works here (I walked through all the steps) except I can't get the refresh token. Somehow the refresh token is not being put into the data folder. Everything else seems to be working...! I just need to get the refresh token.

Is there another method to get the refresh token or a solution why it isn't being put in the folder? It doesnt seem to be in the log either. (the partner authentication token is in the logs) The addon readme shows a paste function to paste the URL after you fill in the generate OATH token. I do get that callback url (with the page not found), but ofcourse this is via addon which is not possible with my docker setup and it should be in the folder instead.

My docker-compose file is in volume2/docker/tesla_http_proxy. The config.sh(config4.sh in the meantime, was debugging some other stuff) is read correctly from the data folder (tesla_http_proxy/data) , also the pem file is put in the right folder (/volume2/docker/homeassistant/config/tesla_http_proxy), and the com.tesla.3p.public-key.pem is put into the web folder. Just the refresh token is missing.

Thanks!

To be complete, here is my docker-compose.yml:


version: '3'
volumes:
  tesla_http_proxy:
    external: true
services:   
  tesla_http_proxy:
    container_name: tesla_http_proxy
    restart: always
    image: "iainbullock/tesla_http_proxy:latest"

    environment:
      - TZ=Europe/Amsterdam
      - CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxx
      - CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
      - DOMAIN=xxxxxxxx # Public FQDN 
      - PROXY_HOST=xxxxxxx # Local hostname (not IP) of this docker host
      - REGION=Europe, Middle East, Africa

    stdin_open: true
    tty: true         

    entrypoint: "/app/run.sh"
    working_dir: /app

    volumes:

      - tesla_http_proxy:/data
      # Webserver root for the $DOMAIN virtual server. Change the path according to your webserver setup. Path must exist or this container won't start
      - type: bind
        source: /volume2/web/teslaproxy # Refer to step 2.1
        target: /share/nginx #Do not modify
      # Path to tesla_http_proxy directory inside /config on Home Assistant instance. Change according to your HA setup. Path must exist or this container won't start
      - type: bind
        source: /volume2/docker/homeassistent/config/tesla_http_proxy #Refer to step 5.1
        target: /share/home-assistant #Do not modify
      - /volume2/docker/tesla_http_proxy/data/config4.sh:/data/config4.sh 

    network_mode: bridge
    ports:
      - 4430:443
      - 8099:8099 

volumes: 
  tesla_http_proxy: {}
iainbullock commented 1 month ago

You get the Refresh Token from the Auth for Tesla app (on iOS) and enter it in the setup dialog for Tesla Custom Integration. Make sure you get a Fleet API token not a Owners API token

iainbullock commented 1 month ago

I should also add that I've just seen this updated integration which if it works will make this project obsolete and everything a whole lot easier. I haven't tested it though so it might be too good to be true

https://www.home-assistant.io/integrations/tesla_fleet/

frankrox commented 1 month ago

You get the Refresh Token from the Auth for Tesla app (on iOS) and enter it in the setup dialog for Tesla Custom Integration. Make sure you get a Fleet API token not a Owners API token

I'm afraid I don't have iOS. is there another option?

frankrox commented 1 month ago

I should also add that I've just seen this updated integration which if it works will make this project obsolete and everything a whole lot easier. I haven't tested it though so it might be too good to be true

https://www.home-assistant.io/integrations/tesla_fleet/

Thanks for your response! I have seen that, but it appears only sensor are available, no switches. Main purposes here is to control the charging (mostly starting and stopping)

iainbullock commented 1 month ago

I can't respond right now.

In the meantime you might find an Android (or other OS) app on the parent project https://github.com/llamafilm/tesla-http-proxy-addon

frankrox commented 1 month ago

In the meantime I found an iOS device and got the tesla fleet refresh token via the iOS app, Thanks!

Now the next error: In the tesla custom integration after putting in all the info, and after initialising it says: All connection attemps failed. The integration retries very 2 minutes, but no joy.

the debug log of the tesla_custom integration says the following(i changed the access token so nothing private). I am not Turkish btw, as you might think from the trusting CA. I saw in some other post it shows up with some people:

2024-08-16 21:21:04.552 DEBUG (MainThread) [teslajsonpy.connection] Successfully refreshed oauth 2024-08-16 21:21:04.552 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:21:06.426 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:58 2024-08-16 21:21:06.426 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:21:08.647 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:56 2024-08-16 21:21:08.648 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:21:13.412 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:51 2024-08-16 21:21:13.412 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:21:19.258 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:45 2024-08-16 21:21:19.258 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:25:55.695 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:56 2024-08-16 21:25:55.695 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:26:00.101 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:51 2024-08-16 21:26:00.101 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:26:05.071 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:46 2024-08-16 21:26:05.071 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:27:25.177 DEBUG (MainThread) [custom_components.tesla_custom] Trusting CA: {'subject': ((('countryName', 'TR'),), (('localityName', 'Gebze - Kocaeli'),), (('organizationName', 'Turkiye Bilimsel ve Teknolojik Arastirma Kurumu - TUBITAK'),), (('organizationalUnitName', 'Kamu Sertifikasyon Merkezi - Kamu SM'),), (('commonName', 'TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1'),)), 'issuer': ((('countryName', 'TR'),), (('localityName', 'Gebze - Kocaeli'),), (('organizationName', 'Turkiye Bilimsel ve Teknolojik Arastirma Kurumu - TUBITAK'),), (('organizationalUnitName', 'Kamu Sertifikasyon Merkezi - Kamu SM'),), (('commonName', 'TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1'),)), 'version': 3, 'serialNumber': '01', 'notBefore': 'Nov 25 08:25:55 2013 GMT', 'notAfter': 'Oct 25 08:25:55 2043 GMT'} 2024-08-16 21:27:25.208 DEBUG (MainThread) [teslajsonpy.controller] 552 endpoints loaded 2024-08-16 21:27:25.208 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in -19952 days, 2:32:35 2024-08-16 21:27:25.208 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected 2024-08-16 21:27:25.208 DEBUG (MainThread) [teslajsonpy.connection] Refreshing access token with refresh_token 2024-08-16 21:27:25.503 DEBUG (MainThread) [teslajsonpy.connection] Saved new auth info {'access_token': 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InE0dHg3Q1UyYzI2V1BiemwxZjZjanM3QnhzayJ9.eyJpc3MiOiJodHRwczovL2F1dGgudGVzbGEuY29tL29hdXRoMi92My9udHMiLCJhenAiOiI5ZjI3M2Q5Zi0yZjA1LTQ1YTItYmI3OS1kYmViZWJhOTRjZGQiLCJzdWIiOiIzYmY1ZmMxMi0yMWZkLTQ1Y2EtYTA0MS1hYjUzZWFhYjkzODkiLCJhdWQiOlsiaHR0cHM6Ly9mbGVldC1hcGkucHJkLm5hLnZuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxjbWRzIiwidmVoaWNsZV9jaGFyZ2luZ19jbWRzIiwiZW1haWwiXSwiYW1yIjpbInB3ZCIsIm1mYSIsIm90cCJdLCJleHAiOjE3MjM4NjUyNDUsImlhdCI6MTcyMzgzNjQ0NSwib3VfY29kZSI6IkVVIiwibG9jYWxlIjoibmwtTkwiLCJhY2NvdW50X3R5cGUiOiJwZXJzb24iLCJvcGVuX3NvdXJjZSI6ZmFsc2UsImFjY291bnRfaWQiOiJiMjQ1ZDNjNC1kMjVjLTQ1NTUtODg2MC03NzI2MzE3NDk5ZDIiLCJhdXRoX3RpbWUiOjE3MjM4MzY0NDUsIm5vbmNlIjpudWxsfQ.0M4s6SbTHgsc64N-Y6nzAiCWnowlYobkYa28922sW5gCVIliYFfv41CgkU6nHbJR9I0KKj31pcK9HAH5SCJqEzajVrce54e1nJcQsTKu9HiSyBxc1T1BgWs2_25mhbBRG0Q7QGNBXihqgPs5FWmNWIceVfPwGOuasp5OwhnCmxnfcBQWjHQTn6CH5NgMrSyqjUEYRXq3jYp_y3uxkO-JJS_wBhKF-Evx_WYmdp1Yck21y0CGftk3TtHZ0N1-Ln6f6eul3LgMdy-hYM0PKaxzcdwDyMsrrK5SDJzrkmq4w3t0gOV9LQo8VHG8i4qDXx3o5XZL-mf9nKBIRUd0JeSUMg', 'refresh_token': 'EU_f8fc3360f624ef92cae7d87d26a319fb137b3034fe99827a01f74fceb4b65f9e', 'expires_in': 1723872445} 2024-08-16 21:27:25.504 DEBUG (MainThread) [teslajsonpy.connection] Successfully refreshed oauth 2024-08-16 21:27:25.504 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:27:26.533 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:59 2024-08-16 21:27:26.534 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:27:29.468 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:56 2024-08-16 21:27:29.469 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:27:33.564 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:52 2024-08-16 21:27:33.565 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {} 2024-08-16 21:27:40.209 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:59:45 2024-08-16 21:27:40.209 DEBUG (MainThread) [teslajsonpy.connection] get: https://xtremerox.local:4430/api/1/products {}

iainbullock commented 1 month ago

This looks normal. I don't see an error message in the logs, is there one? Also do you have logs from the proxy itself to see if HA attempts to connect

frankrox commented 1 month ago

This looks normal. I don't see an error message in the logs, is there one? Also do you have logs from the proxy itself to see if HA attempts to connect

in het ha debug log there is no error message. The custom integration says all connections are refused after initialising.

Where can i find the logs from the proxy itself? I only have the stdout. which gives nothing new since yesterdayevening (despite restarting the custom tesla integration. (the flask server is down) Or do the connection attemps show up here?:

date stream content
2024/08/16 20:19:30 stdout [18:19:30] werkzeug:INFO: Press CTRL+C to quit
2024/08/16 20:19:30 stdout * Running on http://172.17.0.2:8099
2024/08/16 20:19:30 stdout * Running on http://127.0.0.1:8099
2024/08/16 20:19:30 stdout * Running on all addresses (0.0.0.0)
2024/08/16 20:19:30 stdout [18:19:30] werkzeug:INFO: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
2024/08/16 20:19:30 stdout [18:19:30] main:INFO:  Starting Flask server... 
2024/08/16 20:19:30 stdout Starting temporary Python app for authentication flow. Delete /data/access_token to force regeneration in the future
2024/08/16 20:19:30 stdout Found existing keypair
2024/08/16 20:19:30 stdout REGION=Europe, Middle East, Africa
2024/08/16 20:19:30 stdout PROXY_HOST=xtremerox.local
iainbullock commented 1 month ago

Yes the connection attempt should appear here. Looks like HA can't connect to the proxy for some reason. Try using curl from the HA instance command line. Might be a DNS look up issue for example.

frankrox commented 1 month ago

it works! thanks for your help!! The issue here probably was I needed to rebuild the tesla_http_proxy and follow the checklist again after changing the old localhost name.