Script needs to appear as a Lock in HomeKit

Newbie that has just converted from Homebridge and Home Assistant is so much quicker!

I’ve created a Script which which uses the google assistant sdk to unlock a Gainsborough door lock which isn’t compatible with much more than Google and Alexa.

The Script appears in HomeKit, but it appears as a switch/light/fan.

Has anyone got any guidance on how I can present it to HomeKit as a Lock instead so I can tell Siri “unlock the door” rather than “turn on the door”?

I looked into Template Locks but haven’t been able to get that to work.

Appreciate any help!

Can you make a Template Lock - Home Assistant?

Hi Pieter, thanks for taking the time to come back to me.
I have the following but it doesn’t seem to execute the script.
Like I said, I am new to the Home Assistant world.
My current script to unlock the door is UnlockFrontDoor

lock:
  - platform: template
    name: "Door"
    value_template: "{{ is_state('script.UnlockFrontDoor', 'on') }}"
    lock:
      service: script.turn_on
      target:
        entity_id: script.UnlockFrontDoor
    unlock:
      service: script.turn_on
      target:
        entity_id: script.UnlockFrontDoor
        

We need to see that script, but you probably don’t want to call the same script for locking and unlocking. A script is only on while running. Do you have a way of knowing the lock’s state?

Hi Pieter,

The lock is a Gainsborough Trilock Freestyle. In Australia it’s a good front door lock but the smarts to it are average.
The only way I have found that I can interact with it through Home Assistant is through a Google SDK command as the lock connects to Google and Alexa. I am a big HomeKit user.

So this is the Unlock script. I could use a similar script to ask Google SDK if it’s locked. Note that the lock is set to auto lock after 2mins anyway so assuming its always in the locked state is fine. Thats why I had unlock for both states.

alias: UnlockFrontDoor
sequence:
  - service: google_assistant_sdk.send_text_command
    data:
      command:
        - Unlock the front entry door
        - "1234"
icon: mdi:account
mode: single

Got it working!
The HomeKit lock flicks to unlock and then back to lock which is kind of the right behaviour because the door will auto lock.

I realised my script name was different to what I named it!

This worked.

lock:
  - platform: template
    name: "Door"
    value_template: "{{ is_state('script.new_script', 'off') }}"
    optimistic: true
    lock:
      service: script.turn_on
      target:
        entity_id: script.new_script
    unlock:
      service: script.turn_on
      target:
        entity_id: script.new_script

Thanks again Pieter!!!

1 Like