LOQED (Smart Lock) + IP-Symcon + Webhooks

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

Hi Dennis,

I created a module, you can install it via the module control under core instances.

You will find the module soon via the module store.

Also you need at least Symcon Version 6.0 or higher.
You can control the smart lock, status updates are not included yet, but this will be our next step.
There is also no documentation at the moment, but I am sure you know what to do.

My next steps for you:
A manual status request should be possible:
Status. ATTENTION: you can only ask the status a few times per day, until you are rate limited

Can you check if you can get the right url and I need the result information of that.
So in your script maybe you have to replace „OPEN“ with „STATUS“, but I am not sure, var_dump is your friend for the result.

For the outgoing webhook (Loqed → Symcon) you need a valid Symacon subscription. Do you have one?

Enjoy your weekend

Uli

1 „Gefällt mir“

Hi @ubittner ,

I had a good weekend, thanks! I hope you’ve had a good weekend too!
It also explains explains the late reply, I wasn’t at home. :wink:

Right now I have 2 working PHP scripts, one for the actions, created with your help, and one for the status updates, using the outgoing webhook. Maybe the script using the outgoing webhook gives you the needed information?
I will install the module right away!

Update: I’ve installed and tested the module. All commands are executed succesfully.

My idea is on the first creation of the instance we don‘t know the status of the lock.
So therefore we must get it manually.
For upcoming status events we could use the webhook for status updates.

Uli

https://app.loqed.com/API/lock_status.php?api_token=[API_Token]&lock_id=[LOCK_ID]

I’'ve removed the API token and the Lock ID from the URL. „Lock ID“ is a new value, not yet defined in the module. „Device ID“ in the module is called „Lock ID (old)“ in the LOQED documentation.
I think we can confirm that the „status“ URL is different than the „command“ URL. :wink:

That differs from the documentation…

Anyway what is the result of that url?

Maybe it is a json… I need the data to see the structure of it.

Uli