After I wrote the instructions below, someone who is much more knowledgeable about HA made an improved version of this project. So, if you want to give his write-up a try first, you can find it at: Link to Kyle’s Write-Up
Please continue reading for my own version…
This one was inspired by a couple of different people but most recently by Mark H. He also offered some better ideas for how to rewrite my automations. Thanks, Mark!
The basic concept
In most areas of the US, your trash can(s) needs to be put out on the curb late at night, the night before the morning that the trash trucks come by to empty the can.
So in this project, we are going to attach a beacon to one of the trash cans, and place a BLE beacon-scanning gateway (BCG04) inside the garage (or wherever the cans are usually stored). The gateway will scan for this known beacon, then send 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 from the gateway, and make it available to any service on the HA (or any other “subscriber” on the same wifi network) 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. 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 an HA automation that checks:
1. Is the signal strength of the beacon pretty strong, i.e. is the trash can near the gateway? In other words, is the trash can inside the garage (for example)?
and
2. Is it trash night between 8:15pm and 11:00pm?
If so, then send a critical reminder notification to our smartphone HA app telling me/us to move the trash cans out to the curb.
We will also add one more condition to this automation that will prevent this reminder from being sent more often that once every 15 minutes.
The Hardware:
iBeacon: In this project I am using a BC04P water-resistant beacon. It has a nice flat base/flange, so I can use double-back tape to stick it on the trash can, plus it has screw holes which I will use to add a zip-tie for extra security to prevent the beacon from falling off. Or maybe I will just zip-tie it onto the handle and skip the double-back tape. Don’t attach your beacon to your trash can yet, since you want to have the beacon nearby when setting up and testing everything.
The BC04P beacon also has a higher capacity battery which will last for 4 years at default settings. For this project, I could probably even change the broadcast interval from the default 1 second to 2 seconds, and then the battery would last for 8 years.
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 Wyze cam).
HA: My HA is running on an rPi and is (something something technical info here)…Honestly, I am not much of an HA expert.
I am quite sure you HA aficionados will be able to improve on my automation quite easily. 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. FYI, I am planning on using this same gateway in my garage to automate the opening and closing of my garage door using a USB-powered beacon (BC-U1) plugged into the USB power outlet in the car. 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).
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 Beacon:
I used the BC04P standard settings with iBeacon configured in SLOT0, but I also configured a motion trigger for that slot. Take a look at the settings below (from our KBeaconPro configuration app screens) and set yours up the same way.
So, what you just achieved with that beacon config is:
-The beacon will continuosly broadcast its normal UUID (ending in …BDF4). That is the UUID for which the gateway will gather data and send via MQTT to your HA. Your automation will then monitor the smoothed signal strength of this beacon to determine whether the beacon is in the garage (strong signal) or out on the street (weak signal).
-Whenever the beacon is moved/shaken, it will broadcast a slightly modified UUID (ending in …BDF5) for 60 seconds. That is the UUID that the gateway will look for the next morning to trigger the “trash can has been emptied by the truck” notification on your phone.
-Update: I had to increase the motion sensitivity number from default 2 to 20. The valid range is 2~126.
2 is the most sensitive. 126 is the least sensitive. When mine was set at 2, I was getting motion alerts when heavy trucks would simple drive by my house in the morning. Raising it to 20 solved that problem.
Step 4, Create the Sensors:
Go to your configuration.yaml and add this code to create a sensor for the regular beacon broadcast and a second sensor for the movement-sensed beacon broadcast:
# MQTT sensors below: mqtt: sensor: - name: "rssi1B1" #for next line, enter your topic as defined in your gateway device settings state_topic: "bluecharm/publish/BC5729052ED3" unit_of_measurement: "dBm" #for next section, change my regular uuid to the regular uuid of your target beacon value_template: >- {% set targetUuidFound = namespace(found=False) %} {% for i in range(value_json.obj|count) -%} {% if value_json.obj[i].uuid == "1B6295D54F744C58A2D8CD83CA26BDF4" and targetUuidFound.found == False %} {{ value_json.obj[i].rssi }} {% set targetUuidFound.found = True %} {%- endif %} {%- endfor %} {% set targetUuidFound = namespace(found=False) %} - name: "rssi1B1movement" #for next line, enter your topic as defined in your gateway device settings state_topic: "bluecharm/publish/BC5729052ED3" unit_of_measurement: "dBm" #for next section, change my movement uuid to the movement uuid of your target beacon value_template: >- {% set targetUuidFound = namespace(found=False) %} {% for i in range(value_json.obj|count) -%} {% if value_json.obj[i].uuid == "1B6295D54F744C58A2D8CD83CA26BDF5" and targetUuidFound.found == False %} {{ value_json.obj[i].rssi }} {% set targetUuidFound.found = True %} {%- endif %} {%- endfor %} {% set targetUuidFound = namespace(found=False) %} - name: "dmac1" state_topic: "bluecharm/publish/BC5729052ED3" value_template: "{{ value_json.obj[0].dmac }}"
Step 5, Create the Smoothed Sensor for the Regular Sensor:
Go to your configuration.yaml and add this code to create a new smoothed version of the MQTT regular 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' - 'beat' - platform: filter #This one takes the sensor.rssi1B1 we created from the MQTT broadcast from the gateway, and builds a new sensor named "BC04 rssi smoothed". name: "BC04 rssi smoothed" entity_id: sensor.rssi1B1 filters: - filter: outlier window_size: 3 radius: 5.0 #- filter: lowpass # time_constant: 10 # precision: 2 - filter: time_simple_moving_average window_size: "00:01" precision: 2
Step 6, Create the Reminder Automation:
Go to your automations.yaml and add the code shown below to create the automation for trash night reminder and the next day notification that the can has been emptied by the trash truck
Change the day from Wednesday to your trash put out day and the time to be reminded that the trash can is still inside the garage (i.e. near the gateway).
By the way, I should mention that this will work even if your driveway is super long, and the beacon is out of range of the gateway on trash night (i.e. you already put the trash cans out on the very distant curb). Since the signal strength will be non-existent, it will NOT be greater than -60, and therefore won’t trigger the “cans are still inside the garage” notification.
- id: '1705367529303' alias: trash night reminder description: '' trigger: - alias: Blue Charm BC05 Garage Can Beacon platform: state entity_id: - sensor.bc04_rssi_smoothed condition: - alias: When Blue Charm BC04 beacon's smoothed rssi is stronger than -60, i.e. the beacon is close to the gateway inside the garage condition: numeric_state entity_id: sensor.bc04_rssi_smoothed above: -60 - alias: Test if this automation has been triggered more than 15 minutes ago to prevent too frequent reminders condition: template value_template: '{{ now() - state_attr(''automation.trash_night_reminder'', ''last_triggered'') | default(as_datetime(0), true) > timedelta(minutes=15) }}' enabled: true - condition: time weekday: - wed after: '20:15:00' enabled: true before: '23:00:00' action: - alias: Send a notification to my iPhone to remind me to put out the trash cans service: notify.mobile_app_thomass_iphone_14 data: message: Hey, it's trash night, but the trash can is still inside the garage. Go take it out now! title: TRASH CAN REMINDER data: push: sound: name: circles.m4r critical: 1 volume: 1 mode: single
Step 7, Create the Notification for when the trash can is moved/emptied the next morning:
Go to your automations.yaml and add this code to create the automation for a notification when the trash can is moved the next morning (i.e. the trash truck came by and emptied the can); change the day from Thursday to your trash day and the time to sense when the trash can is moved.
In this case, I should also mention that this motion alert will NOT work if your driveway is super long, and the beacon is out of range of the gateway on trash pickup morning (when the trash cans are out on the very distant curb). Since the beacon will never be “seen” by the gateway, the special “movement UUID” will never be picked up by the gateway, and therefore won’t trigger the “cans have been emptied” notification.
- id: '1704930137296' alias: Movement Sensed On Recycling Can description: '' trigger: - alias: Blue Charm BC04 Recycling Can Movement Sensed platform: state entity_id: - sensor.rssi1b1movement condition: - alias: When Blue Charm BC04 beacon's special movement uuid is bring broadcast, i.e. the can has been moved/empied condition: numeric_state entity_id: sensor.rssi1b1movement above: -100 - alias: Test if this automation has been triggered more than 15 minutes ago to prevent too frequent reminders condition: template value_template: '{{ now() - state_attr(''automation.movement_sensed_on_recycling_can'', ''last_triggered'') | default(as_datetime(0), true) > timedelta(minutes=15) }}' enabled: true - condition: time weekday: - thu after: 06:30:00 enabled: true before: '10:00:00' action: - alias: Send a notification to my iPhone to tell me recycling can has been emptied service: notify.mobile_app_thomass_iphone_14 data: message: Recycling Can has been emptied title: RECYCLING CAN HAS BEEN EMPTIED data: push: sound: name: circles.m4r critical: 1 volume: 1 mode: single
Step 8, Attach the beacon to the trash and/or recycling can:
See the photo above showing my beacon attached to my recycling can. Attach yours however you like, but I would recommend zip ties since trash trucks can really throw these cans around and a double-back-tape-attached beacon would easily drop off after a while (due to heat, sun, rain, etc).
Step 9, Add some dashboard stuff if you want:
Step 10, Bask in the glory of your new trash night reminder 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!