![]() |
|
Home Connect - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Home Connect (/showthread.php?tid=3014) |
Home Connect - tomnord - 24.11.2020 Hello. Has anyone tried to control Home Connect units via the api? https://apiclient.home-connect.com/ There needs to be some authentication, and a key given with registration. If anyone could push me in the right direction regarding the authorization and token I would be greatfull. @Erwin ? RE: Home Connect - Erwin van der Zwart - 25.11.2020 Never tried to connect to this API, but it's RESTful so i have a lot of scripts to do that, there are a lot of them here on the forum.. Try looking for "Tesla" and there you have your starting point how to handle token request and auth header. Home Connect - tomnord - 11.02.2021 Hi Erwin. I've been trying to get the authenticatin part of the script to work, but I am having a hard time figuring out how to get hold of the client-secret. I'm guessing this is a init script that needs to be run once? I have the client-id and other credentials. Sent fra min SM-G980F via Tapatalk RE: Home Connect - admin - 12.02.2021 It should be provided to you when you create a new application in the Developer portal. RE: Home Connect - tomnord - 08.03.2021 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/authorization?#device-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
endresponse_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: 5RE: Home Connect - admin - 09.03.2021 After getting the device code you should send periodical requests to https://api.home-connect.com/security/oauth/token until you get a "200 OK" response. This will get you an access_token and a refresh_token. Put both into storage and use the access_token for all normal API calls. Since this token expires in one day you will need a scheduled script that will exchange the refresh_token for a new access_token/refresh_token. RE: Home Connect - tomnord - 09.03.2021 (09.03.2021, 06:54)admin Wrote: After getting the device code you should send periodical requests to https://api.home-connect.com/security/oauth/token until you get a "200 OK" response. This will get you an access_token and a refresh_token. Put both into storage and use the access_token for all normal API calls. Since this token expires in one day you will need a scheduled script that will exchange the refresh_token for a newWhat would be the best practice for getting the scrip mentioned above just to run once? Make an event script, and put the code in memory? Sent fra min SM-G980F via Tapatalk RE: Home Connect - Daniel - 09.03.2021 For testing you can paste it in to Sturt-up(init) script and press Run script. |