Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

Posted

Hi!

Is there anyone here trying to figure out how to communicate with Tesla API?

I want to communicate with my car and adapt the charging current level based on my total power use, so I don’t pass a set power limit.

I’m willing to pay if someone has code of worth.

  • Like 1
Posted

Hi @RoReAl, this sounds like a really useful use case.

 

if you want to write a quick app yourself, this tutorial (based on HC2) will help

Please login or register to see this link.

 

If you want to use an existing Tesla QA, do a search on the forum because someone already wrote one. Though I think the API has recently changed and it needs to be reworked.

 

good luck and perhaps post your progress on the other existing thread.

 

 

  • Topic Author
  • Posted

    Yes I have seen that code and i whant something like that for HC3 and Quickapp. Hopefully someone can refer to a similar LUA project.

    • 11 months later...
    Posted

    I've started to work on this subject, based on the new version of the API that's described here:

    Please login or register to see this link.

    But the journey will be quite long.

    So far, I've managed to generate all the material to build the first authentification step, which is not as simple as they can expect. the generated url works fine in postman (returning me the html page with the hidden section. But the exact same url sent from my HC3 will return a 403 error, meaning that tesla understood my request but considered it as forbidden. There is absolutely no message returned with that error, making it hard to understand the root cause.

    However, I highly suspect that this is because the HC3 HTTPclient doesn't manage, at least by default, cookies. And from what I can see in postman, a bunch of cookies are returned and will be useful for the next steps.

     

    I've tried to check the virtual device code that was available on this forum, but found nothing useful: no url in it that could provide me hints of syntax, no mention of cookies. I'll continue to work on this, the next step being to find out what really the HC3 is sending to tesla.com and comparing it with what postman sends and then trying to find out a way to instruct HC3 to send the same data as postman. 

     

    I think this topic should be collectively managed with each participant providing his knowledge to finally succeed in connecting to Tesla.

     

    The first step I've managed to build is not as simple as it may look: indeed, I had to find out how to hash in lua the challenge-code (random string), using the correct method (sha2 with 256 bits is the answer, no sha3) and then how to encode the answer in url base 64. TO ensure this, I've found a library that had all the needed functions. The only trick being that to encode in urlbase64, it needs to be converted from string to binary and then from binary to urlbase64.  The name of this library is sha2lib_v0.1.fqa (can be found on the market place). It contains two tabs and the sha2 has to be imported in the Tesla QA in order to be callable by your app.

     

    Then, the next tricky thing is to determine how to pass variables to the tesla server and how to manage spaces (%20?) or if quotes are needed. And last, how to force http client to use https. The result of all those steps looks like this:

    Please login or register to see this link.

     

    code_challenge is the hash of a ramdom string and state is a ramdom string. 

     

    For information, here is the full code I've used to generate the url and to send it, without success so far, to the Tesla server:

        local sha256 = sha.sha256
        local hex2bin=sha.hex2bin
        local bin2base64=sha.bin2base64
        --génère une chaine aléatoire de 86 caractères de long comme code_verifier qui sera utilisée dans la procédure d'identification
        code_verifier=""
        for i=1,86 do -- boucle pour arriver à une chaine de caractères de 86 de long
            a=math.random(48,122)
            while (a<65 and a>57or (a<97 and a>90do
                a=math.random(48,122)
            end
            -- à ce stade, a ne contient que des codes ascii correspondant à des lettres ou des chiffres
            code_verifier=code_verifier .. string.char(a)
        end
        state=""
        for i=1,10 do -- boucle pour arriver à une chaine de caractères de 10 de long
            a=math.random(48,122)
            while (a<65 and a>57or (a<97 and a>90do
                a=math.random(48,122)
            end
            -- à ce stade, a ne contient que des codes ascii correspondant à des lettres ou des chiffres
            state=state .. string.char(a)
        end
        self:debug("state: ",state) -- state contient à ce stade une chaine hexadecimale aléatoire de 10 caractères
        --string.byte("Z")
        self:debug("code_verifier: ",code_verifier) -- code_verifier contient à ce stade une chaine hexadecimale aléatoire de 86 caractères
        -- genère le hash sha256 encodé en urlbase64 de code_verifier
        code_challenge=bin2base64(hex2bin(sha256(code_verifier)))
        self:debug("code_challenge: ",code_challenge) -- code_challenge contient le hash sha256 encodé en urlbase64 de code_verifier
    --------------------------------------------------------------------
        MyURL="https://auth.tesla.com/oauth2/v3/authorize?client_id=ownerapi&code_challenge=" .. code_challenge .."&code_challenge_method=S256&redirect_uri=https://auth.tesla.com/void/callback&response_type=code&scope=openid%20email%20offline_access&state=" ..state.."&login_hint=" .. self.Login
        self:debug("MyURL: ", MyURL)
        self.http = net.HTTPClient({timeout=3000, sync= true})
        self.http:request(MyURL, 
            {
            options = { method = "GET"
                        headers = {['User-Agent']="PostmanRuntime/7.30.0", Accept="*/*" } },
            success = function(response) 
            print("Status", response.status)
            print("Data", response.data)
          end,
          error = function(message)
            self:error(message)
          end
        })
     
    You can note the snyc=true option in the call of the HTTPclient that is meant to provide synchronous calls instead of the native asynchronous mode. As the steps to connect to Tesla are obviously sequential, I through this was easier to proceed this way. I wanted to highlight this as I've been searching for such an option during weeks and never found it on fibaro forums. And I find it much easier than using the strategy of the function having another function running within its arguments.
     
    So, if there is someone that knows how to manage cookies receiving from the server with an httpclient call (= creating a cookie storage and then accessing to it), that would probably be a big step forward to establish the communication between an HC3 and a Tesla.
     
    Also, if someone knows a simple way to parse a returned HTML message from a server, this would help a lot for the next step that is getting the returned parameters in the html hidden section.
    • Thanks 1
    • 2 months later...
    Posted

    hi, is there any progress on the integration? It would be very useful for solar charge management

    • 1 year later...
    Posted

    Hi somebody have Tesla Quick app for HC3?

    Posted

    I buy for this page 

    Please login or register to see this link.

    • 5 months later...
    Posted

    Do you have somebody Tesla Quick app? Or for now is not exist. I asking because if not I will try to do it.

    Posted

    I haven't seen it, but if you do, I'd be happy to test it :)

    • 2 months later...
    Posted

    No body try to program Tesla to HCE like in HA? 

    Please login or register to see this link.

    ?? Can somebody to help try it ?

    Posted (edited)
    22 hours ago, Martin555 said:

    No body try to program Tesla to HCE like in HA? Can somebody to help try it ?

     

    To be honest it is not only complex QA, the prereqs are already in very complex (secp384r1) to not possible (SSL proxy, redirect to HC3) range.

    To make them possible, one need e.g. raspi, as a proxy and some dev.

     

    Much easier is to use HA and code something to forward Tesla toys to HC3

     

    Edited by tinman
    Posted (edited)

    There is an application in Hommeassistance. It works. I managed it in HC3 to get a response and access token from Tesla from the name sent. I currently want to get a list of cars and I'm figuring out what header to send. I'm working on it, I'll send what I have. 

     
     
    I managed to load the vehicle data, I'm now working on listing the specific values.
     
    Auto #1: (ID: XXXXX, VIN: 5YJS...)[23.11.2025] [15:03:37] [TRACE] [QUICKAPP3649]: Auto #2: Tomulko  (ID: YYYY, VIN: 5YJSA...)[23.11.2025] [15:03:37] [TRACE] [QUICKAPP3649]: Auto #3: Martin (ID: XXXXXX, VIN: LRWY...)


    If somebody to whant help you can

     

    I have data [23.11.2025] [15:46:47] [TRACE] [QUICKAPP3649]: Batéria: 51%[23.11.2025] [15:46:47] [TRACE] [QUICKAPP3649]: Dojazd: 142.85 km

     

    Please login or register to see this image.

    /monthly_2025_11/image.png.e5b79ea4934b976c7342d4c73b5990db.png" />

    Edited by Martin555
    Posted
    On 3/15/2025 at 4:41 PM, wojtas810 said:

    Kupujem pre túto stránku

    Please login or register to see this link.

    I created QA for HC3. 

     

     

    On 11/20/2025 at 2:23 AM, tinman said:

     

    Úprimne, nejde len o zložité QA, predpoklady sú už veľmi zložité (secp384r1) až nemožné (SSL proxy, presmerovať na HC3).

    Aby boli možné, potrebujeme napríklad raspiho ako zástupcu a nejakého vývojára.

     

    Oveľa jednoduchšie je použiť HA a naprogramovať niečo na preposielanie Tesla hračiek na HC3

     

    I created QA for HC3. 

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...