[V2] Automatically unlock your door when getting in bluetooth range

This is V2 of my old blueprint which you can find here:

V1 had some setup hick-ups and also a Typo in the post. Since I can’t edit the post anymore because of it being too old, I have to create a new Topic to share my Blueprint with you :slight_smile:

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. (optionally) 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

Pros

Compared to OOTB solutions like Nuki Geozones or SwitchBots solution, you have additional configuration parameters.

  • You can set a delay before opening the lock, if your lock opens too quickly. For example, I live in a flat. If I use the SwitchBot OOTB solution, my SwitchBot already opens the door while I’m still 2 sets of stairs away from the door and by the time I reach the door, it is closed again.
  • You can set up additional automations to cancel the unlocking of the door, if you e.g. enter through the garage or the garden door.

Setup

To make this work, there is some configuration needed:

  • The bluetooth proxy closest to your door 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. So install Bermuda first and set it up to track your devices.

Telegram Notifications

To allow Telegram notifications to function properly, please do the following:

  1. Set up a Telegram Bot
  2. For Telegram notifications, the blueprint uses a custom parameter of your persons. See here in the old post.

This new Version gladly doesn’t require any additional automations to handle the buttons sent via Telegram. Everything is handled from within the Automation.

Blueprint

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

The blueprint 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`
  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/


        Afterwards, enter a new value in your "customize.yaml" file to add your telegram user_id
        to your person entity in Home Assistant.


        person.<<Your Person Name>>: { telegram_id: <<Your Telegram Id>> }
      selector:
        boolean:
    zone:
      name: Zone
      default: zone.home
      description: The zone that 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:
    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
    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_device_class
    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 recognition 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: single

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

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

action:
  - action: telegram_bot.send_message
    metadata: {}
    enabled: !input enable_telegram
    response_variable: response
    data:
      target: '{{state_attr(person,"telegram_id")}}'
      message: >-
        You were recognized close to your home. If you are near your door in the
        next {{ timeout.hours*60 + timeout.minutes }}{% if timeout.seconds != 0 %}:{{ timeout.seconds }}{% endif %} minutes,
        the door will be opened.
      one_time_keyboard: true
      inline_keyboard:
        - Cancel:/cancel,Open:/unlock
  - variables:
      telegram_edit_text: "Keine Angabe"
  - wait_for_trigger:
      - trigger: state
        entity_id: !input beacon
        id: unlock_by_bluetooth_beacon
        attribute: area_id
        to: !input area
        for: !input minimum_beacon_time
      - trigger: event
        id: unlock_by_telegram
        event_type: telegram_callback
        event_data:
          command: "/unlock"
          message:
            chat:
              id: "{{ response.chats[0].chat_id | int(0) }}"
            message_id: "{{ response.chats[0].message_id | int(0) }}"
      - trigger: event
        id: cancel_by_telegram
        event_type: telegram_callback
        event_data:
          data: "/cancel"
          message:
            chat:
              id: "{{ response.chats[0].chat_id | int(0) }}"
            message_id: "{{ response.chats[0].message_id | int(0) }}"
    continue_on_timeout: true
    timeout: !input timeout
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ wait.trigger.id == "unlock_by_bluetooth_beacon" or 
                wait.trigger.id == "unlock_by_telegram" }}
        sequence:
          - variables:
              telegram_edit_text: "The door has been opened for you"
          - action: lock.unlock
            target:
              entity_id: !input lock
      - conditions:
          - condition: template
            value_template: |
              {{ wait.trigger.id == "cancel_by_telegram" }}
        sequence:
          - variables:
              telegram_edit_text: "Opening the door was manually cancelled."
    default:
      - variables:
          telegram_edit_text: >-
            You weren't recognized near the door within
            {{ timeout.hours*60 + timeout.minutes }}{% if timeout.seconds != 0 %}:{{ timeout.seconds }}{% endif %} minutes
            and the opening was cancelled.
  - action: telegram_bot.edit_message
    metadata: {}
    data:
      chat_id: "{{ response.chats[0].chat_id }}"
      message_id: "{{ response.chats[0].message_id }}"
      message: "{{ telegram_edit_text }}"

2 Likes

Hello doktormerlin,

Thanks for contributing to the community with a new Blueprint.
I have a suggestion for you. Many people who are not familiar with directory structures will have problems installing this without the Home Assistant MY tools.
Adding a MY link for this Blueprint to your top post would help them a lot.
Here is the link to make that.
Create a link – My Home Assistant
You need to be a trust level ‘member’ to edit a post. Understanding Discourse Trust Levels
If you can’t edit, I would load a link into a second post.

Hello @doktormerlin,

thanks for your nice Blueprint.

I do have a problem with installment:
For me it does not show an area.

Do you have any ideas why?

LG,
Ferdi :slight_smile:

Hi Ferdi,

I’m glad you got bermuda to work, that’s the trickiest part :slight_smile:

For the area: You need to add your Bluetooth Proxy Device to an Area, so that this shows up. Do you have this? Can you see in the Bermuda Integration that your device is correctly set up?

Additionally, I would advice you to replace the blueprint with the following:

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
  domain: automation
  input:
    person:
      name: Person
      description: The person, who has to enter the zone
      selector:
        entity:
          domain: person
    telegram_notify_entity:
      name: Telegram Notify Entity
      description: If set, Telegram notifications are enabled. This is optional
      default:
      selector:
        entity:
          domain: notify
          integration: telegram_bot
    zone:
      name: Zone
      default: zone.home
      description: The zone that 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:
    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 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.
    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_device_class
    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 recognition 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: single

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

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

action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ telegram_notify_entity != None }}"
        sequence:
          - action: telegram_bot.send_message
            metadata: {}
            response_variable: response
            data:
              entity_id: "{{ telegram_notify_entity }}"
              message: >-
                You were recognized close to your home. If you are near your door in the
                next {{ timeout.hours*60 + timeout.minutes }}{% if timeout.seconds != 0 %}:{{ timeout.seconds }}{% endif %} minutes,
                the door will be opened.
              one_time_keyboard: true
              inline_keyboard:
                - Cancel:/cancel,Open:/unlock
  - variables:
      telegram_edit_text: "No Input"
  - wait_for_trigger:
      - trigger: state
        entity_id: !input beacon
        id: unlock_by_bluetooth_beacon
        attribute: area_id
        to: !input area
        for: !input minimum_beacon_time
      - trigger: event
        id: unlock_by_telegram
        event_type: telegram_callback
        event_data:
          command: "/unlock"
          message:
            chat:
              id: "{{ response.chats[0].chat_id | int(0) }}"
            message_id: "{{ response.chats[0].message_id | int(0) }}"
      - trigger: event
        id: cancel_by_telegram
        event_type: telegram_callback
        event_data:
          data: "/cancel"
          message:
            chat:
              id: "{{ response.chats[0].chat_id | int(0) }}"
            message_id: "{{ response.chats[0].message_id | int(0) }}"
    continue_on_timeout: true
    timeout: !input timeout
  - choose:
      - conditions:
          - condition: template
            value_template: |
              {{ wait.trigger.id == "unlock_by_bluetooth_beacon" or 
                wait.trigger.id == "unlock_by_telegram" }}
        sequence:
          - variables:
              telegram_edit_text: "The door has been opened for you"
          - action: lock.unlock
            target:
              entity_id: !input lock
      - conditions:
          - condition: template
            value_template: |
              {{ wait.trigger.id == "cancel_by_telegram" }}
        sequence:
          - variables:
              telegram_edit_text: "Opening the door was manually cancelled."
    default:
      - variables:
          telegram_edit_text: >-
            You weren't recognized near the door within
            {{ timeout.hours*60 + timeout.minutes }}{% if timeout.seconds != 0 %}:{{ timeout.seconds }}{% endif %} minutes
            and the opening was cancelled.
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ telegram_notify_entity != None }}"
        sequence:
          - action: telegram_bot.edit_message
            metadata: {}
            enabled: "{{ telegram_notify_entity != 'None' }}"
            data:
              chat_id: "{{ response.chats[0].chat_id }}"
              message_id: "{{ response.chats[0].message_id }}"
              message: "{{ telegram_edit_text }}"


Sadly I can’t update the link.

This new blueprint works with Telegram after 2026.9.0 and is easier to set up thanks to it using the notify entities.

Hey Merlin,

Thanks for the quick answer!

this is how it is looking for me.

According to my understanding the Bluetooth Proxy Device is added to an area, but still no area shows up.

Thanks for the new blueprint :slight_smile: