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.

Home Connect
#1
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 ?
Reply
#2
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.
Reply
#3
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
Reply
#4
It should be provided to you when you create a new application in the Developer portal.
Reply
#5
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

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
Reply
#6
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.
Reply
#7
(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 new
access_token/refresh_token.
What 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
Reply
#8
For testing you can paste it in to Sturt-up(init) script and press Run script.
------------------------------
Ctrl+F5
Reply


Forum Jump: