Skip to content
Image of TTLock
Template

TTLock

by eReitan ConsultingNo rating yet362 downloads

Content languageEnglish

Description

TTLock is a smart lock platform that powers a variety of affordable smart locks from manufacturers worldwide. These connected smart locks integrate with Loxone to seamlessly automate access management. With this integration, TTLock-enabled smart locks can easily connect to Loxone, allowing you to take full advantage of universal access control features for managing access to your properties.

You can communicate directly with a Wi-Fi door lock or via a gateway that connects to the door lock using Bluetooth. Additionally, you can use a door sensor to monitor the open/close status of the door. The TTLock Bluetooth door sensor can be used for this purpose, communicating through the gateway, or you can simply use Loxone door and window contacts.

- TTlock Smart Door Lock Bluetooth or Wifi - TTLock G2 Wifi Gateway for Smart Door Lock Bluetooth - TTLock G3 Gateway With RJ45 Ethernet Port for Smart Door Lock Bluetooth - TTLock DS2 Door Sensor

Setup:

1. Add all locks and gateways into the app. 2. Ensure that you can use your mobile app to remotely control your door lock. 3. Register a developer account on the door lock supplier's website.(Sciener Open Platform) 4. Once your developer account is approved, you will receive a "client_id" and "client_secret." 5. To find lock_id you need to open TTlock APP, settings, basic, MAC/ID 6. 7. Edit the Program code and set the client_id, client_secret, username, password parameters and lock ID. Password must be md5 encrypted (MD5 Hash Generator). 8. Add this into the PicoC program in TTLock example file. 9. Then you will obtain an access token and refresh token. 10. Access token returned will expire in seconds of "expires_in"(Default validity of 90 days),request with expired access token will get 10004 error code.

The Loxone Miniserver has limited support for directly parsing JSON data. To work around this, you can save the JSON response as a text file and extract specific values using virtual HTTP virtual inputs. Remember to update the IP address, username, and password for the files stored on the miniserver, and add this URL for the virtual inputs.

http://username:password@miniserver_IP/dev/fsget/user/common/TTLock_lock_details.txt

Since Loxone does not support OAuth2 authentication, a PicoC program has been created to receive the access token and refresh token from the cloud service.

Documentation: Open API

Inputs and outputs · 4

NameTypeCommandUnit
Lock battery statusVirtualInHttpelectricQuantity":\v%
LockIdVirtualInHttplockId":\v<v>
lockUpdateDateVirtualInHttp"lockUpdateDate":\v<v>
DateVirtualInHttpdate":\v<v>

FAQ

No questions have been answered yet.

Ratings and comments

No ratings or comments yet.

Questions and answers

  1. Is there a way to have more details on this integration?

    Open

    It is a good option but the details are not sufficient to make it work, is there a way to get more detailed description or step by step on this please. Thanks Robert

    1 reply

    1. How far did you get in setup steps 1–7, and which points do you need more explanation on?

  2. More details to this integration?

    Open

    I did everything up to step 6. I got all the information I need to replace in your TTLock _example.Loxone file, meaning the following information client_id client_secret username password lock_id

    Since the Loxone file opens separately in a different config file, I copy/pasted all in my config in a page called TTLock same as yours. The rest is where I got stuck, meaning creating the memory flags, and how to finish it up, plus http://username:password@miniserver_IP/dev/fsget/user/common/TTLock_lock_state.txt does not return any value for me. In other words step 6 and 7 to finish. I am sure all the other steps are done correctly since I tested them with Postman app and it communicates with the lock.

    My other questions: 1- Do I need 1 developer account per lock or account with 2 locks or for all our locks? I only have 1 2- I know that the token needs to be refreshed every 2 months otherwise the Loxone-Lock stops working. Is that done through your script? 3- Where and what is TTLock_lock_details.txt

    Thank you for your help.

    1 reply

    1. Hi Please contact me by mail, and I will try tp explain, and update the description if needed.

      br eirik

  3. Has anyone managed to launch the integration?

    Open

    Completed positions 1-6 link to the screenshot: https://disk.yandex.ru/i/4InQpJm_iEmP2w

    4 replies

    1. According to picture you have not added LOCK_ID into the picoC program.

    2. Hello. Yes, you're right, I didn't add a lock ID. Now I've added it, but the mini server stops the script from working. link to the screenshot: https://disk.yandex.ru/i/UBlt4Vq1PucTrA

    3. // *** PROGRAM DISABLED *** // This PicoC program caused an error. // Please find and correct the error and remove these three comment lines to enable this PicoC program again. //Password needs to be MD5 encrypted char* client_id = "-------------"; char* client_secret = "1dd----------"; char* username = "direktor"; char* password = "874246------"; int lock_id = 1--------; //---------------------------------------------------------- // do not change below this line (v1.0.1) //----------------------------------------------------------

      char buffer[65536]; int length = strlen(client_id) + strlen(client_secret) + strlen(username) + strlen(password) + 45;

      STREAM* stream = stream_create("/dev/tcp/euapi.ttlock.com/80", 0, 0); char* cmd = "POST /oauth2/token HTTP/1.1\r\nHost: euapi.ttlock.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n"; sprintf(buffer, cmd, length);

      stream_write(stream, buffer, strlen(buffer)); sprintf(buffer, "client_id=%s&client_secret=%s&username=%s&password=%s\r\n", client_id, client_secret, username, password); stream_write(stream, buffer, strlen(buffer)); stream_flush(stream);

      int cnt = 0; int total = 0;

      do { cnt = stream_read(stream, &buffer[total], 65536 - total, 5000); total += cnt; } while (cnt > 0 && total < 65536);

      stream_close(stream);

      // Extracting expires_in char* expires_in_str = strstrskip(buffer, "\"expires_in\":"); if (expires_in_str != NULL) { // Convert the value to an integer int expires_in = atoi(expires_in_str); setoutput(0, expires_in); // Output expires_in as integer } else { setoutput(0, 100); // If expires_in is not found, return 100 }

      // Extract uid char* uid_str = strstrskip(buffer, "\"uid\":"); if (uid_str != NULL) { // Convert the value to an integer int uid = atoi(uid_str); // Safely extract uid (entire number) setoutput(2, uid); // Output uid as integer } else { setoutput(2, 100); // If uid is not found, return 100 }

      // Extract openid char* openid_str = strstrskip(buffer, "\"openid\":"); if (openid_str != NULL) { // Convert the value to an integer int openid = atoi(openid_str); // Safely extract open_id (entire number) setoutput(3, openid); // Output uid as integer } else { setoutput(3, 100); // If uid is not found, return 100 } // Extracting refresh_token char* refresh_token = strstrskip(buffer, "\"refresh_token\":\""); int pos_B = strfind(refresh_token, "\"", 0);

      // Extracting access_token char* access_token = strstrskip(buffer, "\"access_token\":\""); int pos_A = strfind(access_token, "\"", 0);

      refresh_token[pos_B] = 0; setoutputtext(1, refresh_token);

      access_token[pos_A] = 0; setoutputtext(0, access_token); setoutputtext(2, client_id); setoutput(1, lock_id);

      sleep(43200000); // Pause for 12 hours }

    4. The postman token is coming, the team is working

Report this entry

Report abuse

You have to be logged in to report an entry. Log in