This is a bit of a long one but it has the potential to help many with a really cool and helpful automation if something else out there does not already exist. I haven’t been able to find anything so far.
Context:
I have
-
a number of ESPHome Bluetooth proxies (3) and a whole bunch of Shelly devices (20) that have Bluetooth scanning set to ‘passive’.
-
a number of people (6) tracked with the
Private BLE
integration and bicylces & cars (4) tracked withiBeacon
. -
an automated gate with two Shelly’s, one for a gate light and one for opening the gate. The gate Shelly has two outputs, one opens both gate leaves for cars, the other only opens one gate leaf for pedestrians and bicycles. Only one gate Shelly has Bluetooth scanner running for simplicity. The gate always closes 3 seconds after opening or an object leaves the gate area (photocell) to keep the dogs in. The close delay can be set to 10sec but this is too long because of the dogs.
-
an automated garage door with one Shelly attached for automation.
-
an automation that turns on the gate light for 5 mins when a Private BLE tracker changes from not_home to home. This works for the light but cannot be used to open the gate because it is triggered too soon and by the time the person gets to the gate it is closed again.
-
another automation that turns on the light and opens the gate (and garage door if it is not already open). The gate closes 3 secs after opening and this is usually ok because cars are faster than people on foot.
Desired outcome:
-
Each tracked object (Private BLEs & iBeacons) has an additional sensor added that shows which proxy it is connected to by name. Presently the
source
is an attribute with the MAC address. This is for debugging information and possibly to help with 2. & 3. below. -
A sensor that lists the entities connected through the gate along with their distance. This would likely be a dictionary with entity ID, name and distance. This would be used for 3. below.
-
An automation that is triggered by an entity approaching the gate that then turns on the light and opens the gate. If it is a person or bicycle one gate leaf opens when the distance is within 2 metres (or some configurable distance). If it is a car, both leaves open when the distance is within 10 metres (or some second configurable distance)
Method:
I’m dividing this up to work on each step separately and am presently stuck on a good way to do 1.
-
Ten template sensors (
sensor.person1_ble_proxy
,sensor.car1.ble_proxy
, etc.) that does a table lookup of MACs to return the location name of the proxy it is connected to. I.e. 10 sensors are created, one for each BLE entity and each sensor would have a result something likegate
ordining
orkitchen
, etc. These sensors could have attributes like entity_id, name, distance which could help with 2. -
A template sensor that uses 1. to list all the
sensor.xxxx_ble_proxy
equal togate
and also store the distance. This would most likely be a dictionary array something like[{entity_id, entity_name, distance}]
- sorry if I’ve got the symbology a bit off there - so long as it is compatible with a trigger for 3. -
An automation that is watching attributes in the array created in 2. above and triggers when any distance drops below a threshold and the entity has changed from not_home to home within the last 30 seconds.
Phew, that was a mouthful, but good to put down on paper to find a way forward with 1.
Thanks in advance for anyone with ideas on how best to move forward. There may be better methods than what I’ve outlined above so suggestions are most welcome.