I've gotten a bit further here. The HC API requires me to log in to my account and accept the API connection. I have made that part of the script, but the question is how to get this part of the script only to run once when needed. The return is a device_code and a url for logging in to HC account. If the function is run every cycle, the verification url changes, and the device_code also.
Documentation: https://api-docs.home-connect.com/author...evice-flow
response_decode:
Documentation: https://api-docs.home-connect.com/author...evice-flow
Code:
function GetDeviceCode()
local request_code_url = "https://api.home-connect.com/security/oauth/device_authorization"
local response_body = {}
local export_data = {}
local request_body = "client_id=" .. client_id .. "&scope=" .. scope
local body, code, hdrs, stat = https.request
{
url = request_code_url;
method = "POST";
headers =
{
["Content-Type"] = "application/x-www-form-urlencoded";
["Content-Length"] = #request_body;
};
source = ltn12.source.string(request_body);
sink = ltn12.sink.table(response_body);
}
log(code)
if code == 200 then
response_decode = json.decode(table.concat(response_body))
log(response_decode)
sleep = response_decode["interval"]
return response_decode["device_code"]
end
end
response_decode:
Code:
* table:
["expires_in"]
* number: 600
["verification_uri_complete"]
* string: https://api.home-connect.com/security/oauth/device_verify?user_code=xxxx-xxxx
["verification_uri"]
* string: https://api.home-connect.com/security/oauth/device_verify
["user_code"]
* string: xxxx-xxxx
["device_code"]
* string: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
["interval"]
* number: 5