LOQED (Smart Lock) + IP-Symcon + Webhooks

It looks like there is no native support in IP-Symcon for the LOQED Smart Lock. Would it be difficult to integrate LOQED in IP-Symcon using Webhooks?
Integration über Webhooks mit jeder Smart-Home-Plattform oder jedem Gerät
Smart Lock | LOQED - Das cleverste und sicherste Smart Lock.

Hi,

I only took a quick look at your Smart Lock.

It seems that you can use a script with cURL to lock / unlock your Smart Lock.
You also can register a webhook to get the status of your Smart Lock in IP-Symcon.

The best way would be to have a closer look at their API and build a module for your Smart Lock.

Uli

You make it sound easy :grin:

Here is a code example, but will not fit 100% to your needs.

//Send data to endpoint
        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_CUSTOMREQUEST   => $CustomRequest,
            CURLOPT_URL             => $Endpoint,
            CURLOPT_HEADER          => true,
            CURLOPT_RETURNTRANSFER  => true,
            CURLOPT_FAILONERROR     => true,
            CURLOPT_CONNECTTIMEOUT  => $timeout,
            CURLOPT_TIMEOUT         => 60,
            CURLOPT_POSTFIELDS      => $Postfields,
            CURLOPT_HTTPHEADER      => [
                'Authorization: Bearer ' . $accessToken,
                'Content-Type: application/json']]);
        $response = curl_exec($ch);

You also have do define the Variables for $… e.g. $CustomRequest = ‚GET‘;

Open/lock the door when something happens (incoming webhook)

If you want to control your lock from a third-party service or device, you can do this by way of a HTTPS GET call to a URL of LOQED.

The

CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $accessToken, 'Content-Type: application/json']]);

will possible not fit.

So have a look at their documentation and strings they use for the calls here.

Uli

I’ve been able to create „Open, Lock and Unlock“ triggers using IFTTT Webhooks as „Man in the Middle“. I guess if that’s possible, it should be possible without IFTTT too. (But I haven’t got a clue how to do it) :wink:

For the status updates I created a WebHook in IPS with help from some community members (link).

The calls look like this:

Did you register to their API service?

You need your API key and token.

Uli

Hi Uli,

Thank you for your reply.
Yes, I’ve registered to their API service. Above are the URLs which open, lock, and unlock the lock (GET URL). I removed the actual lock_id, api_key, api_token and key_id. I don’t want the whole world to open my smart lock. :grinning:

I will have a look at the weekend.

Uli

1 „Gefällt mir“

If you feel like it and have the time, that would be fabulous!

I think the URL could be constructed using 6 variables:
url_base, lock_id, api_key, api_token, state, key_id

So please try this… I can’t test it, so I am not sure if it will fit to your needs…

<?php

//Change to your needs
$deviceID = '123456789';
$apiKey = 'abcdefghij';
$apiToken = 'klmnopqrst';
$localKeyID = '99999';
$lockState = 'OPEN';

//Don't change!
$customRequest = 'Get';
$endpoint = 'https://gateway.production.loqed.com/v1/locks/' . $deviceID . '/state?lock_api_key=' . $apiKey . '&api_token=' . $apiToken . '&lock_state=' . $lockState . '&local_key_id=' . $localKeyID;
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST   => $customRequest,
CURLOPT_URL             => $endpoint,
CURLOPT_HEADER          => true,
CURLOPT_RETURNTRANSFER  => true,
CURLOPT_FAILONERROR     => true,
CURLOPT_CONNECTTIMEOUT  => 5,
CURLOPT_TIMEOUT         => 60]);
$response = curl_exec($ch);

//Dump the result, only needed for developing
var_dump($response);

Uli

Thanks @ubittner ,

It looks like I have to „URL Encode“ the $apiKey and $apiToken variables. Is there some function that I can use to „URL Encode“ those variables? It’s always possible to „URL Encode“ the variables myself and use those values in the variable, that’s what I did now.
The PHP script ends with „bool(false)“, I guess this is the „var_dump($response)“. If I enter the value of variable $endpoint in an internet browser window the requested action will be executed. The PHP script itself doesn’t trigger anything, not sure if the PHP script should do that. :wink:
Thanks for your assistance!
Dennis.

https://www.php.net/manual/en/function.urlencode.php

$apiKey = urlencode(‚abcdefghij‘);
$apiToken = urlencode(‚klmnopqrst)‘;

This is only to check the response.

Try to play with the parameters and uncomment them:

//CURLOPT_HEADER => true,

The script is only for executing the action.
At the end you have to combine it with a variable like in your other post or creating a module.

Uli

Please try this for the curl part:

//Don't change!
$customRequest = 'Get';
$endpoint = 'https://gateway.production.loqed.com/v1/locks/' . $deviceID . '/state?lock_api_key=' . $apiKey . '&api_token=' . $apiToken . '&lock_state=' . $lockState . '&local_key_id=' . $localKeyID;
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST   => $customRequest,
CURLOPT_URL             => $endpoint,
CURLOPT_HEADER          => true,
//CURLOPT_RETURNTRANSFER  => true,
//CURLOPT_FAILONERROR     => true,
CURLOPT_CONNECTTIMEOUT  => 5,
CURLOPT_TIMEOUT         => 60]);
$response = curl_exec($ch);
curl_close($ch);

Uli

It works! After changing:

$customRequest = 'Get' to $customRequest = 'GET'

and leaving the rest to the defaults.

Perfect, so your next step is to create a boolean variable with an action skript including the script above.

You have to check if your boolean variable is false or true, for open and close.

Uli

Hello @ubittner ,
Thanks for your help so far. I was thinking about creating an Integer variable, with 3 possible values; 0 - Open, 1 - Unlock, 2 - Lock and creating three different php scripts, one for Open, one for Unlock and one for Lock.
I would have to create an action script that triggers the different PHP scripts. What is the best course of action?

Hi Dennis,

this is also possible. You have also to create a switching profile.

SetValue($_IPS[‚VARIABLE‘], $_IPS[‚VALUE‘]);

I would prefer to do it in one Action Script and using the switch method

switch ($_IPS['VALUE']) {
     case 0: # open
        $lockState = 'OPEN';
        break;

    case 1: # unlock
       $lockState = 'DAY_LOCK';
      break;

    case 2: # lock
       $lockState = 'NIGHT_LOCK';
   break;    
}

Then you also need the webhooks for the state…

The premium version is to build a module!

Uli

1 „Gefällt mir“

Thanks for the action script. That was exactly what I had in mind!
Building a module? Isn’t that next level and for users who know what they are doing? I wouldn’t know where to start. :flushed:
I think I know what you’re after using the webhooks for the state. The status (string) and trigger (integer) are not in sync. Is it somehow possible to update the trigger integer variable without creating a chicken/egg problem or infinite loop? The „Open“ action is automatically followed by an „Unlocked“ action. (Another option could be if the integer variable value returns to a „neutral“ position.)

Did you register already an outgoing webhook from Loqed to IP-Symcon? And did you also create a webhook for the incoming status data in IP-Symcon?
So you will get an information if the status of your lock changes.

I would use two variabels:
One for switching
One for the status

From my point of view both must not be synced.
Or you must use a “sender” to split between action and status information.

The control of the lock is the incoming webhook to Loqed, what we did with the curl.

Maybe I can support you with a small module……

Uli