28.04.2021, 05:25
This should provide a list of products which id should be used in the next request. Change gateway URL and token as needed.
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'
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)