Hello people,
I have a question concerning the control of a thermostat.
We have at home a e-thermostat from Essent.
Now I have done myself a little research and found this script.
<?php
class Thermostat {
function __construct($username, $password){
$this->username = $username;
$this->password = $password;
}
function getData($return='token'){
$url = "https://portal.icy.nl/login";
$postData = "username=".$this->username."&password=".$this->password;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output=curl_exec($ch);
curl_close($ch);
$json = json_decode($output);
return $json->{''.$return.''};
}
function getTemp($temp="temperature2"){
$token = $this->getData();
$url = "https://portal.icy.nl/data?username=".$this->username."&password=".$this->password;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Session-token:".$token));
$output = curl_exec($ch);
curl_close($ch);
$json = json_decode($output);
return $json->{''.$temp.''};
}
function setTemp($temp){
$token = $this->getData();
$uid = $this->getData('serialthermostat1');
$url = "https://portal.icy.nl/data";
$postData = "uid=".$uid."&temperature1=".$temp;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Session-token:".$token));
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output=curl_exec($ch);
curl_close($ch);
$json = json_decode($output);
if($json->{'status'}->{'code'} == "200"){
return true;
}
}
}
?>
And this
<?php
//Start a new class
$Thermostat = new Thermostat(’{gebruikersnaam}’, ‘{wachtwoord}’);
//Main temp? Let op! Links = temperature1, Rechts = temperature2. Standaard staat hij op 1
$Thermostat->getTemp();
//New main temp
$Thermostat->setTemp(’{temperatuur}’);
?>
Is there a way te implent this in pimatic? Or if someone can help me further ahead.
Thanks in advance!