Automatically unlock your door when getting in bluetooth range

My new Switchbot Lock Pro doesn’t have an auto-unlock (yet) like for example Nukis have, which was quite a bummer for me. So I thought about creating my own version of the auto-unlock, including Telegram notifications and bluetooth presence detection with Bluetooth-Proxies. The automation is set up, so that you can easily add all users of your Home Assistant instance to it, by adding more automations with more persons.

Prerequisites

The automation works like this:

  1. You enter a specified geozone (or optionally, you are marked as “Home” by e.g. a wifi-tracker)
  2. A Telegram notification is sent out, that the unlocking automation started. If this is a misfire, you can cancel it directly from the notification
  3. A specific bluetooth proxy notifies that you are close to it
  4. The door gets unlocked

To make this work, there is some configuration needed:

  • The bluetooth proxy should have the correct Area attached
  • Set up the companion app to transmit bluetooth beacons See here. I think this is only necessary for Android, since iOS always transmits iBeacons
  • The blueprint uses Bermuda to get the Area of your phone.

Telegram Notifications

Only if you want telegram notifications (highly recommended):

Blueprint

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

The blueprints code is here:

blueprint:
  name: Automatic door unlock
  description: >-
    Automatically unlock the door, when the selected person first enters the specified
    zone and afterwards gets close to the bluetooth range of a bluetooth proxy.

    Prerequisites:
      - The automation uses the [Bermuda Triangulation](https://github.com/agittins/bermuda) integration
      to get the Area of your bluetooth device
      - Your phone has to be set to transmit bluetooth beacons
      - (Only if Telegram is enabled) Set up `person.xxx.telegram_id` using the `customize.yaml`
      - You need another automation to trigger the cancellation of your door
      with the event_type `telegram_callback` and command `/cdu` as trigger
  domain: automation
  input:
    person:
      name: Person
      description: The person, who has to enter the zone
      selector:
        entity:
          domain: person
    enable_telegram:
      name: Enable Telegram?
      default: false
      description: >-
        If enabled, will sent out the Telegram notifications. Make sure that you set up the
        telegram_bot integration first: https://www.home-assistant.io/integrations/telegram_bot/
      selector:
        boolean:
    zone:
      name: Zone
      default: zone.home
      description: The zone which has to be entered by the person
      selector:
        entity:
          domain: zone
    coming_home:
      name: Activate when person is marked as "home"?
      default: false
      description: >-
        If set to true, the automation will also trigger, when the person is marked as "home".
        This makes sense, when you want to use your wifi as device_tracker
      selector:
        boolean:
    beacon:
      name: Bluetooth Beacon
      description: >-
        The bluetooth beacons that have to be connected to the bluetooth proxy

        Notes:  
        - When using another integration than bermuda, change the "integration"
        part of this selector to your integration name in the blueprint's .yaml file  
        - The entity has to be in reach when creating this automation,
        otherwise it will not show up
      selector:
        entity:
          integration: bermuda
          multiple: true
          domain: sensor
          device_class: bermuda__custom_deviformusce_class
    area:
      name: Area
      description: >-
        The area the phone has to be considered as.
        Use the area that the bluetooth proxy at your door is in.

        Note: All areas with ESPHome devices are shown. You might need to double-check
        that there actually is a bluetooth proxy in the area you selected, otherwise
        it will not work.
      selector:
        area:
          entity:
            integration: esphome
    timeout:
      name: Zone-Entering Timeout
      default:
        hours: 0
        minutes: 10
        seconds: 0
      description: >-
        When you enter the zone and don't come close to the door in this timeframe,
        the automation will cancel. This is so that the door does not open automatically,
        when the zone you entered is triggered accidentally
      selector:
        duration:
    minimum_beacon_time:
      name: Minimal connection time
      default:
        hours: 0
        minutes: 0
        seconds: 5
      description: >-
        The minimum time the bluetooth beacon has to be connected to
        the proxy, to open the door.
      selector:
        duration:
    lock:
      name: Lock
      selector:
        entity:
          domain: lock

mode: restart

variables:
  timeout: !input timeout
  person: !input person
  lock: !input lock

trigger:
  - platform: zone
    entity_id: !input person
    zone: !input zone
    event: enter
  - platform: state
    entity_id:
      - !input person
    to: home
    enabled: !input coming_home

action:
  - service: telegram_bot.send_message
    metadata: {}
    enabled: !input enable_telegram
    data:
      target: '{{state_attr(person,"telegram_id")}}'
      message: >-
        You have been detected close to home. If you near {{ area }} in the next
        {{ timeout.hours*60 + timeout.minutes }} minutes{% if timeout.seconds != 0 %} and {{timeout.seconds}} seconds{%endif%},
        the door will be opened for you.
      one_time_keyboard: true
      inline_keyboard:
        - Cancel:/cdu {{this.entity_id}}
  - wait_for_trigger:
      - platform: state
        entity_id: !input beacon
        attribute: area_id
        to: !input area
        for: !input minimum_beacon_time
    continue_on_timeout: false
    timeout: !input timeout
  - service: lock.unlock
    target:
      entity_id: !input lock
    data: {}
  - service: telegram_bot.edit_message
    enabled: !input enable_telegram
    metadata: {}
    data:
      chat_id: '{{state_attr(person,"telegram_id")}}'
      message_id: last
      message: The door has been unlocked.
3 Likes

Telegram automations

To enable telegram automations, add the following to your customize.yaml:

customize.yaml

person.<<person-name>>:
  telegram_id: <<persons-telegram-chat-id>>

Also add the following automation to enable the cancellation:

Automation: Telegram Cancellation

To cancel automations using Telegram (in case of misfires), set up an automation that listens for the /cdu command (cdu is for “cancel door unlock”, but thanks to message size limits for telegram callbacks, this has to be short)

The automation could look like this:

alias: "Lock: Cancel unlocking"
description: ""
trigger:
  - platform: event
    event_type: telegram_callback
    event_data:
      command: /cdu
condition: []
action:
  - service: automation.turn_off
    data:
      entity_id: "{{ trigger.event.data.args[0] }}"
      stop_actions: true
  - service: automation.turn_on
    data:
      entity_id: "{{ trigger.event.data.args[0] }}"
  - service: telegram_bot.edit_message
    metadata: {}
    data:
      message_id: "{{ trigger.event.data.message.message_id }}"
      chat_id: "{{ trigger.event.data.chat_id }}"
      inline_keyboard: []
      message: |
        Unlocking cancelled.

Thanks a lot for your suggestions, I added the MyHA Button as you suggested. I am new to sharing blueprints as you have seen and am very glad that people like you exist and help make posts for newbies better. <3

1 Like

Hi. So basically the geozone sensor is what starts the trigger to unlock the door? When you get closer to the bluetooth proxy, the door opens. While you are home and as long as the geozone does not remark you as Home, the door will not unlock itself? Have you encountered any weird issues? My concern is that the door unlock while I am home.

Yes, when you enter the Geozone, the automation starts. Only when you come close to the Bluetooth Proxy, the door will actually unlock. You can specify the time that you need to be close to the Bluetooth Proxy if you find that the door unlocks to early.

I found it very helpful to have the Telegram notification enabled, so I am sure the Automation never starts on its own. The message in Telegram is also edited so that you can see when the door opens. There have been zero complications with the automation triggering from away and also while I am in the staircase at home the door never opened automatically, only if I am very close to it.

@doktormerlin Hi, I’m trying to make this work with my iPhone. The iPhone beacon shows up in the right area in the Private BLE Device integration and in the Bermuda integration, but I don’t see a way of using that as a trigger. I tried changing yaml to

selector:
        entity:
          integration: 'Private BLE Device'
          multiple: true
          domain:
          - sensor

but I always get No matching entities found in the Bluetooth Beacon selector of the blueprint. Any help would be much appreciated. thanks!

Hi uspino, have you added the iPhone Beacon in the Bermuda integration as a device? Can you see the Areas for your iPhone correctly in the Bermuda devices?

@doktormerlin Yes, my iPhone shows up as a Device in the Bermuda integration. All sensors work correctly (Distance, area, etc.).

But when I try to set up an Automation with your Blueprint, I get:

Screenshot 2025-04-02 at 8.39.11 AM

…I can’t select any device. Thanks for your help!

1 Like

Can you send a screenshot of what your Bermuda sensor looks like in Developer tools?

What does it say under device class? It looks like this for me:

@doktormerlin These are all the attributes in every Bermuda sensor created. Thanks for helping!

Hey, I am also having some concerns about the all-in-open-door :o :smiley:

As the device is coming into the gezone, it connects to the HA right?
Would it be possible, to verify if the phone is unlocked? That way, if your phone is locked, you have to unlock it (mostly with Biometry sensors) as a higher security feature.

Also the question about the unlocking the door if the device is in the area.
You can check if the device has been connected previoulsy right?

And you are able to set a variable if the device has disconnected, right?
So, would it be save to say, that if this variable is set (away = true), than the script runs?

That way, if the device has been in the area, the feature would not engage?

I don’t know why I dont get emails from Home Assistant, so I am very sorry that I always answer so late. Do you not have a sensor.ble_beacon_iphone_16_pro sensor? I have the device_tracker that you also have, but for every Bermuda device I also have a sensor which includes the device_class. This also uses the area_id instead of the area name which the device tracker uses, which is why I use it in the automations. The area_id is safer to use, since the device_tracker only shows a simple string.

I am not sure if the devices lock-status is provided by the Home Assistant Companion App sensor, but I think this would make the automation to unreliable for everyday use. The Companion App sensor updates in Home Assistant are not live, they often take some time. You don’t want to sit on your door waiting 30 seconds with the phone in your hand, your key would be a much quicker option in this case.

Regarding the “if the device has been in the area”: This is not needed, once the automation opens the door it finishes and there is no more door opening. You would need to leave your Geofence Zone to reactivate the automation. Since the automation is already in the single mode, it can not accidentally trigger twice.

1 Like

This is the only sensor I have with both area_id and device_class: bermuda__custom_device_class

But I still get No matching entities found on “Bluetooth Beacon” drop-down menu when trying to set up your Automation. Thanks for looking into this…

Ok I think I found the issue, maybe a typo in your code…? It says…

  selector:
    entity:
      integration: bermuda
      multiple: true
      domain: sensor
      device_class: bermuda__custom_deviformusce_class

…shouldn’t it be…?

  selector:
    entity:
      integration: bermuda
      multiple: true
      domain: sensor
      device_class: bermuda__custom_device_class

Is there also a way to not open the door if I use the backdoor? That’s the problem I now have with my Nuki. If I use the Auto Unlock it unlocks even when I use the backdoor.

1 Like

yes, that’s 100% the issue. I think there was some mistyping when I edited the post to update the YAML.

I sadly don’t see a way to edit my post anymore. Arrgh

hello i trye to install the automation.
I can select everything but only area not so i can not save the automation.
what do i wrong? i installed bermuda and private BLE device.
it shows my phone also.