17.02.2023, 09:14
Use this. Make sure you have the latest firmware as requests in such format won't work on older versions.
Change unitid, username, password as needed. unitid is the ID that you see when opening the status page (https://pool.aseko.com/XYZ/data/actual). Sometimes the login fails with gateway timeout, just run the script again if it happens.
Change unitid, username, password as needed. unitid is the ID that you see when opening the status page (https://pool.aseko.com/XYZ/data/actual). Sometimes the login fails with gateway timeout, just run the script again if it happens.
Code:
json = require('json')
http = require('socket.http')
unitid = '1234'
username = 'user@example.com'
password = 'password'
body = json.encode({
username = username,
password = password,
agree = 'on'
})
resp, code, hdrs, stat = http.request({
url = 'https://pool.aseko.com/api/login',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
['Content-Length'] = #body,
},
body = body
})
setcookie = hdrs['set-cookie'] or ''
cookie = setcookie:split(';')[1]
if not cookie then
log('login failed', resp)
return
end
resp, code, hdrs, stat = http.request({
url = 'https://pool.aseko.com/api/units/' .. unitid,
method = 'GET',
headers = {
['Cookie'] = cookie
}
})
data = json.pdecode(resp)
if type(data) ~= 'table' then
log('data request failed', resp)
return
end
values = {}
for _, var in ipairs(data.variables) do
values[ var.type ] = var.currentValue
end
grp.checkupdate('1/1/1', values.rx)
grp.checkupdate('1/1/2', values.waterTemp)
grp.checkupdate('1/1/3', values.ph)