Gate lock and homekit

I have one gate lock similar to this one and I connected one Shelly1 to send the input to unlock the gate.

Everything works fine.

My actual integration on HomeAssistant (which works fine) on switch.yaml is:

- platform: mqtt
  name: "Gate"
  state_topic: 'shellies/Gate1/relay/0'
  command_topic: 'shellies/Gate1/relay/0/command'
  availability_topic: 'shellies/Gate1/online'
  unique_id: 'Gate1-relay-0'
  payload_on: 'on'
  payload_off: 'off'
  payload_available: 'true'
  optimistic: false

The issue is when I include it in HomeKit, the device is seen as a switch and so, using Siri, I can’t say “open the Gate” but I have to say “switch on the Gate”.

How should I setup the device in order to make it work as a gate lock on Home.app?

Should I define somehow the device class? Should I use a template? How the template would be built?

Thank you!

1 Like

Use a cover, this is the point of it Cover - Home Assistant

Hello @jorhett thanks for the input! Should I remove the configuration from switch.yaml and reconfigure the device as cover? Yestereday I was looking at that documentation but I couldn’t understand if it’s something you do on top of your existing configuration (something like templates).

No your underlying (real) switches remain in the configuration. The cover is a wrapper around the switches that provide the expected controls – it “covers” your switch and sensor with a garage door interface. Sorry I sent you to the general doc – this is the doc that goes over your use case: Template Cover - Home Assistant. Ignore the mentions of “script” and just trigger your switch :wink:

This thread contains some good examples Add Conditional to Cover Garage Door Controller GD00Z-4

@jorhett as per your suggestion I created the following cover configuration:

- platform: template
  covers:
    garden_gate:
      device_class: gate
      value_template: "{{ is_state('switch.gate', 'true') }}"
      friendly_name: "Garden gate"
      open_cover:
         service: switch.turn_on
         target:
           entity_id: switch.gate
      close_cover:
         service: switch.turn_off
         target:
           entity_id: switch.gate

As far I can see, everything seems to be fine enough now on HomeAssistant (I mean I can click on a button and get the proper service call) but the status on Homekit is inconsistent.

Since the lock is stateless (there is a link to a photo in the first post), I can’t get the “open” state or the “opening”/“closing” ones (it’s not a garage gate, it’s just a simple garden door).

When I trigger the call from HomeAssistant or from the iOS Home app the status of the device will get stuck in “opening” (or “closing” if I try to click once again) forever. The only way to reset it is to reboot HomeAssistant (or the homekit bridge I guess).

How should I play with the value_template in order to get the proper status update?

One last note: the shelly1 is configured as a push button with an auto turn off timer after 0.2 seconds (the locking device needs just a short timed current as input to exectute the action). This works fine if I use the switch.gate button but as said in the first post, I am forced to use “switch on the gate” by Siri…

Hello, we have already met on Matrix. As it is a German community, I am reaching out to you here. As your Shelly is in a “push button” mode and turns off after some time, the status of the garage door in HomeKit is inconsistent. You would need an additional helper e.g. “input Boolean helper” and or a sensor that shows the current open and closed state.

Maybe you reach out to these guys here. They are having a similar setup as yours and I am sure they can help you.

Hello @SmartLiving.Rocks and thanks for reaching me out here. I have readend the post you linked but as far as I can see the OP decided to fork and edit the cover code inside homeassistant to make it work.
I would like to avoid that.

Yes, my switch is a “push button” (the shelly1 is configured to reset the command after 0.5s). I don’t obviously have different states as no door sensor is installed on the gate (it’s the garden gate, it make no sense to me to check the real status but I still want to be able to open it when needed).

The “switch” configuration works fine: the status is updated accordingly (I see the device in “green” for 0.5 seconds and after that I see it in grey once again on both HA and HomeKit) but the cover seems to be a little bit different unfortunately.

OK cool. But what do you want to do to get it working then?

Hello @SmartLiving.Rocks sorry for the delay. My hope is to find out how to define the correct status template inside the cover configuration. If that will not be the case, I think I will switch back to the “switch” definition which works fine except for the Siri wording.

Yesterday I tried to push on the topic and managed to create a fake boolean input sensor. I created two automation scripts in order to change the status when the cover is open (after two seconds the bool is reset to False from a second script). If I play with this boolean variable, the HomeKit cover status is properly updated and shown on the Home App.

The (strange) issue I have now, is that I can’t control the switch anymore. I mean… when I try to call the open_cover service no switch is triggered / no mqtt command is issued.

The code is the following:

Inside cover.yaml I have:

- platform: template
  covers:
    garden_gate:
      unique_id: "Garden Gate"
      device_class: gate
      value_template: "{{ false if is_state('input_boolean.gate_fake_sensor','off') else true }}"
      friendly_name: "Garden Gate"
      open_cover:
           service: switch.turn_on
           target:
             entity_id: switch.gate
      close_cover:
           service: switch.turn_off
           target:
             entity_id: switch.gate

While, the switch.yaml device (it’s a shelly1) is configured as:

#Garden Gate
- platform: mqtt
  name: "Garden Gate"
  state_topic: 'shellies/GardenGate/relay/0'
  command_topic: 'shellies/GardenGate/relay/0/command'
  availability_topic: 'shellies/GardenGate/online'
  unique_id: garden_gate
  payload_on: 'true'
  payload_off: 'false'
  payload_available: 'true'

In order to complete the code report, my boolean input variable is described as the following:

gate_fake_sensor:
  name: "Garden Gate - Fake Sensor"
  icon: mdi:gate

While the automations I wrote are the following two:

- id: '1653511856618'
  alias: Garden Gate Fake Sensor - Reset if True
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_boolean.gate_fake_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 2
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.gate_fake_sensor
  mode: single
- id: '1653519204938'
  alias: Garden Gate - Fake Sensor to True
    (Duplica)
  description: ''
  trigger:
  - platform: state
    entity_id:
    - cover.garden_gate
    from: closed
  condition: []
  action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.gate_fake_sensor
  mode: single

I am not sure what I am missing now since everything seems to be as suggested by the documentation…

Any idea?

The yaml code check is ok and I tried already to reboot the homeassistant service.

Hi there,

I stumbled upon this thread when looking to properly indicate my gate status in homekit instead of showing the switch state that turns on similar to your case for just a second or so. Thanks all for the inputs.

I would like to also raise your awareness to a very different approach to your problem, if you only want Siri to act nicely on your preferred trigger words but you don’t care of the actual state of your door/lock, then I would use one of these methods (this is how my system is currently set up):

  • Roll back your HA setup to the simple switch behaviour with auto off after 0.5s
  • Option A: Create a shortcut in Apple Shortcuts, where the shortcut name is your wanted Siri text
  • Option B: Create a scene in Apple Home, where the scene name is your wanted Siri text (I prefer this one as sometimes Siri asked for confirmation on the shortcut version)

Thanks @miklosbard for your suggestions. I will keep them in mind but as long as I can fix it inside homeassistant I would prefer. The less configuration I have to do on every Apple device the better (at home we have different accounts).

Right now, the issue is the open_cover command does nothing. I had no time to enable the debug but the code should be ok. :frowning:

Good luck then and keep us posted :slight_smile:

We also use separate Apple accounts with the family, but the Scene itself is connected to the Home, not to the individual’s accounts, I think that was also a reason why I ended up doing that instead of Shortcuts.

Of course if you have your HA setup shared with people who don’t have access to the same Apple Home, then it’s a different issue :slight_smile:

Thanks @miklosbard. Do you have any idea why the open_cover of my code is not working? How can I debug a cover template?

      open_cover:
           service: switch.turn_on
           target:
             entity_id: switch.gate

For the folks coming here looking for a solution, I managed to make it work this way:

  1. I created a fake boolean (input_boolean.yaml):
fake_gate_status_bool:
  name: "Fake Gate Status"
  icon: mdi:gate
  1. I created a cover this way (cover.yaml):
#Gate
- platform: template
  covers:
    portone_giardino:
      unique_id: "Gate"
      device_class: gate
      friendly_name: "Gate"
      value_template: "{{ false if is_state('input_boolean.fake_gate_status_bool','off') else true }}"
      position_template: "{{ false if is_state('input_boolean.fake_gate_status_bool','off') else true }}"
      open_cover:
         service: script.open_gate
      close_cover:

Note the close_cover command, it’s mandatory to have but you can leave it empty.

  1. I had to create the script to control the switch (script.yaml):
apri_portone_giardino:
  sequence:
    # This is Home Assistant Script Syntax
    - service: switch.turn_on
      target:
        entity_id: switch.portone_giardino
    - service: input_boolean.turn_on
      target:
        entity_id: input_boolean.portone_giardino_fake_finecorsa
  1. Finally, I had to create an automation to flip the boolean when the switch is on, wait two seconds and switch it off once again. I don’t have the yaml for this since I created it on NodeRed (that’s my place for automations, you could use HA).

This way on HomeKit I can see the open/close status (it will always roll back to close) and the opening/closing transitions.

TL;DR: I have a gate with no sensors to check if the gate is open or close. I can open it with a pulse command and nothing else. I wanted to manage it as a cover (gate) instead of a switch on HomeKit. I had to create a fake sensor to tell the status to the cover template.

Hope it helps!

Emanuele,
I am trying to replicate your steps, but I am stuck in the automation
Can you share a little more info on it?
Thank you

1 Like

Can share which gate lock you interested in? Very interested in reproducing this at the house.

gate lock similar to this one

Yeah that doesn’t help with model and such.

Hello @Nodomw what would you like to know? I am using HomeAssistant to create the sensors and NodeRed to manage the logic.