Home Assistant … set up a Bluetooth proxy in the ESPHome dashboard
You can create a Bluetooth proxy (a DIY Bluetooth gateway) which can read data from sensors around the home. All you need is an ESP32 development board which will use wifi and Bluetooth to send information to Home Assistant.
Presently I get data from my Xiaomi room temperature sensors, my Xiaomi Nightlights, my Switchbot water leak sensors. At a future point I will get Home Assistant listening out for the presence of my phone.
what you need to set up a Bluetooth proxy
A Bluetooth proxy requires almost any of the ESP32 development boards you can find at maker shops or Amazon. You need an ESP32-based board not an ESP8266 board – some shop listings aim to confuse on this point. I rather like the M5Stack Atom Lite board because it comes with its own casing and looks discrete.
You’ll also need a simple USB power supply, plus a mains socket fairly close to the centre of your house. You can set up a couple of these should you need to ‘listen’ out for Bluetooth devices, such as phones around the home. In theory the Raspberry Pi running Home Assistant is very capable of picking up the useful data – however some software conflicts there lead us to set up separate Bluetooth sniffing devices like this.
go to Home Assistant ESPHome
Click add device. The idea is to create a place in the ESPHome dashboard, upload some basic code and lastly upload the BT proxy code below.
Go through this initialisation process – it will put the BT proxy in the ESPHome dashboard. It will make the device update-able over wifi (OTA update).
replace the code in the ESPHome dashboard with this code
use the suggested key; change the wifi SSID and password; DO use esp-idf framework as below – do NOT use arduino framework; do add mdns: as shown. When you’ve made the edits, compile the code and install it ‘wirelessly’ or ‘ota’.
When your BT proxy has been running a while it may find or discover devices on your network.
esphome:
name: btproxy-m5stack
friendly_name: btproxy-m5stack
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# level: VERBOSE
# Enable Home Assistant API
api:
encryption:
key: "IMKiexluIv7Z5zHpJpTYcDYfGBnYlwm3nNgZY62P77Y="
# THIS LONG KEYCODE NEEDS CHANGING WITH THE ENCRYPTION CODE
ota:
- platform: esphome
# password: ""
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
- ssid: !secret ee_ssid
password: !secret ee_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "btproxy-m5stack fallback hotspot"
password: ""
captive_portal:
mdns:
esp32_ble_tracker:
scan_parameters:
active: true
interval: 1100ms
window: 1100ms
bluetooth_proxy:
active: true
binary_sensor:
# LISTEN FOR SPECIFIC PHONES or BT devices
- platform: ble_presence
mac_address: 48:74:12:5f:b8:37
name: "rgr phone"
# USE THE m5 BUTTON - to toggle light or trigger something
- platform: gpio
pin:
number: 39
inverted: true
name: btproxy-m5stack-button
on_press:
then:
- light.toggle: status_led
# THE FOLLOWING LIGHT EFFECT IS TRIVIAL/UNNECESSARY
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB
pin: 27
num_leds: 1
rmt_channel: 0
chipset: SK6812
id: status_led
name: btproxy-m5stack-light
effects:
- addressable_rainbow:
- addressable_rainbow:
name: rainbow effect speed and width Values
speed: 10
width: 5
- random:
- random:
name: random effect 5s
transition_length: 5s
update_interval: 7s
- flicker:
sensor:
- platform: wifi_signal
id: wifis
update_interval: 60