GLUE lock working in Homey

To get GLUE smart lock working in Homey you can do this by using the GLUE api and calling this with two (lock and unlock) Homeyscript app that you then uses in a flows.

First you have to you need to create an api-key from GLUE api this is done by going to this page here and add this script and press run
remember to change <user>:<pass> to your user and password for the glue lock without the <>.

curl --location --request POST 'https://user-api.gluehome.com/v1/api-keys' --header 'Content-Type: application/json' -u <user>:<pass> --data-raw '{ "name": "My Test Key", "scopes": ["events.read", "locks.read", "locks.write"] }'

After this you will now have the api-key in the replay to the right in the page.
Copy this and replace <api-key> in this script and past and run this at the same page.
You will now have the lock-id

curl -L -H "Authorization: Api-Key <api-key>" https://user-api.gluehome.com/v1/locks

Then you have all you need to make the 2 homeyscript in homey to make the lock and unlock scripts.

So go to homeyscript and add a new script called unlock and past this
Remember to replace <lock-id> with your lock-id from before and <api-key> with your api-key from earlier.

fetch('https://user-api.gluehome.com/v1/locks/<lock-id>/operations', {
    method: 'POST',
    headers: {
        'Authorization': 'Api-Key <api-key>',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({"type":"unlock"})
});

Then add one more script and call this lock and past this
Remember to replace the lock-id and api-key here also.

fetch('https://user-api.gluehome.com/v1/locks/<lock-id>/operations', {
    method: 'POST',
    headers: {
        'Authorization': 'Api-Key <api-key>',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({"type":"lock"})
});

Then you can call the scripts in any flow you would like to lock and unlock your GLUE lock.

4 Likes

Thank you! Is there any way to update the status of the lock after the script has been run?

Sadly not. There is no features in the API for that.

1 Like

Hi Kjetil
Thx for this but i have some problem.
when i trying to run script it says Returned: undefined

I dont know if i copy api key and id in the right way.
but i remove <>and just type id and API without “”

Hi, I had the same issue but got it working after a couple of tries.

Hi Niklas
can you tell how you write it ?
do you remove <> and do you leave " " signs ?

so it looks like this ?
‘Authorization’: ‘Api-Key “xxxxxxxxxxxxxxxxxxxxx”’,

No like this
'Authorization': 'Api-Key xxxxxxxxxxxxxxx'

Thx Kjetil
But now i have testet 20 times. and i cant get it to work.
I dont know if it is becouse they have made a update from glue.
if you lock out on app you need to use phone number to login and not e-mail as user.

any good ideas ? it keeps saying this when i make the test.
image

So sorry it works now.Awesome script. Thx again Kjetil

1 Like

Great that it works and hope you get it to work with a flow also👍

Hi @Kjetil_Vert

I am stuck on Script Success / Returned: undefined…
Can you help me?

Thanks!

As I have not seen your script I have no possibility to support you.

As this is working for all it have to be a copy past error

@Kjetil_Vert
Sorry it’s working now!

I get the following error when trying to get the api keys via curl:

{“correlationId”:“166c3a8c”,“code”:50003,“title”:“Limit of 10 api keys reached.”,“status”:400,“detail”:“Limit of 10 api keys reached.”,“instance”:"/v1/api-keys"}

A big thank you, who wrote and shared this!!!

1 Like

I get it to work lock the door, but not unlock it. Why not open?

I am :100: this is a copy past error as this is working 100% for me for more then a year and on 2 locks at home.

The only change between lock and unlock script is the word lock and unlock :metal:

I can confirm this works. But I’ve noticed that after a while, the unlock stops working and just initiates the lock, i.e. I can hear the little motor running but it doesn’t rotate to open. Any idea what could be causing this? Both (lock and unlock) worked for my initial tests, but now it stopped working.

Hi I dont know what is wrong with your lock but it sounds like this has nothing to do with the script if it runs and the motor is moving.

I have this running at home and I only have a problem some times if the hub is offline and all I have to do then is cute the power and give it power again.

But as i have this now running daily for over 2-3 years I know the script is working 100%

And after a bit more research on my part, I did notice that your script works perfectly indeed. I had trouble identifying the data from the Aqara push buttons. Was almost no documentation and I had to figure out the hard way exactly what was incoming when pushing. But as soon as I did, everything worked perfectly. Great job in the script!

1 Like