This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Tesla Powerwall Local Connection broken with New Release
#1
Tongue Hi


For a few months now I've been connecting our SHAC / LogicMachine to our TeslaPowerwall to load-shift our electricity usage between the battery and the grid in response to the 30 minute electricity pricing provided by Amber Electric.  This has worked really well and we have seen our energy bills fall by about 50%.

Tesla pushed a firmware update the the Powerwall today (v21.20.2) which is causing an error with the local login script.  The remote login script for control of the Powerwall still works well).

Here is the local login script which is no longer working...

Code:
https = require('ssl.https')
json = require('json')
https.TIMEOUT = 5

loginURL = 'https://POWERWALLGATEWAY/api/login/Basic'
  loginBody = "{\"username\":\"customer\",\"password\":\"MYPASS\", \"email\":\"MY@EMAIL.COM\",\"force_sm_off\":false}"
  loginPostResponse = {}

  res, err, loginResponseHeaders, status = https.request
    {
      url = loginURL,
      method = 'POST',
      protocol = 'tlsv12',
      headers =
      {
        ['Accept'] = '*/*',
        ['Content-Type'] = 'application/json',
        ['Content-Length'] = loginBody:len()
      },
      source = ltn12.source.string(loginBody),     
      sink = ltn12.sink.table(loginPostResponse)
    }

   log(res, err, loginResponseHeaders) -- DEBUG

  if loginPostResponse then
   
    mmm_cookies = loginResponseHeaders['set-cookie']
    if mmm_cookies then
      token = mmm_cookies:match('(AuthCookie=[^;]+)'..';')
     
      log ("Successfully retrieved local Tesla Powerwall Login Token " .. token)
     
    end
    
  end 


Now, I get the following error

Code:
attempt to index global 'loginResponseHeaders' (a nil value)

and the debug line returns 

Code:
* arg: 1
  * nil
* arg: 2
  * string: closed
* arg: 3
  * nil


when trying to connect to the Powerwall with the above code.

Previously POWERWALLGATEWAY was a DNS name, however the PowerWall now drops the connection unless an IP address is used in a web browser.  I can connect ok to https://POWERWALLGATEWAY/api/login/Basic/ with a web browser to retrieve the token, however Logic Machine script no longer works.

Pointing a web browser at the Powerwall yields a NET::ERR_CERT_AUTHORITY_INVALID error, which one can click through, however the Logic Machine script can't get past this

The SSL certificate used by Tesla and discussed here https://github.com/vloschiavo/powerwall2. - but don't know how to work around this in the script.

Does anyone have another way that I can connect with logic machine using the IP address to get around this (SSL certificate?) issue?

Many thanks in advance

Kind Regards
James
Reply


Messages In This Thread
Tesla Powerwall Local Connection broken with New Release - by jamesng - 02.07.2021, 07:25

Forum Jump: