Set GPIO switch as lock for homekit

Hi
I have a GPIO switch that open the gate of my house. I want to set it as a lock.
Usually I use the homekit to control my home.
I saw the Lock Template in home assistant examples, but I didn’t succeed it.
This is my code:

switch: 
 - platform: rpi_gpio
   ports:
    18: relay1
    23: relay2  
    24: relay3
    25: relay4
lock:
   - platform: template   
     name: Gate
     value_template: "{{ is_state('switch.relay4', 'on')}}"  
     lock:     
        service: switch.turn_off   
        target: 
          entity_id: switch.relay4
     unlock:
        service: switch.turn_on 
        target: 
           entity_id: switch.relay4

I can’t see the Gate as a lock in home assistant and can’t see it in home kit.
HELP?

Help us help you, format your post properly.

Can’t understand how to do this 3 dots
‘’’
Using iPhone

did it - using Mac

1 Like

Great! That makes it a lot clearer that your lock indentation is slightly off. Should be:

lock:
  - platform: template   
    name: Gate
    value_template: "{{ is_state('switch.relay4', 'on')}}"  
    lock:     
      service: switch.turn_off   
      target: 
        entity_id: switch.relay4
    unlock:
      service: switch.turn_on 
      target: 
        entity_id: switch.relay4

Other that that I can’t see any issues with what you have.

I can’t see the different between my code and yours

Look at the indentation highlighted in red. Yours:

yours

Mine:

mine

Also I just noticed there are quite a few trailing spaces (dots at the end of the lines). They won’t hurt but are not good practice.

Those dots are the copy paste issues.
I repaired the code as you described- it’s still ain’t working :cry: