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.

Help with Tesla Powerwall API V3
#11
This should provide a list of products which id should be used in the next request. Change gateway URL and token as needed.
Code:
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')

access_token = 'ABCDEF'

url = 'https://192.168.1.1/api/1/products'

resp = {}
res, code, headers = http.request({
  url = url,
  method = 'GET',
  sink = ltn12.sink.table(resp),
  protocol = 'tlsv12',
  headers = {
    ['Authorization'] = 'Bearer ' .. access_token,
  }
})

resp = table.concat(resp)
log(res, code, resp)

This request will set the battery reserve percent to 50. energy_site_id is the ID from the previous request.
Code:
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')

access_token = 'ABCDEF'
energy_site_id = '123456'
backup_reserve_percent = 50

url = 'https://192.168.1.1/api/1/energy_sites/' .. energy_site_id .. '/backup'

body = json.encode({
  backup_reserve_percent = backup_reserve_percent,
})

res, code, headers = http.request({
  url = url,
  method = 'POST',
  source = ltn12.source.string(body),
  protocol = 'tlsv12',
  headers = {
    ['Content-Type'] = 'application/json',
    ['Content-Length'] = #body,
    ['Authorization'] = 'Bearer ' .. access_token,
  }
})

log(res, code, headers)
Reply


Messages In This Thread
Help with Tesla Powerwall API V3 - by jamesng - 21.04.2021, 14:18
RE: Help with Tesla Powerwall API V3 - by admin - 28.04.2021, 05:25

Forum Jump: