Beacon-Powered Garage Door Opener

This project is an addition to the already existing BLE scanner in my garage. My trash can reminder project already uses this same scanner to determine if the trash cans are inside the garage on trash night and, if so, reminds me to take them out to the street. Since the scanner is already there in the garage, I thought it would be fun to add on this garage door open/close automation. You can also do this as a standalone project if you don’t want to do the trash can project.

The basic concept

This one is obvious: it opens and closes the garage door automatically.

Firstly, we will place a BC-U1 usb-powered beacon in the car in one of the powered/unpowered slots. When the car is turned off, the usb beacon gets no power so doesn’t broadcast. When the car is turned on, the beacon begins to broadcast. (If your car doesn’t have this sort of USB outlet, you will probably need to make some adjustments to the settings and automations, but it shouldn’t be too difficult. )

Secondly, we will attach a BC-S1 door position beacon to the frame of the garage door, and attach the little magnetic sensor thingy to the garage door itself. The gateway will also scan for the beacon broadcast from this beacon in order to determine if the door is open or closed, since we have different thresholds/conditions for action based on whether the door is open or closed.

The BLE beacon-scanning gateway (BCG04) was already installed inside the garage for my other project. The gateway scans for this known “car beacon”, then sends this scan data to our Home Assistant (HA) installation running on the same wifi network. The HA can be anywhere in the house as long as it is connected to the same wifi.

The HA will have an MQTT server integration installed on it in order to act as an MQTT server. So the MQTT server on the HA will receive the data “published” from the gateway, and make it available to any service “subscriber” on the HA that wants to use this data.

Next, we will create an MQTT sensor (sort of a virtual sensor since there is no hardware) on the HA that will subscribe to this specific beacon’s data. This sensor will report the signal strength of the beacon.

But since the signal strength of all BLE beacons is sometimes a bit jumpy due to signal bouncing and wifi interference, we will create a second “filter sensor” that will smooth this MQTT sensor data.

Finally, we will create two HA automations. The “open the door” automation checks:

1. Is the car beacon seen by the scanner?
and
2. Is the door closed now?
(and some other conditions)

If so, then trigger the door to open.

That automation takes care of the initial opening of the door when you first get in the car and turn the ignition key (or press the start button for an electric car like mine).

It also opens the door when you return from a drive.

The other automation, the “close the door” automation, checks:

1. Is the car beacon seen by the scanner and the signal power weaker than -65 (i.e. the car is out of the garage now)?
and
2. Is the door open now?
(and some other conditions)

If so, then trigger the door to close.

The Hardware:

Car Beacon: In this project I am using a BC-U1 USB-powered beacon. I plugged it into one of the powered/unpowered usb power outlets in the car. I set the interval to 500ms and the broadcast power to +4 dBm.

Door Position Beacon: I used the BC-S1 Door Position Beacon. This beacon can be configured to broadcast one UUID when open and a different UUID when closed. The gateway can see this broadcast and thus know whether the door is currently open or not. If you have a more high-tech garage door opener, you might not need this.

Beacon Scanning Gateway: I am using the BCG04 BLE scanning gateway. You can see it in the picture below. It’s the little thing on the bottom with the blue light. (The thing on the top is a Wyze cam which I previously used when I drove away but then got paranoid that I had forgotten to close the garage door!).

Gateway in garage

HA: My HA is running on an rPi and is (something something technical info here)…Honestly, I am not much of an HA expert.

Garage Door Opener: My garage door opener is quite old so completely not compatible with anything high tech. Even the door open/close button is one single button instead of two distinct buttons. So I attached a Shelly 1 Wifi Relay Switch 15A to it, and powered the relay switch with an old power plug I had laying around. Your case will likely be different, but here are a few pictures for your reference:

I am quite sure you HA aficionados will be able to improve on my automation. In addition, while you are walking through this setup, I can imagine that you will think of lots of other things a BLE gateway can do with beacons and automations. Remember that a single gateway can scan for many different beacons and report this data to the HA. Once there, the data can be used for multiple different automations based on multiple MQTT sensors (i.e. beacons or a virtual beacon on your smartphone).

Some Final Words Before Jumping Into The Steps:

Note that the example and steps below are based on my particular garage, opener, car, and driveway. Each of these physical things will have some effect on the results. So you will need to adjust some of the key numbers below to fit your install case. For example, the -65 threshold for closing the door might be different for you. Also the filter settings for the smoothed car beacon sensor might be very different for you.

You might also notice that I have added a few weird delays and double checks in the automations. Here’s a screenshot of the visual editor version of the opening automation with some explanations below for your insight:

Breakdown of the “open the door” automation:
-Check if the car beacon is seen by the scanner regardless of the signal strength
-Test if the opening automation has triggered within the last 15 seconds. If yes, do nothing. This prevents some oddball double triggers that occur when the update of the beacon status is not fast enough to prevent a double trigger.
-Test if the close automation has been triggered less than 30 seconds ago. If so, do nothing. This prevents the door from reopening when my car is still on the street and pulling away from the house.
-Test if the garage door is closed, and test if the garage door is not open. A bit over a double check just to be sure.
-If everything looks good and the trigger and conditions are all met, then send a notification to my phone (mainly for troubleshooting), trigger the Shelly relay ON, pause for half a second, and then trigger it OFF. This is the way my particular garage door button works. This ON/Delay/OFF is imitating what happens when I press the garage door’s hardwired button on the garage door wall.

Step 1, Set Up the MQTT Server on the HA:

Before you click on the standard HQ instruction link below, I should note a couple of settings that worked for me:

On the HA, go to the Settings menu, then system, then network.

For hostname, enter homeassistant. I previously used homeassistant.local but it stopped working recently after an HA update.

Click here to follow the HA integration instructions to setup the MQTT server (broker) on your HA.

Here are some image links showing how my MQTT integration looked when it was all set up. Note that for the topic “bluecharm/publish/(MAC of the gateway here)”, you should fill in the actual MAC of your gateway.

MQTT setup page 1
MQTT setup page 2
MQTT setup page 3
MQTT setup page 4
MQTT setup page 5
MQTT setup page 6 (Note: This screenshot shows “Enable Discovery” as enabled. I later disabled this.)

Step 2, Set Up the Gateway:

Click here to follow the instructions to setup the BCG04 Beacon Gateway.

Step 3, Configure the Car Beacon:

Remember to plug the car beacon into a powered/unpowered usb power outlet in the car so that it stops broadcasting when the car is turned off. In my car, the front seat usb outlets are always powered, but the backseat outlet is only powered when the car is turned on. If your car doesn’t have this sort of USB outlet, you will probably need to make some adjustments to the settings and automations, but it shouldn’t be too difficult.

I changed the default BC-U1 settings a bit to suite this project better:

Firstly, I adjusted the interval from 100ms (super frequent) to 500ms (twice per second). That is plenty of data for the HA whereas the 100ms interval would just be wasting the brain power of the HA needlessly.

Secondly, I also adjusted the broadcast power of the beacon from default 0 dBm to +4 dBm so that it would be strong enough to reach the scanner from inside the car and at the bottom of the driveway. Take a look at the settings below (from our KBeacon configuration app screens) and set yours up the same way. My car beacon is called “ShanDian-U1”:

Step 4, Configure the Door Beacon:

I changed the default settings of the door beacon to the following in order to make it broadcast the standard UUID (….BBBBB) when closed and a slightly modified UUID (…BBBC2) when open. Take a look at the settings below (from our KBeaconPro configuration app screens) and set yours up the same way. My door beacon is called “G-DoorPosition”. (Note that this app is different from the app you need to use to configure the BC-U1 car beacons.) :

Step 5, Create the Car Beacon Sensor:

Go to your configuration.yaml and add this code to create a sensor for the car beacon broadcast:

# MQTT sensors below:
mqtt:
sensor:
- name: "rssiCarBeacon"
#for next line, enter your state topic as defined in your gateway device settings (different from the example below) and your beacon UUID (different from example below)
state_topic: "bluecharm/publish/BC5729052ED3"
unit_of_measurement: "dBm"
value_template: >-
{% set targetUuidFound = namespace(found=False) %}
{% for i in range(value_json.obj|count) -%}
{% if value_json.obj[i].uuid == "7777772E6B6B6D636E2E636F6D000002" and targetUuidFound.found == False %}
{{ value_json.obj[i].rssi }}
{% set targetUuidFound.found = True %}
{%- endif %}
{%- endfor %}
{% set targetUuidFound = namespace(found=False) %}

In case your curious, what the above value template does is grab the beacon scan data packet from the MQTT server, then count how many beacon reports are present in the packet, then cycle through them one by one until it finds one that matches our car beacon UUID. Then it marks that one down as the present signal strength (rssi) of that beacon. Finally, it stops cycling through that packet since the target beacon has already been found once, since there is no need to update the signal strength more than once per MQTT packet.

Step 6, Create the Smoothed Sensor Based On The Car Beacon Sensor:

Go to your configuration.yaml and add this code to create a new smoothed version of the MQTT regular car beacon sensor. Sort of like a “smoothed sensor of a sensor”:

# Some sensor definitions below
sensor:
- platform: time_date
#I think this one is needed later for the automation but not sure about this
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- platform: filter
#This one takes the sensor.rssiCarBeacon we created from the MQTT broadcast from the gateway, and builds a new smoothed sensor named "Car Beacon rssi smoothed". the smoothing is done with two filters, outlier and lowpass.
name: "Car Beacon rssi smoothed"
entity_id: sensor.rssiCarBeacon
filters:
- filter: outlier
window_size: 4
radius: 4.0
- filter: lowpass
time_constant: 2
precision: 1

We will come back to this topic later, but just to mention it now, the filter settings (e.g. window_size, radius, Time_constant, and precision) are one of the keys to a smooth and fast automation. The settings above are what I dialed in for my particular car, garage door, driveway, etc. You can use these as a starting point, but you will likely want to fiddle with them to suite your case. For the other project in which we checked if the trash can was in the garage, these settings were not very important since the reaction timing of the automation was also not very important.

Step 7, Create the open and close automations:

Go to your automations.yaml and add the code shown below to create the automations for opening the door and closing the door.

- id: '1714601711232'
alias: Open garage door when car is inside or outside and beacon is scanned
description: ''
trigger:
- alias: Blue Charm BC-U1 USB-Powered Beacon in Car
platform: state
entity_id:
- sensor.car_beacon_rssi_smoothed
condition:
- alias: 'Test if this automation has been triggered more than 15 seconds ago to
prevent double triggering '
condition: template
value_template: '{{ now() - state_attr(''automation.opengarageifclosedandbeaconnearby'',
''last_triggered'') | default(as_datetime(0), true) > timedelta(seconds=15)
}}'
enabled: true
- alias: 'Test if the close automation was triggered more than 30 seconds ago to
prevent reopening before leaving the area '
condition: template
value_template: '{{ now() - state_attr(''automation.close_garage_door_when_car_is_outside_and_beacon_rssi_is_below_threshold_level'',
''last_triggered'') | default(as_datetime(0), true) > timedelta(seconds=30)
}}'
enabled: true
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.rssidoorbeaconclosed.last_changed)
| int < 10 }}'
alias: Test if garage door is closed
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.rssidoorbeaconopen.last_changed)
| int > 10 }}'
enabled: true
alias: Test if garage door is not open
action:
- alias: Send a notification to my iPhone saying door was closed and now has been
opened
service: notify.mobile_app_thomass_iphone_14
data:
message: Garage door was closed and has now been opened
title: GARAGE DOOR OPENED
data:
push:
sound:
name: circles.m4r
critical: 1
volume: 1
- service: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.shelly1_3494547a1a93
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
enabled: true
- service: switch.turn_off
metadata: {}
data: {}
target:
device_id: 8d9770f0c1f9c772d22fc863ebcf86dc
enabled: true
mode: single
- id: '1715208958200'
alias: Close garage door when car is outside and beacon rssi is below threshold
level
description: ''
trigger:
- alias: Blue Charm BC-U1 USB-Powered Beacon in Car - rssi below threshold
platform: numeric_state
entity_id:
- sensor.car_beacon_rssi_smoothed
below: -65
condition:
- alias: Test if door was opened more than 15 seconds ago
condition: template
value_template: '{{ now() - state_attr(''automation.opengarageifclosedandbeaconnearby'',
''last_triggered'') | default(as_datetime(0), true) > timedelta(seconds=15)
}}'
enabled: true
- alias: Test if this automation was triggered more than 15 seconds ago to prevent
double triggering
condition: template
value_template: '{{ now() - state_attr(''automation.close_garage_door_when_car_is_outside_and_beacon_rssi_is_below_threshold_level'',
''last_triggered'') | default(as_datetime(0), true) > timedelta(seconds=15)
}}'
enabled: true
- alias: Test if garage door is not closed
condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.rssidoorbeaconclosed.last_changed)
| int > 10 }}'
- alias: Test if garage door is open
condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.rssidoorbeaconopen.last_changed)
| int < 10 }}'
enabled: true
action:
- alias: Send a notification to my iPhone saying door was open and now has been
closed
service: notify.mobile_app_thomass_iphone_14
data:
message: Garage door was open and has now been closed
title: GARAGE DOOR CLOSED
data:
push:
sound:
name: circles.m4r
critical: 1
volume: 1
- service: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.shelly1_3494547a1a93
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
enabled: true
- service: switch.turn_off
metadata: {}
data: {}
target:
device_id: 8d9770f0c1f9c772d22fc863ebcf86dc
enabled: true
mode: single

You will notice that I have added an alert on my smartphone when the garage door opens or closes. I mainly did this for troubleshooting when I was first dialing in the correct settings. For example, sometimes the garage door would close when I backed out to the street, but then as I turned the car to drive away, it would open again (thinking that I had just arrived back). I later added some other checks in the automations shown above to prevent these types of mistakes. You might want to disable the phone notifications once you’ve got your project up and running smoothly.

Step 8, Install the garage door position beacon

I installed my door beacon on the side edge of the garage with the little magnetic sensor attached to the garage door. It broadcasts the regular UUID when the door is closed and a different UUID when the door is open.

Step 9, Bask in the glory of your new magical garage door opening/closing system!

If you have any questions about this, it would be great if you could ask those questions on the Home Assistant forums. you can tag my user name on your post (u/BlueCharmBeacons) to be sure I get notified about it.

You are also encouraged to share your ideas for improvement or modifications there. As I mentioned earlier, I am not much of an HA maven.

Thanks for reading!