LOQED (Smart Lock) + IP-Symcon + Webhooks

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

string(437) "HTTP/1.1 200 OK
Date: Mon, 28 Feb 2022 11:05:16 GMT
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000; preload
Content-Length: 211
Content-Type: text/html; charset=UTF-8

{"id":"LOCK_ID","bolt_state_numeric":2,"bolt_state":"day_lock","lock_online":1,"bridge_online":1,"battery_percentage":89,"battery_type":0,"guest_access_mode":0,"twist_assist":0,"touch_to_connect":1}"
string(437) "HTTP/1.1 200 OK
Date: Mon, 28 Feb 2022 11:05:16 GMT
Server: Apache/2.4.38 (Debian)
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000; preload
Content-Length: 211
Content-Type: text/html; charset=UTF-8

{"id":"LOCK_ID","bolt_state_numeric":2,"bolt_state":"day_lock","lock_online":1,"bridge_online":1,"battery_percentage":89,"battery_type":0,"guest_access_mode":0,"twist_assist":0,"touch_to_connect":1}"

I’ve replaced the lock ID value with „LOCK_ID“

  • Status. ATTENTION: you can only ask the status a few times per day, until you are rate limited. Instead of asking for the status, you should implement a webhook that calls your server, so you are updated as soon as something changes, without polling. It returns the following JSON keys:
    • id (lock id)
    • bridge_online (1 if bridge is online, otherwise 0)
    • battery_percentage
    • battery_type (0 = Alkaline, 1 = NiMH, 2 = Lithium (non-rechargable))
    • bolt_state_numeric (0 = unknown, 1 = open, 2 = day_lock, 3 = night_lock)
    • bolt_state (unknown, open, day_lock, night_lock)
    • guest_access_mode (1 if enabled, 0 if disabled)
    • twist_assist (1 if enabled, 0 if disabled)
    • touch_to_connect (1 if Touch to Open 500-meter restriction is removed, 0 otherwise)

Thanks, I will have a look at the result this evening….

Can you control the lock with my module without errors?

Uli

Yes, the „Open“, „Unlock“ & „Lock“ commands work without problem using the module you created.

There is a new version online. Please update. I added the device states. In the instance configuration in the action area you will find a developer area and in this an update button for manual update.

Please let me know if this update button works. Before you press the button please open the debug for the instance to see further information and also the message tab.

I will add the outgoing webhook for automatic updates within the next days or next weekend, because my time is limited for today.

Uli

Do we need both or only the „new“ lock_id ?

Uli

Good Morning Dennis,

another new version (1.0-3 20200301) is online. Please update. This version includes now the outgoing webhook for automatic updates.

It was coded quick and dirty, so please test it.

Uli

Good morning @ubittner ,

Thank you so much for your help. We need both the „Lock ID“ and the „Lock ID (old)“.
„Lock ID (old)“ is needed for the „command“ URL, „Lock ID“ is needed for the „status“ URL.
I just installed the updated module and will get back with the results.

I think the outgoing webhook is not updating the status. Is there a way I can test the outgoing webhook? The URL used in the module for the outgoing webhook looks a bit different than the URL I’m using for the outgoing webhook php script. It prepends username & password or something to the URL I’m using.

Hi Dennis,

you have to use the web hook which was generated by the instance. It is displayed in the action area.
Please copy this and use it for the outgoing webhook on the Loqed portal for testing purpose.

You can test it using Postman, but you also have to use the generated webhook.

If you delete the instance, the webhook is also deleted. So if you create a new one, a new webhook will be created and you have to update it in the Loqed Portal.

Did the single update (update button in the action area) works?

Uli

Hello Uli,

The single update works as expected, the outgoing webhook doesn’t, I used the URL shown in the module.
The „old“ outgoing webhook PHP script still works. (It is possible to add multiple webhook URLs at the LOQED webhook service/portal)

Do you have a log on the Loqed site?

What information does the debug of the instance show, if you control your smart lock?

The outgoing webhook is only initiated if the state of the lock changes.

Your connect control is active?

Maybe the user and password may be a problem…

Uli

I don’t know, you have to ckeck it by yourself.

Uli

This is the php script I use for the outgoing webhook:

<?php
// STATUS LOG
IPS_LogMessage("WebHook IPS", print_r($_IPS, true));
IPS_LogMessage("WebHook RAW", file_get_contents("php://input"));

// WebHook RAW
$LOQED_JSON_Data = file_get_contents("php://input");

// Parse JSON Data
$LOQED_JSON_Data_Array = json_decode($LOQED_JSON_Data, true);
$value1 = explode(',', $LOQED_JSON_Data_Array['value1']);
$value1_array = array();
foreach($value1 as $v){
    $t = explode(":", $v);
    $value1_array[trim($t[0])] = trim($t[1]);
    }
$state = $value1_array['State'];

// List $value1_array
//print_r($value1_array);

// Set LOQED Status
SetValue(15295,$state);
?>

The outgoing webhook sends the following JSON data:

01-03-2022 10:03:03 | WebHook RAW          | {"key_name_user": "", "key_account_email": "", "requested_state": "NIGHT_LOCK", "event_type": "STATE_CHANGED_NIGHT_LOCK", "value2": "IP-Symcon", "key_name_admin": "IP-Symcon", "value1": "LockID: XXXX, KeyID: X, State: NIGHT_LOCK", "value3": "", "key_account_name": "", "key_local_id": X, "lock_id": XXXX}
01-03-2022 10:03:14 | WebHook RAW          | {"key_name_user": "", "key_account_email": "", "requested_state": "DAY_LOCK", "event_type": "STATE_CHANGED_LATCH", "value2": "IP-Symcon", "key_name_admin": "IP-Symcon", "value1": "LockID: XXXX, KeyID: X, State: DAY_LOCK", "value3": "", "key_account_name": "", "key_local_id": X, "lock_id": XXXX}

It wasn’t a question, it was a confirmation. :wink:

I’ve sent you the debug log privately.