So here is the php script:
<!DOCTYPE html>
<body>
<?php
$tokenExpireFile = file_get_contents("expires.txt");
$tokenExpireObj = DateTime::createFromFormat('d.m.Y H:i:s', $tokenExpireFile);
function httpCall($url, $data, $headers, $method) {
$options = array(
'http' => array(
'header' => $headers,
'method' => $method,
'content' => $data
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo "sent";
}
function httpAuth($url, $data, $headers, $method, $tokenExpireObj)
{
$currentTime = new DateTime();
if($currentTime >= $tokenExpireObj) {
$options = array(
'http' => array(
'header' => $headers,
'method' => $method,
'content' => $data
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$json = json_decode($result);
$expiresIn = $json->expires_in;
$accessToken = $json->access_token;
$tokenExpiresDate = new DateTime();
$tokenExpiresDate->add(new DateInterval("PT".$expiresIn."S"));
$post = $tokenExpiresDate->format("d.m.Y H:i:s");
$fp = fopen('expires.txt', 'w');
fwrite($fp, $post);
fclose($fp);
$fp = fopen('token.txt', 'w');
fwrite($fp, $accessToken);
fclose($fp);
echo "generated new token\r\n";
}
}
if ($_GET["code"] == 123456)
{
$url = 'https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token';
$headers = "Content-Type: application/x-www-form-urlencoded";
$data = http_build_query(array("grant_type" => "password",
"client_id" => "your client id",
"scope" => "openid your client id",
"response_type" => "token",
"username" => "your user / email",
"password" => "your account password"
));
$method = "POST";
httpAuth($url, $data, $headers, $method, $tokenExpireObj);
$token = file_get_contents("token.txt");
$url = 'https://api.tedee.com/api/v1.15/my/lock/open';
$headers = ["Content-Type: application/json",
"Authorization: Bearer ".$token];
$data = array("deviceId" => 4123, "openParameter" => 1);
$JSON = json_encode($data);
$method="POST";
httpCall($url, $JSON, $headers, $method, $token);
echo "<br>abgeschickt";
}
else {
echo "wrong code";
}
?>
</body>
currently I use tedee not integrated in openhab but with this php script. I use HTTP Shortcuts app on android to make http request to this script like https://servername.com/dooropener.php?code=123456
you have to make sure, that your webserver / reverse proxy is secured via tls (https) that nobody can sniff your code (because I can use this script through the internet without to be logged in to wifi).
additionally, you have to find out your device id: Tedee WebAPI Documentation
here you can read, how to generate a token code that you can execute the device request: How to authenticate — Tedee API documentation documentation (readthedocs-hosted.com)
keep in mind that you need to insert your individual stuff at two places: first username/password and second the device id.
and the folder where you place and save my php script, there you have to manually create a token.txt and expires.txt file (keep it empty… it will be temporary filled from my script).