Einzelner Wert aus stdClass Object

an die PHP Profis wie komme ich an den einzelnen „Wert“ state um ihn in eine Variable zuschreiben?

stdClass Object
(
    [result] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 3813
                    [isConnected] => 1
                    [lockProperties] => stdClass Object
                        (
                            [state] => 2
                            [isCharging] => 
                            [batteryLevel] => 60
                        )

                )

        )

    [success] => 1
    [errorMessages] => Array
        (
        )

    [statusCode] => 200
)

hier das Script dazu

<?php
IPS_RunScript(31236);

IPS_Sleep(300);
$token = GetValue(26285);
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.tedee.com/api/v1.15/my/lock/sync",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer ".$token, 
      "Content-Type: application/json"
    
),
));

$response = curl_exec($curl);

curl_close($curl);


$a =  (json_decode($response));

print_r($a);


Moin jheinz,

du kannst die Ausgabe vereinfachen, wenn du json_decode mit True verwendest PHP: json_decode - Manual

Das Ergebnis ist dann ein assoziatives Array und damit wird es übersichtlicher :wink: Solltest du damit nicht klar kommen melde dich noch einmal.

Gruß
Hans

Hallo Hans,

vielen Dank. Jetzt habe ich es hin bekommen.:slight_smile:

Hallo jheinz,

läuft das Skript für das tedee-Schloss bei Dir noch?
Woher kommt der Token in der Variable 26285?

Viele Grüße aus dem Unterallgäu
Harry

Ja Habe mittlerweile 2 x Tedde im Einsatz. Der Token wird per Script abgefragt und in eine Variable geschrieben.

https://tedee-tedee-api-doc.readthedocs-hosted.com/en/latest/howtos/authenticate.html

Vielen Dank für die schnelle Antwort.

Ich habe seit vier Wochen ein tedee und bin sehr zufrieden damit, aber ich scheitere an der Einbindung in IPS.

Danke für den Tipp und das Skript - ich hoffe, ich komme damit weiter. Die API-Dokumentation ist schwer zu verstehen und ich komme mit den empfohlenen Tools/Client nicht zu Recht. :grimacing:

Auf jeden Fall ist das Schloss besser als HomeMatic/KeyMatic und Danalock, die habe ich wieder ausgebaut.

Viele Grüße aus dem Unterallgäu
Harry

Hallo Harry,

hier mal das Script für den Token:
Du musst natürlich noch deine Daten (ids, Benutzer und Passwort) eintragen (xxx).

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "grant_type=password&client_id=xxx&scope=openid%2002106b82-0524-4fd3-ac57-af774f340979&response_type=token&username=xxxx&password=xxx",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
$a =(json_decode($response));
//print_r($a);

SetValue(26285, $a->{"access_token"});

Hier zum öffnen:

<?php
include_once('31236.ips.php');
$token =  $a->{"access_token"};


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.tedee.com/api/v1.15/my/lock/open",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"{\r\n  \"deviceId\": 3813\r\n}",
  CURLOPT_HTTPHEADER => array(
   "Authorization: Bearer ".$token,
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

DANKE - ich werde testen!

Viele Grüße aus dem zu kalten Unterallgäu
Harry

Hallo jheinz,

ich bin kurz vor dem Ziel. :wink:

Im Portal https://portal.tedee.com/ habe ich alles aufgeräumt und dort werden Bridge und Lock korrekt angezeigt.

Letzter kleiner Stolperstein ist die Client-ID.
Die Doku sagt „The client id assigned to your application.“

Ich habe das Anforderungsformular gefunden und hänge bei

  • Public Mobile (Implicit Flow)
  • Public Service (Code Flow)
  • Private (ROPC Flow)

Was hast Du dort angegeben?

Viele Grüße
Harry

Bei ROPC steht:

ROPC Flow is deprecated. Estimated time of removing: end of Q4 2021. The new authentication method will be introduced instead.

CURL funktioniert!

Die Client-ID ist identisch zum Scope:
client_id=02106b82-0524-4fd3-ac57-af774f340979

Nun schaue ich mir die Response an.

Gruß Harry

Bei mir ist client_id und Scope identisch jedoch ist bei scope noch ein Leerzeichen da vor (%20)

Vielleicht hilft es. Ist schon etwas länger her wo ich die scripte zusammen gezimmert habe.

Der CURL-Aufruf funktioniert, aber ich bekomme eine Fehlermeldung:

„Lock not found or not assigned to the user.“

Unverständlich, da im Portal der tedee-App alles korrekt angezeigt wird. Da werde ich wohl den Support kontaktieren müssen.

Gruß Harry

Hast Du die richtige deviceid angegeben?

was ist die richtige Device-ID?
wo finde ich die? die fünfstellige Nummer des Lock in der App?

Ich glaube nicht, musst Du in der API abfragen.

Ich kann mir das gerne morgen nochmal anschauen.

Bin heute leider auf dem Sprung.

alles klar - danke
Gruß Harry

Hallo jheinz,

ich habe die gewünschten Werte von Bridge und Lock im JSON-Array.

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.tedee.com/api/v1.15/my/lock",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
   "Authorization: Bearer ".$token,
    "Content-Type: application/json"
  ),
));

Die wesentliche Hürde war der Token.
Danke, dass Du mir so schnell geholfen und mich in die Spur gebracht hast. :+1:

Wie holst Du die Werte ab?
Regemäßig per Skript oder arbeitest Du mit einer Regiservariablen?

Viele Grüße aus dem Unterallgäu
Harry

Hallo jheinz,

Entsperren und Schliessen funktioniert.

Hast Du das Ziehen der Falle realisiert? pull als Befehl funktioniert bei mir nicht.

Gruß Harry

Hallo Harry,

schön dass es funktioniert. Das Ziehen der Falle habe ich nicht realisiert.

Guten Morgen Harry,

hast Du das gelesen:?

Note

When lock has auto pull spring enabled it will also perform pull spring within unlock command. Optional parameter in the request allows to unlock the lock without pulling the spring.

Pull spring in tedee lock

To perform pull spring first make sure lock is in unlocked state then use pull spring command.

Note

When lock has auto pull spring enabled it will also perform pull spring within unlock command. You shouldn’t send additional pull spring command then.