HTTP Request Flow with username/password

Now my Homey is running for a while very stable, I want to move to the next level :-).

My sauna is Wifi controlled with HUUM controller. I would like to be able to turn on sauna to a fix temperature and automatically turn on the lights as well. There is a basic API available: https://github.com/horemansp/HUUM

I tried several URLs and I believe I can make it work with the Homey App “HTTP Request Flow card”. However, after entering the URLs to access API, it always asks for my username/password first. Here I get stuck, as I am not sure how to bring this with the GET option into the flow card.

Any ideas how to make this HUUM controller work under Homey?

An idea: First try it in a browser like this:
http://username:password@example.com/
In your case as a POST request:
https://username:password@api.huum.eu/action/home/start?targetTemperature=80
(http or https? Just try)

If that works, without being asked for your credentials, (and the heater is switched on to 80°C),
you can use it in your HTTP request flow card

I think i could be possible with http request, and maybe a little easier with logic, make a webrequest.

I also found a begin of the solution for Homeyscript. I think if you adjust this script it can work

var token_ // variable will store the token
var userName = “clientID”; // app clientID
var passWord = “secretKey”; // app clientSecret
var caspioTokenUrl = “https://xxx123.caspio.com/oauth/token”; // Your application token endpoint
var request = new XMLHttpRequest();

function getToken(url, clientID, clientSecret) {
var key;
request.open(“POST”, url, true);
request.setRequestHeader(“Content-type”, “application/json”);
request.send(“grant_type=client_credentials&client_id=”+clientID+“&”+“client_secret=”+clientSecret); // specify the credentials to receive the token on request
request.onreadystatechange = function () {
if (request.readyState == request.DONE) {
var response = request.responseText;
var obj = JSON.parse(response);
key = obj.access_token; //store the value of the accesstoken
token_ = key; // store token in your global variable “token_” or you could simply return the value of the access token from the function
}
}
}
// Get the token
getToken(caspioTokenUrl, userName, passWordz);

Peter, many thanks! This works well… I can now toggle the light and turn off the sauna. I am sure I should be able to fix the start as well. The flow card seems not to handle the PUT perfect, but I guess I need to play with the arguments. Status request I did not try yet, but I guess I can use that to get status string in a variable.

1 Like

Marcel, I believe your suggestion makes it even better as I can directly make dependencies in the script. E.g. to really turn on or off the ligth based on status instead of toggling. But also bit more complex… Looking forward to a rainy weekend to try that.

Looking forward to your solution. I to am struggling with the autorisation. I also want this script to use. It is in my to do list. But at this moment i am still trying to get my solarpanel script to work fully. But because i am not a real scripter it takes quit some time. If you are ahead if me it would nice to publish it here. When i get to it i will also publish it here