Any chance of getting a full write up on how this is done with the new api? Does it run native in HA or does it need Homebridge?
/Marcus
What’s different between those two?
Probably not
Does anyone know of a way to take the curl messages sent by the homebridge plugin to the new API and make a simple HA switch to send those commands? Alternatively, move the glue lock homebridge accessory over to HA?
My goal is to run automations through HA / NodeRED however I do not own any iDevices to go through HomeKit.
When I discovered that my glue locked stopped working today I investigated the homebridge plugin and eventually got the curl commands to work. I think you need to create an api-key as described in the plugin.
Anyway, this is the resulting glue lock curl command line switch w/o support for reading state adapted from GitHub - GlueHome/homebridge-plugin: Homebrige plugin to integrate with Glue ecosystem.
Create/fetch <api-key> with glue <user>:<pass> according to plugin README:
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"] }'
Fetch <lock-id> using created <api-key>:
curl -L -H "Authorization: Api-Key <api-key>" https://user-api.gluehome.com/v1/locks
Test operation <op>=lock/unlock on <lock-id>:
curl -L -H "Authorization: Api-Key <api-key>" -H 'Content-Type: application/json' -d '{"type":"<op>"}' https://user-api.gluehome.com/v1/locks/<lock-id>/operations
Be sure to replace values in <> with your own values and append "-v" to curl command to get more info on failure.
My switch:
# In secrets.yaml you will need to escape "" in json:
# glue_command_on: "curl -L -H 'Authorization: Api-Key <api-key>' -H 'Content-Type: application/json' -d '{\"type\":\"lock\"}' https://user-api.gluehome.com/v1/locks/<lock-id>/operations"
# glue_command_off: "curl -L -H 'Authorization: Api-Key <api-key>' -H 'Content-Type: application/json' -d '{\"type\":\"unlock\"}' https://user-api.gluehome.com/v1/locks/<lock-id>/operations"
- platform: command_line
switches:
friggebod_lock:
friendly_name: "Olåst <-Friggebod-> Låst"
command_on: !secret glue_command_on
command_off: !secret glue_command_off
I created a rest sensor to go with the command_line switch in the previous post:
# Glue lock rest sensor, secrets:
# glue_resource: "https://user-api.gluehome.com/v1/locks/<lock-id>"
# glue_auth: "Api-Key <api-key>"
- platform: rest
resource: !secret glue_resource
name: friggebod_lock
method: GET
headers:
Authorization: !secret glue_auth
json_attributes:
- description
- batteryStatus
- lastLockEvent
- connectionStatus
value_template: "OK"
- platform: template
sensors:
friggebod_lock_last_event:
friendly_name: Last friggebod lock event
value_template: "{{ state_attr('sensor.friggebod_lock', 'lastLockEvent')['eventType'] }}"
friggebod_lock_battery:
friendly_name: Friggebod lock battery
value_template: "{{ state_attr('sensor.friggebod_lock', 'batteryStatus') }}"
friggebod_lock_status:
friendly_name: Friggebod lock connection status
value_template: "{{ state_attr('sensor.friggebod_lock', 'connectionStatus') }}"
Tusen tack bengtj! This worked for me, too.
does this still works?
Just tested and it still works to lock/unlock using hass. Don’t know if anything has changed when creating api keys. It has worked since my post so I haven’t touched anything…
i try , maybe i’ll be back
Hej!
I have recently been trying to move off Homebridge to HA, and the Glue Lock was the only device that wasn’t supported natively.
I am trying to figure out how to include the code snippets you shared previously in to the “confirguratio.yaml” I assume?
Do you have a “full version” of the snippet when I can replace my respective values?
If not happy for you to point me to a few places to get going.
Thanks in advance!
The first snippet, after “My switch:”, is from “switch.yaml” that is included from “configuration.yaml” like this:
switch: !include switch.yaml
Note that including “switch.yaml” will actually create a “switch:” scope so if you put it directly into configuration.yaml without including you will need to prefix with “switch:” and indent accordingly.
The second snippet is from “sensors.yaml” that is included the same way. But you do not actually need that part to lock/unlock. It is only needed if you want to read information like battery. Start by getting lock/unlock working.
The snippets look like what I actually have in the files. But you will need to fill in “secrets.yaml” with the lacking values, these will then fill in those "!secret " placeholders. See Storing secrets - Home Assistant
So for lock/unlock to work you will need to put these lines in secrets.yaml with <>-stuff replaced with your values as well as the first snippet as a switch:
glue_command_on: "curl -L -H 'Authorization: Api-Key <api-key>' -H 'Content-Type: application/json' -d '{\"type\":\"lock\"}' https://user-api.gluehome.com/v1/locks/<lock-id>/operations"
glue_command_off: "curl -L -H 'Authorization: Api-Key <api-key>' -H 'Content-Type: application/json' -d '{\"type\":\"unlock\"}' https://user-api.gluehome.com/v1/locks/<lock-id>/operations"
Finally got around to figuring this out (and it took a little work), your instructions were super clear!
Thank you so much! I can finally get off Homebridge and move to HA fully! Now I need to sell a RPi 4 or maybe do something else with it.
Hej!
So recently I have had the rest sensors become unavailable. This has led to my template lock being unlocked (not good), then locked when the sensor becomes available again (I guess because the last_event sensor goes from unavailable to remoteLock).
Anyone have any idea how I can edit my template lock to ensure that the lock stays locked even if the sensors become unavailable?
I added is_state(‘sensor.hallway_front_door_lock’,‘unavailable’) which didn’t help.
Below is the template sensor in my config
- platform: template
name: Lock
value_template: "{{ is_state('sensor.hallway_front_door_lock_last_event', 'remoteLock') or is_state('sensor.hallway_front_door_lock_last_event', 'manualLock') or is_state('sensor.hallway_front_door_lock','unavailable') }}"
lock:
service: switch.turn_on
target:
entity_id: switch.hallway_front_door_lock
unlock:
service: switch.turn_off
target:
entity_id: switch.hallway_front_door_lock
Hi , I am not sure what I am doing wrong , I want to create the API key , so I enter the curl command in the terminal with my username and password filled in , I hit enter and then nothing , it starts a new line as if it accepts the command but I don’t see any file that is created etc?
Not sure how to do so via terminal.
I used the Postman app to make the request from my machine, that way everything stays local at least and Im not using an online service giving my password / API keys away.
https://reqbin.com/ is such an online tool, but again would recommend using Postman on your machine to make the POST call.
Ah perfect , I got the switch part working ,thank you so much