dalehumby / ESPHome-Apple-Watch-detection

ESPHome BLE Apple Watch presence detection
MIT License
332 stars 17 forks source link

apple watch 3 always in OFF state #13

Closed duceduc closed 2 years ago

duceduc commented 2 years ago

I am testing this script out and have used the same settings for the binary and sensor sensor settings. In mqtt, I can see the binary sensor but the sensor does not appear. Also, the binary sensor is always in the OFF state even though my apple watch 3 is sitting right beside the esp32 node. I am assuming the node isn't detecting my watch??

dalehumby commented 2 years ago

Hi. Could you send logs from ESPHome while is running? That will help see where the problem is.

Also, just to confirm: you are wearing the watch, and it is currently unlocked? By default it’ll only report RSSI when unlocked.

Thanks

duceduc commented 2 years ago

Hi. I am not wearing the watch and the watch does not have a passcode. Though I did unlock it while testing it. I will try to wear the watch now. Here is the log.

Using 'COM4' as serial port.
Showing logs:
[06:38:51]ts Jun[I][logger:214]: Log initialized
[06:38:51][C][ota:458]: There have been 2 suspected unsuccessful boot attempts.
[06:38:51][D][esp32.preferences:114]: Saving preferences to flash...
[06:38:51][I][app:029]: Running through setup()...
[06:38:51][D][esp32_ble_tracker:214]: Starting scan...
[06:38:51][C][wifi:037]: Setting up WiFi...
[06:38:52][I][wifi:245]: WiFi Connecting to 'rice_dwarf'...
[06:38:52][D][binary_sensor:036]: 'Duc hallway presence': Sending state OFF
[06:38:55][W][esp32_ble_tracker:085]: Too many BLE events to process. Some devices may not show up.
[06:38:55][I][wifi:502]: WiFi Connected!
[06:38:55][C][wifi:350]:   Local MAC: xxxxxxxxx
[06:38:56][C][wifi:351]:   SSID: 'rice_dwarf'
[06:38:56][C][wifi:352]:   IP Address: 192.168.1.201
[06:38:56][C][wifi:354]:   BSSID: E4:C3:2A:27:66:4F
[06:38:56][C][wifi:355]:   Hostname: 'hallway'
[06:38:56][C][wifi:357]:   Signal strength: -86 dB ▂▄▆█
[06:38:56][C][wifi:361]:   Channel: 7
[06:38:56][C][wifi:362]:   Subnet: 255.255.255.0
[06:38:56][C][wifi:363]:   Gateway: 192.168.1.1
[06:38:56][C][wifi:364]:   DNS1: 0.0.0.0
[06:38:56][C][wifi:365]:   DNS2: 0.0.0.0
[06:38:56][C][ota:082]: Over-The-Air Updates:
[06:38:56][C][ota:083]:   Address: 192.168.1.201:3232
[06:38:56][C][ota:086]:   Using Password.
[06:38:56][W][ota:092]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[06:38:56][C][api:025]: Setting up Home Assistant API server...
[06:38:56][C][mqtt:029]: Setting up MQTT...
[06:38:56][I][mqtt:174]: Connecting to MQTT...
[06:38:56][I][mqtt:214]: MQTT Connected!
[06:38:56][I][app:062]: setup() finished successfully!
[06:38:56][I][app:102]: ESPHome version 2021.12.3 compiled on Feb  3 2022, 08:17:58
[06:38:56][C][wifi:488]: WiFi:
[06:38:56][C][wifi:350]:   Local MAC: xxxxx
[06:38:56][C][wifi:351]:   SSID: 'rice_dwarf'
[06:38:56][C][wifi:352]:   IP Address: 192.168.1.201
[06:38:56][C][wifi:354]:   BSSID: E4:C3:2A:27:66:4F
[06:38:56][C][wifi:355]:   Hostname: 'hallway'
[06:38:56][C][wifi:357]:   Signal strength: -87 dB ▂▄▆█
[06:38:56][C][wifi:361]:   Channel: 7
[06:38:56][C][wifi:362]:   Subnet: 255.255.255.0
[06:38:56][C][wifi:363]:   Gateway: 192.168.1.1
[06:38:56][C][wifi:364]:   DNS1: 0.0.0.0
[06:38:56][C][wifi:365]:   DNS2: 0.0.0.0
[06:38:56][C][logger:233]: Logger:
[06:38:56][C][logger:234]:   Level: DEBUG
[06:38:56][C][logger:235]:   Log Baud Rate: 115200
[06:38:56][C][logger:236]:   Hardware UART: UART0
[06:38:56][C][template.sensor:023]: Template Sensor 'Duc Apple Watch hallway RSSI'
[06:38:56][C][template.sensor:023]:   Device Class: 'signal_strength'
[06:38:56][C][template.sensor:023]:   State Class: ''
[06:38:56][C][template.sensor:023]:   Unit of Measurement: 'dBm'
[06:38:56][C][template.sensor:023]:   Accuracy Decimals: 0
[06:38:56][C][template.sensor:024]:   Update Interval: 60.0s
[06:38:56][C][template.sensor:023]: Template Sensor 'room_presence_debounce'
[06:38:56][C][template.sensor:023]:   State Class: ''
[06:38:56][C][template.sensor:023]:   Unit of Measurement: ''
[06:38:56][C][template.sensor:023]:   Accuracy Decimals: 1
[06:38:56][C][template.sensor:024]:   Update Interval: 60.0s
[06:38:56][C][template.binary_sensor:018]: Template Binary Sensor 'Duc hallway presence'
[06:38:56][C][template.binary_sensor:018]:   Device Class: 'occupancy'
[06:38:56][C][esp32_ble_tracker:705]: BLE Tracker:
[06:38:56][C][esp32_ble_tracker:706]:   Scan Duration: 300 s
[06:38:56][C][esp32_ble_tracker:707]:   Scan Interval: 1200.0 ms
[06:38:56][C][esp32_ble_tracker:708]:   Scan Window: 500.0 ms
[06:38:56][C][esp32_ble_tracker:709]:   Scan Type: PASSIVE
[06:38:56][C][captive_portal:144]: Captive Portal:
[06:38:56][C][ota:082]: Over-The-Air Updates:
[06:38:56][C][ota:083]:   Address: 192.168.1.201:3232
[06:38:56][C][ota:086]:   Using Password.
[06:38:56][W][ota:092]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[06:38:56][C][api:134]: API Server:
[06:38:56][C][api:135]:   Address: 192.168.1.201:6053
[06:38:56][C][api:139]:   Using noise encryption: NO
[06:38:56][C][mqtt:063]: MQTT:
[06:38:56][C][mqtt:065]:   Server Address: 192.168.1.20:1883 (192.168.1.20)
[06:38:56][C][mqtt:066]:   Username: 'mqttuser'
[06:38:56][C][mqtt:067]:   Client ID: 'hallway-7c9ebdedc954'
[06:38:56][C][mqtt:072]:   Topic Prefix: 'esphome/hallway'
[06:38:56][C][mqtt:074]:   Log Topic: 'esphome/hallway/debug'
[06:38:56][C][mqtt:077]:   Availability: 'esphome/hallway/status'
[06:38:56][C][mdns:084]: mDNS:
[06:38:56][C][mdns:085]:   Hostname: hallway
[06:38:57][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Present Value'
[06:38:57][C][homeassistant.sensor:030]:   State Class: ''
[06:38:57][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[06:38:57][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[06:38:57][C][homeassistant.sensor:031]:   Entity ID: 'input_number.duc_watch_present'
[06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Present Value':
[06:38:57][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_present_value/state'
[06:38:57][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Not Present Value'
[06:38:57][C][homeassistant.sensor:030]:   State Class: ''
[06:38:57][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[06:38:57][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[06:38:57][C][homeassistant.sensor:031]:   Entity ID: 'input_number.duc_watch_not_present'
[06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Not Present Value':
[06:38:57][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_not_present_value/state'
[06:38:57][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Duc hallway presence':
[06:38:57][C][mqtt.binary_sensor:023]:   State Topic: 'esphome/hallway/binary_sensor/duc_hallway_presence/state'
[06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'Duc Apple Watch hallway RSSI':
[06:38:57][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/duc_apple_watch_hallway_rssi/state'
[06:43:51][I][ota:102]: Boot seems successful, resetting boot loop counter.
[06:43:51][D][esp32.preferences:114]: Saving preferences to flash...
[06:43:51][D][esp32_ble_tracker:214]: Starting scan...
dalehumby commented 2 years ago

I’ve noticed the log did not go further than Starting scan. Is this because there weren’t any more (useful) logs?

Sometimes (or maybe some) ESP32s lock up and Bluetooth scanning doesn’t work properly.

Under scan_parameters: try remove interval: 1.2s and window: 500ms so that the default values are used.

If you start getting BLE logs, then you can add those two lines back, but try a lower window, like 300ms or 100ms.

On 03 Feb 2022, at 22:46, duceduc @.***> wrote:

 Hi. I am not wearing the watch and the watch does not have a passcode. Though I did unlock it while testing it. I will try to wear the watch now. Here is the log.

Using 'COM4' as serial port. Showing logs: [06:38:51]ts Jun[I][logger:214]: Log initialized [06:38:51][C][ota:458]: There have been 2 suspected unsuccessful boot attempts. [06:38:51][D][esp32.preferences:114]: Saving preferences to flash... [06:38:51][I][app:029]: Running through setup()... [06:38:51][D][esp32_ble_tracker:214]: Starting scan... [06:38:51][C][wifi:037]: Setting up WiFi... [06:38:52][I][wifi:245]: WiFi Connecting to 'rice_dwarf'... [06:38:52][D][binary_sensor:036]: 'Duc hallway presence': Sending state OFF [06:38:55][W][esp32_ble_tracker:085]: Too many BLE events to process. Some devices may not show up. [06:38:55][I][wifi:502]: WiFi Connected! [06:38:55][C][wifi:350]: Local MAC: xxxxxxxxx

[06:38:56][C][wifi:352]: IP Address: 192.168.1.201 [06:38:56][C][wifi:354]: BSSID: E4:C3:2A:27:66:4F

[06:38:56][C][wifi:357]: Signal strength: -86 dB ▂▄▆█ [06:38:56][C][wifi:361]: Channel: 7 [06:38:56][C][wifi:362]: Subnet: 255.255.255.0 [06:38:56][C][wifi:363]: Gateway: 192.168.1.1 [06:38:56][C][wifi:364]: DNS1: 0.0.0.0 [06:38:56][C][wifi:365]: DNS2: 0.0.0.0 [06:38:56][C][ota:082]: Over-The-Air Updates: [06:38:56][C][ota:083]: Address: 192.168.1.201:3232 [06:38:56][C][ota:086]: Using Password. [06:38:56][W][ota:092]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts [06:38:56][C][api:025]: Setting up Home Assistant API server... [06:38:56][C][mqtt:029]: Setting up MQTT... [06:38:56][I][mqtt:174]: Connecting to MQTT... [06:38:56][I][mqtt:214]: MQTT Connected! [06:38:56][I][app:062]: setup() finished successfully! [06:38:56][I][app:102]: ESPHome version 2021.12.3 compiled on Feb 3 2022, 08:17:58

[06:38:56][C][wifi:350]: Local MAC: xxxxx

[06:38:56][C][wifi:352]: IP Address: 192.168.1.201 [06:38:56][C][wifi:354]: BSSID: E4:C3:2A:27:66:4F

[06:38:56][C][wifi:357]: Signal strength: -87 dB ▂▄▆█ [06:38:56][C][wifi:361]: Channel: 7 [06:38:56][C][wifi:362]: Subnet: 255.255.255.0 [06:38:56][C][wifi:363]: Gateway: 192.168.1.1 [06:38:56][C][wifi:364]: DNS1: 0.0.0.0 [06:38:56][C][wifi:365]: DNS2: 0.0.0.0

[06:38:56][C][logger:234]: Level: DEBUG [06:38:56][C][logger:235]: Log Baud Rate: 115200 [06:38:56][C][logger:236]: Hardware UART: UART0 [06:38:56][C][template.sensor:023]: Template Sensor 'Duc Apple Watch hallway RSSI' [06:38:56][C][template.sensor:023]: Device Class: 'signal_strength' [06:38:56][C][template.sensor:023]: State Class: '' [06:38:56][C][template.sensor:023]: Unit of Measurement: 'dBm' [06:38:56][C][template.sensor:023]: Accuracy Decimals: 0 [06:38:56][C][template.sensor:024]: Update Interval: 60.0s [06:38:56][C][template.sensor:023]: Template Sensor 'room_presence_debounce' [06:38:56][C][template.sensor:023]: State Class: '' [06:38:56][C][template.sensor:023]: Unit of Measurement: '' [06:38:56][C][template.sensor:023]: Accuracy Decimals: 1 [06:38:56][C][template.sensor:024]: Update Interval: 60.0s [06:38:56][C][template.binary_sensor:018]: Template Binary Sensor 'Duc hallway presence' [06:38:56][C][template.binary_sensor:018]: Device Class: 'occupancy' [06:38:56][C][esp32_ble_tracker:705]: BLE Tracker: [06:38:56][C][esp32_ble_tracker:706]: Scan Duration: 300 s [06:38:56][C][esp32_ble_tracker:707]: Scan Interval: 1200.0 ms [06:38:56][C][esp32_ble_tracker:708]: Scan Window: 500.0 ms [06:38:56][C][esp32_ble_tracker:709]: Scan Type: PASSIVE [06:38:56][C][captive_portal:144]: Captive Portal: [06:38:56][C][ota:082]: Over-The-Air Updates: [06:38:56][C][ota:083]: Address: 192.168.1.201:3232 [06:38:56][C][ota:086]: Using Password. [06:38:56][W][ota:092]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts [06:38:56][C][api:134]: API Server: [06:38:56][C][api:135]: Address: 192.168.1.201:6053 [06:38:56][C][api:139]: Using noise encryption: NO

[06:38:56][C][mqtt:065]: Server Address: 192.168.1.20:1883 (192.168.1.20)

[06:38:56][C][mqtt:067]: Client ID: 'hallway-7c9ebdedc954' [06:38:56][C][mqtt:072]: Topic Prefix: 'esphome/hallway' [06:38:56][C][mqtt:074]: Log Topic: 'esphome/hallway/debug'

[06:38:56][C][mdns:085]: Hostname: hallway [06:38:57][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Present Value' [06:38:57][C][homeassistant.sensor:030]: State Class: '' [06:38:57][C][homeassistant.sensor:030]: Unit of Measurement: '' [06:38:57][C][homeassistant.sensor:030]: Accuracy Decimals: 1 [06:38:57][C][homeassistant.sensor:031]: Entity ID: 'input_number.duc_watch_present' [06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Present Value': [06:38:57][C][mqtt.sensor:031]: State Topic: 'esphome/hallway/sensor/ha_rssi_present_value/state' [06:38:57][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Not Present Value' [06:38:57][C][homeassistant.sensor:030]: State Class: '' [06:38:57][C][homeassistant.sensor:030]: Unit of Measurement: '' [06:38:57][C][homeassistant.sensor:030]: Accuracy Decimals: 1 [06:38:57][C][homeassistant.sensor:031]: Entity ID: 'input_number.duc_watch_not_present' [06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Not Present Value': [06:38:57][C][mqtt.sensor:031]: State Topic: 'esphome/hallway/sensor/ha_rssi_not_present_value/state' [06:38:57][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Duc hallway presence': [06:38:57][C][mqtt.binary_sensor:023]: State Topic: 'esphome/hallway/binary_sensor/duc_hallway_presence/state' [06:38:57][C][mqtt.sensor:027]: MQTT Sensor 'Duc Apple Watch hallway RSSI': [06:38:57][C][mqtt.sensor:031]: State Topic: 'esphome/hallway/sensor/duc_apple_watch_hallway_rssi/state' [06:43:51][I][ota:102]: Boot seems successful, resetting boot loop counter. [06:43:51][D][esp32.preferences:114]: Saving preferences to flash... [06:43:51][D][esp32_ble_tracker:214]: Starting scan... — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

duceduc commented 2 years ago
I’ve noticed the log did not go further than `Starting scan`. Is this because there weren’t any more (useful) logs?

Yes, no more logs. I also notice with that message it just stays like that for over 5 -10. Then it repeats with my wifi settings logs.

duceduc commented 2 years ago

I will try removing those two inputs and test again. During compiling, I am seeing these warnings. Ok to ignore them?

INFO Reading configuration /config/esphome/hallway.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing hallway (board: nodemcu-32s; framework: arduino; platform: platformio/espressif32 @ 3.3.2)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <WiFi> 1.0
|-- <FS> 1.0
|-- <Update> 1.0
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <AsyncTCP-esphome> 1.2.2
|-- <DNSServer> 1.1.0
|-- <AsyncMqttClient-esphome> 0.8.6
|   |-- <AsyncTCP-esphome> 1.2.2
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESPmDNS> 1.0
Compiling /data/hallway/.pioenvs/hallway/src/main.cpp.o
src/main.cpp:259:3: warning: multi-line comment [-Wcomment]
   //         \ status_flags == 2) {\n      best_rssi = max(rssi, best_rssi.value_or(rssi));\n\
   ^
/config/esphome/hallway.yaml: In static member function 'static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Functor = setup()::<lambda(const esphome::esp32_ble_tracker::ESPBTDevice&)>; _ArgTypes = {const esphome::esp32_ble_tracker::ESPBTDevice&}]':
/config/esphome/hallway.yaml:69:40: warning: '*((void*)& best_rssi +2)' may be used uninitialized in this function [-Wmaybe-uninitialized]
             id(apple_watch_rssi).publish_state(*best_rssi);
                                        ^
/config/esphome/hallway.yaml:49:25: note: '*((void*)& best_rssi +2)' was declared here
           optional<int16_t> best_rssi = nullopt;
                         ^
Linking /data/hallway/.pioenvs/hallway/firmware.elf
duceduc commented 2 years ago

Removed the 2 lines as suggested. Doesn't seem to have any affect. Still stuck on starting scan.....

Using 'COM4' as serial port.
Writing at 0x0018d4ff... (100 %)Wrote 1570128 bytes (938511 compressed) at 0x00010000 in 22.0 seconds (effective 571.7 kbit/s)...
Hash of data verified.

Leaving...
Hard Resetting...
Hard resetting via RTS pin...
Done! Flashing is complete!

Showing logs:
[07:37:57][I][logger:214]: Log initialized
[07:37:57][C][ota:458]: There have been 0 suspected unsuccessful boot attempts.
[07:37:57][D][esp32.preferences:114]: Saving preferences to flash...
[07:37:57][I][app:029]: Running through setup()...
[07:37:58][D][esp32_ble_tracker:214]: Starting scan...
[07:37:58][C][wifi:037]: Setting up WiFi...
[07:37:58][I][wifi:245]: WiFi Connecting to 'rice_dwarf'...
[07:37:58][D][binary_sensor:036]: 'Duc hallway presence': Sending state OFF
[07:38:02][I][wifi:502]: WiFi Connected!
[07:38:02][C][wifi:350]:   Local MAC: xxxxx
[07:38:02][C][wifi:351]:   SSID: 'rice_dwarf'
[07:38:02][C][wifi:352]:   IP Address: 192.168.1.201
[07:38:02][C][wifi:354]:   BSSID: E4:C3:2A:27:66:4F
[07:38:02][C][wifi:355]:   Hostname: 'hallway'
[07:38:02][C][wifi:357]:   Signal strength: -86 dB ▂▄▆█
[07:38:02][C][wifi:361]:   Channel: 7
[07:38:02][C][wifi:362]:   Subnet: 255.255.255.0
[07:38:02][C][wifi:363]:   Gateway: 192.168.1.1
[07:38:02][C][wifi:364]:   DNS1: 0.0.0.0
[07:38:02][C][wifi:365]:   DNS2: 0.0.0.0
[07:38:02][C][ota:082]: Over-The-Air Updates:
[07:38:02][C][ota:083]:   Address: 192.168.1.201:3232
[07:38:02][C][ota:086]:   Using Password.
[07:38:02][C][api:025]: Setting up Home Assistant API server...
[07:38:02][C][mqtt:029]: Setting up MQTT...
[07:38:02][I][mqtt:174]: Connecting to MQTT...
[07:38:03][I][mqtt:214]: MQTT Connected!
[07:38:03][I][app:062]: setup() finished successfully!
[07:38:03][I][app:102]: ESPHome version 2021.12.3 compiled on Feb  4 2022, 07:33:02
[07:38:03][C][wifi:488]: WiFi:
[07:38:03][C][wifi:350]:   Local MAC: xxxx
[07:38:03][C][wifi:351]:   SSID: 'rice_dwarf'
[07:38:03][C][wifi:352]:   IP Address: 192.168.1.201
[07:38:03][C][wifi:354]:   BSSID: E4:C3:2A:27:66:4F
[07:38:03][C][wifi:355]:   Hostname: 'hallway'
[07:38:03][C][wifi:357]:   Signal strength: -84 dB ▂▄▆█
[07:38:03][C][wifi:361]:   Channel: 7
[07:38:03][C][wifi:362]:   Subnet: 255.255.255.0
[07:38:03][C][wifi:363]:   Gateway: 192.168.1.1
[07:38:03][C][wifi:364]:   DNS1: 0.0.0.0
[07:38:03][C][wifi:365]:   DNS2: 0.0.0.0
[07:38:03][C][logger:233]: Logger:
[07:38:03][C][logger:234]:   Level: DEBUG
[07:38:03][C][logger:235]:   Log Baud Rate: 115200
[07:38:03][C][logger:236]:   Hardware UART: UART0
[07:38:03][C][template.sensor:023]: Template Sensor 'Duc Apple Watch hallway RSSI'
[07:38:03][C][template.sensor:023]:   Device Class: 'signal_strength'
[07:38:03][C][template.sensor:023]:   State Class: ''
[07:38:03][C][template.sensor:023]:   Unit of Measurement: 'dBm'
[07:38:03][C][template.sensor:023]:   Accuracy Decimals: 0
[07:38:03][C][template.sensor:024]:   Update Interval: 60.0s
[07:38:03][C][template.sensor:023]: Template Sensor 'room_presence_debounce'
[07:38:03][C][template.sensor:023]:   State Class: ''
[07:38:03][C][template.sensor:023]:   Unit of Measurement: ''
[07:38:03][C][template.sensor:023]:   Accuracy Decimals: 1
[07:38:03][C][template.sensor:024]:   Update Interval: 60.0s
[07:38:03][C][template.binary_sensor:018]: Template Binary Sensor 'Duc hallway presence'
[07:38:03][C][template.binary_sensor:018]:   Device Class: 'occupancy'
[07:38:03][C][esp32_ble_tracker:705]: BLE Tracker:
[07:38:03][C][esp32_ble_tracker:706]:   Scan Duration: 300 s
[07:38:03][C][esp32_ble_tracker:707]:   Scan Interval: 320.0 ms
[07:38:03][C][esp32_ble_tracker:708]:   Scan Window: 30.0 ms
[07:38:03][C][esp32_ble_tracker:709]:   Scan Type: PASSIVE
[07:38:03][C][captive_portal:144]: Captive Portal:
[07:38:03][C][ota:082]: Over-The-Air Updates:
[07:38:03][C][ota:083]:   Address: 192.168.1.201:3232
[07:38:03][C][ota:086]:   Using Password.
[07:38:03][C][api:134]: API Server:
[07:38:03][C][api:135]:   Address: 192.168.1.201:6053
[07:38:03][C][api:139]:   Using noise encryption: NO
[07:38:03][C][mqtt:063]: MQTT:
[07:38:03][C][mqtt:065]:   Server Address: 192.168.1.20:1883 (192.168.1.20)
[07:38:03][C][mqtt:066]:   Username: 'mqttuser'
[07:38:03][C][mqtt:067]:   Client ID: 'hallway-7c9ebdedc954'
[07:38:03][C][mqtt:072]:   Topic Prefix: 'esphome/hallway'
[07:38:03][C][mqtt:074]:   Log Topic: 'esphome/hallway/debug'
[07:38:03][C][mqtt:077]:   Availability: 'esphome/hallway/status'
[07:38:03][C][mdns:084]: mDNS:
[07:38:03][C][mdns:085]:   Hostname: hallway
[07:38:03][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Present Value'
[07:38:03][C][homeassistant.sensor:030]:   State Class: ''
[07:38:03][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[07:38:03][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[07:38:03][C][homeassistant.sensor:031]:   Entity ID: 'input_number.duc_watch_present'
[07:38:03][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Present Value':
[07:38:03][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_present_value/state'
[07:38:03][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Not Present Value'
[07:38:03][C][homeassistant.sensor:030]:   State Class: ''
[07:38:03][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[07:38:03][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[07:38:03][C][homeassistant.sensor:031]:   Entity ID: 'input_number.duc_watch_not_present'
[07:38:03][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Not Present Value':
[07:38:03][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_not_present_value/state'
[07:38:03][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Duc hallway presence':
[07:38:03][C][mqtt.binary_sensor:023]:   State Topic: 'esphome/hallway/binary_sensor/duc_hallway_presence/state'
[07:38:03][C][mqtt.sensor:027]: MQTT Sensor 'Duc Apple Watch hallway RSSI':
[07:38:03][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/duc_apple_watch_hallway_rssi/state'

[07:42:57][I][ota:102]: Boot seems successful, resetting boot loop counter.
[07:42:57][D][esp32.preferences:114]: Saving preferences to flash...
[07:42:58][D][esp32_ble_tracker:214]: Starting scan...
0nikola1 commented 2 years ago

You can find watch by logging all bluetooth traffic and search for apple related sensors till you find your info. You do so by enabling


logger:
   level: VERY_VERBOSE

I don't know how well will it work on regular ESP32 as I used it on ethernet version. For my Apple Watch SE I had to set data_flags == 0x18 as it have this instead of data_flags == 0x98 when unlocked as in example.

dalehumby commented 2 years ago

Hi @duceduc - I've tested a bunch of config changes on my ESP32 and HA, and I cannot get it to not detect my Watch. I'm using the exact same yaml as in this repo. My device is an ESP32-WROOM-32, in the "D1 mini" form factor.

I did change my logging level to VERY_VERBOSE as suggested by @0nikola1, and I got the following:

[21:33:12][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.09 s).
[21:33:12][V][component:200]: Components should block for at most 20-30ms.

It may be that some ESP's are a little slower (why?) and that is causing the bluetooth thread to not complete?

duceduc commented 2 years ago

I have switched over the a esp32 d1 mini just like the img you have in the read me file. Here are my log. Doesn't seems like my watch are being picked up still.

config:

  substitutions:
    roomname: hallway
    static_ip: 192.168.1.201
    yourname: Duc
    rssi_present: id(harssi_present).state
    rssi_not_present: id(harssi_not_present).state

  esphome:
    name: $roomname
    platform: ESP32
    board: wemos_d1_mini32 # nodemcu-32s esp-wrover-kit

  wifi:
    ssid: !secret ssid_3
    password: !secret ssid_pass
    fast_connect : true
    manual_ip:
      static_ip: $static_ip
      subnet: 255.255.255.0
      gateway: 192.168.1.1

  captive_portal:

  logger:
    level: VERY_VERBOSE

  api:

  ota:
    password: !secret ota_pass

  mqtt:
    topic_prefix: esphome/$roomname
    discovery: false
    broker: 192.168.1.20
    username: !secret mqtt_user
    password: !secret mqtt_pass

  esp32_ble_tracker:
    scan_parameters:
      interval: 1.2s
      window: 500ms
      active: false
    on_ble_advertise:
      - then:
        # Look for manufacturer data of form: 4c00 10 05 YY 98 XXXXXX
        # Where YY can be 01..0F or 20..2F; and XXXXXX is ignored
        - lambda: |-
            optional<int16_t> best_rssi = nullopt;
            for (auto data : x.get_manufacturer_datas()) {
              // Guard against non-Apple datagrams, or those that are too small.
              if (data.data.size() < 4 || data.uuid.to_string() != "0x004C" || data.data[0] != 0x10 || data.data[1] < 5) {
                continue;
              }
              const int16_t rssi = x.get_rssi();
              const uint8_t status_flags = data.data[2] >> 4;  // High nibble
              const uint8_t data_flags = data.data[3];

              if (data_flags == 0x98) {  // Match unlocked Apple Watch. To also match locked watch use: if (data_flags == 0x98 || data_flags == 0x18) {
                if (status_flags == 0 || status_flags == 2) {
                  best_rssi = max(rssi, best_rssi.value_or(rssi));
                  ESP_LOGD("ble_adv", "Found Apple Watch (mac %s) rssi %i", x.address_str().c_str(), rssi);
                } else {
                  ESP_LOGD("ble_adv", "Possible Apple Watch? (mac %s) rssi %i, unrecognised status/action flags %#04x", x.address_str().c_str(), rssi, data.data[2]);
                }
              }
            }
            if (best_rssi) {
              id(apple_watch_rssi).publish_state(*best_rssi);
            }

  sensor:
    - platform: template
      id: apple_watch_rssi
      name: "$yourname Apple Watch $roomname RSSI"
      device_class: signal_strength
      unit_of_measurement: dBm
      accuracy_decimals: 0
      filters:
        - exponential_moving_average:
            alpha: 0.3
            send_every: 1
      on_value:
        then:
          - lambda: |-
              if (id(apple_watch_rssi).state > $rssi_present) {
                id(room_presence_debounce).publish_state(1);
              } else if (id(apple_watch_rssi).state < $rssi_not_present) {
                id(room_presence_debounce).publish_state(0);
              }
          - script.execute: presence_timeout  # Publish 0 if no rssi received

    - platform: template
      id: room_presence_debounce
      filters:
        - sliding_window_moving_average:
            window_size: 3
            send_every: 1

    - platform: homeassistant
      name: HA RSSI Present Value
      entity_id: input_number.duc_watch_present  #insert your input.number entity id here
      id: harssi_present
    - platform: homeassistant
      name: HA RSSI Not Present Value
      entity_id: input_number.duc_watch_not_present  #insert your input.number entity id here
      id: harssi_not_present

  binary_sensor:
    - platform: template
      id: room_presence
      name: "$yourname $roomname presence"
      device_class: occupancy
      lambda: |-
        if (id(room_presence_debounce).state > 0.99) {
          return true;
        } else if (id(room_presence_debounce).state < 0.01) {
          return false;
        } else {
          return id(room_presence).state;
        }

  script:
    # Publish event every 30 seconds when no rssi received
    id: presence_timeout
    mode: restart
    then:
      - delay: 30s
      - lambda: |-
          id(room_presence_debounce).publish_state(0);
      - script.execute: presence_timeout

log:

INFO Reading configuration /config/esphome/hallway.yaml...
INFO Starting log output from 192.168.1.201 using esphome API
WARNING Can't connect to ESPHome API for 192.168.1.201: Error connecting to ('192.168.1.201', 6053): [Errno 113] Connect call failed ('192.168.1.201', 6053)
INFO Trying to reconnect to 192.168.1.201 in the background
INFO Successfully connected to 192.168.1.201
[06:57:41][I][app:102]: ESPHome version 2021.12.3 compiled on Feb 16 2022, 06:54:28
[06:57:41][C][wifi:488]: WiFi:
[06:57:41][C][wifi:350]:   Local MAC: 78:E3:6D:10:0D:B0
[06:57:41][C][wifi:351]:   SSID: [redacted]
[06:57:41][C][wifi:352]:   IP Address: 192.168.1.201
[06:57:41][C][wifi:354]:   BSSID: [redacted]
[06:57:41][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:41][VV][esp32_ble_tracker:510]:   Address: 7C:D1:C3:11:49:91 (PUBLIC)
[06:57:41][VV][esp32_ble_tracker:512]:   RSSI: -82
[06:57:41][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:41][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:57:42][VV][esp32_ble_tracker:527]:   Manufacturer data: 09.06.02.01.C0.A8.44.65 (8)
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.0B.FF.4C.00.09.06.02.01.C0.A8.44.65 (15)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: F4:F8:39:CD:40:FD (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -70
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: 63:E1:C4:17:02:22 (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -85
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0B.FF.4C.00.10.06.15.1A.F7.55.81.74 (18)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: 49:6D:1C:9D:22:63 (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -50
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:57:42][VV][esp32_ble_tracker:510]:   Address: E2:B3:C5:C1:0D:CC (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -63
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:42][VV][esp32_ble_tracker:527]:   Manufacturer data: E2.B3.C5.C1.0D.CC (6)
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E2.B3.C5.C1.0D.CC (13)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -51
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:42][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:57:42][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.46.BD.93.11.2F (13)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -68
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -65
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:57:42][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.03.18.44.23.E6 (7)
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.03.18.44.23.E6 (17)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: E2:B3:C5:C1:0D:CC (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -58
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:42][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:57:42][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:42][VV][esp32_ble_tracker:510]:   Address: 52:6E:D5:BE:35:C2 (RANDOM)
[06:57:42][VV][esp32_ble_tracker:512]:   RSSI: -81
[06:57:42][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:42][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:57:42][C][template.sensor:023]: Template Sensor 'Duc Apple Watch hallway RSSI'
[06:57:42][C][template.sensor:023]:   Device Class: 'signal_strength'
[06:57:42][C][template.sensor:023]:   State Class: ''
[06:57:42][C][template.sensor:023]:   Unit of Measurement: 'dBm'
[06:57:42][C][template.sensor:023]:   Accuracy Decimals: 0
[06:57:42][C][template.sensor:024]:   Update Interval: 60.0s
[06:57:42][C][template.sensor:023]:   Accuracy Decimals: 1
[06:57:42][C][template.binary_sensor:018]: Template Binary Sensor 'Duc hallway presence'
[06:57:42][C][template.binary_sensor:018]:   Device Class: 'occupancy'
[06:57:42][C][esp32_ble_tracker:705]: BLE Tracker:
[06:57:42][C][esp32_ble_tracker:706]:   Scan Duration: 300 s
[06:57:42][C][esp32_ble_tracker:707]:   Scan Interval: 1200.0 ms
[06:57:42][C][esp32_ble_tracker:708]:   Scan Window: 500.0 ms
[06:57:42][C][esp32_ble_tracker:709]:   Scan Type: PASSIVE
[06:57:42][C][captive_portal:144]: Captive Portal:
[06:57:42][C][ota:082]: Over-The-Air Updates:
[06:57:42][C][ota:083]:   Address: 192.168.1.201:3232
[06:57:42][C][ota:086]:   Using Password.
[06:57:42][C][api:134]: API Server:
[06:57:42][C][api:135]:   Address: 192.168.1.201:6053
[06:57:42][C][api:139]:   Using noise encryption: NO
[06:57:42][C][mqtt:063]: MQTT:
[06:57:42][C][mqtt:065]:   Server Address: 192.168.1.20:1883 (192.168.1.20)
[06:57:43][C][mqtt:066]:   Username: [redacted]
[06:57:43][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:43][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:57:43][VV][esp32_ble_tracker:512]:   RSSI: -52
[06:57:43][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:43][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:43][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.46.BD.93.11.2F (6)
[06:57:43][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.46.BD.93.11.2F (13)
[06:57:43][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:43][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:57:43][VV][esp32_ble_tracker:512]:   RSSI: -70
[06:57:43][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:43][VV][esp32_ble_tracker:527]:   Manufacturer data: 01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (27)
[06:57:43][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:57:43][V][component:200]: Components should block for at most 20-30ms.
[06:57:43][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:43][VV][esp32_ble_tracker:510]:   Address: E7:93:41:CC:F8:EA (RANDOM)
[06:57:43][VV][esp32_ble_tracker:512]:   RSSI: -48
[06:57:43][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:43][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:57:43][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.93.41.CC.F8.EA (6)
[06:57:43][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.93.41.CC.F8.EA (13)
[06:57:43][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:43][VV][esp32_ble_tracker:510]:   Address: AC:BC:32:68:DE:57 (PUBLIC)
[06:57:43][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:57:43][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.02.14.D5.37.5F (17)
[06:57:43][VV][esp32_ble_tracker:493]: Parse Result:
[06:57:43][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:57:43][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:57:43][VV][esp32_ble_tracker:513]:   Name: ''
[06:57:43][VV][esp32_ble_tracker:521]:   Ad Flag: 6
INFO 192.168.1.201: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for 192.168.1.201
WARNING Disconnected from API
INFO 192.168.1.201: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Successfully connected to 192.168.1.201
[06:57:55][VV][esp32_ble_tracker:493]: Parse Result:
INFO 192.168.1.201: Ping timed out!
INFO Disconnected from ESPHome API for 192.168.1.201
WARNING Disconnected from API
INFO Successfully connected to 192.168.1.201
[06:58:23][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:23][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:23][VV][esp32_ble_tracker:512]:   RSSI: -72
[06:58:23][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:23][VV][esp32_ble_tracker:527]:   Manufacturer data: 01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (27)
[06:58:23][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:23][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:23][VV][esp32_ble_tracker:510]:   Address: 73:C0:9C:0C:D4:13 (RANDOM)
[06:58:23][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:23][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:23][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:23][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.06.2A.1E.87.15.3D.A0 (8)
[06:58:24][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.08.0B.FF.4C.00.10.06.2A.1E.87.15.3D.A0 (18)
[06:58:24][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:24][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:24][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:24][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:24][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:24][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:24][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:24][VV][esp32_ble_tracker:512]:   RSSI: -90
[06:58:24][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:24][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:24][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.0B.FF.4C.00.09.06.02.01.C0.A8.44.65 (15)
[06:58:24][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:24][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:58:24][VV][esp32_ble_tracker:512]:   RSSI: -73
[06:58:24][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:24][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:24][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.46.BD.93.11.2F (6)
[06:58:24][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.46.BD.93.11.2F (13)
[06:58:24][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:24][VV][esp32_ble_tracker:510]:   Address: C9:F9:18:6C:A3:0D (RANDOM)
[06:58:24][VV][esp32_ble_tracker:512]:   RSSI: -72
[06:58:24][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:24][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:24][VV][esp32_ble_tracker:527]:   Manufacturer data: C9.F9.18.6C.A3.0D (6)
INFO 192.168.1.201: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for 192.168.1.201
WARNING Disconnected from API
INFO 192.168.1.201: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Successfully connected to 192.168.1.201
[06:58:39][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Present Value':
[06:58:39][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_present_value/state'
[06:58:39][C][homeassistant.sensor:030]: Homeassistant Sensor 'HA RSSI Not Present Value'
[06:58:39][C][homeassistant.sensor:030]:   State Class: ''
[06:58:39][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[06:58:39][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[06:58:39][C][homeassistant.sensor:031]:   Entity ID: 'input_number.duc_watch_not_present'
[06:58:39][C][mqtt.sensor:027]: MQTT Sensor 'HA RSSI Not Present Value':
[06:58:39][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/ha_rssi_not_present_value/state'
[06:58:39][C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Duc hallway presence':
[06:58:39][C][mqtt.binary_sensor:023]:   State Topic: 'esphome/hallway/binary_sensor/duc_hallway_presence/state'
[06:58:39][C][mqtt.sensor:027]: MQTT Sensor 'Duc Apple Watch hallway RSSI':
[06:58:39][C][mqtt.sensor:031]:   State Topic: 'esphome/hallway/sensor/duc_apple_watch_hallway_rssi/state'
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:510]:   Address: 63:E1:C4:17:02:22 (RANDOM)
[06:58:39][VV][esp32_ble_tracker:512]:   RSSI: -88
[06:58:39][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:39][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:39][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:39][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.06.15.1A.F7.55.81.74 (8)
[06:58:39][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0B.FF.4C.00.10.06.15.1A.F7.55.81.74 (18)
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:39][VV][esp32_ble_tracker:512]:   RSSI: -62
[06:58:39][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:39][VV][esp32_ble_tracker:527]:   Manufacturer data: 01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (27)
[06:58:39][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:39][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.11 s).
[06:58:39][V][component:200]: Components should block for at most 20-30ms.
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:510]:   Address: F4:F8:39:CD:40:FD (RANDOM)
[06:58:39][VV][esp32_ble_tracker:512]:   RSSI: -84
[06:58:39][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:39][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:39][VV][esp32_ble_tracker:527]:   Manufacturer data: F4.F8.39.CD.40.FD (6)
[06:58:39][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.F4.F8.39.CD.40.FD (13)
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:510]:   Address: 47:ED:D0:EE:41:E2 (RANDOM)
[06:58:39][VV][esp32_ble_tracker:512]:   RSSI: -67
[06:58:39][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.13.18.67.66.34 (7)
[06:58:39][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.13.18.67.66.34 (17)
[06:58:39][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:39][VV][esp32_ble_tracker:510]:   Address: 74:C5:81:8D:67:87 (RANDOM)
[06:58:39][VV][esp32_ble_tracker:512]:   RSSI: -69
[06:58:39][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:40][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:40][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:40][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.07.1D.1F.EE.08.4C.F9.18 (9)
[06:58:40][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0C.FF.4C.00.10.07.1D.1F.EE.08.4C.F9.18 (19)
[06:58:40][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:40][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:40][VV][esp32_ble_tracker:512]:   RSSI: -61
[06:58:40][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:40][VV][esp32_ble_tracker:527]:   Manufacturer data: 01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (27)
[06:58:40][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:40][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:40][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:40][VV][esp32_ble_tracker:512]:   RSSI: -69
[06:58:40][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:40][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:40][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:40][VV][esp32_ble_tracker:510]:   Address: 7A:90:45:8B:59:83 (RANDOM)
[06:58:40][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:40][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.02.18.F3.01.87 (7)
[06:58:40][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.18.0A.FF.4C.00.10.05.02.18.F3.01.87 (17)
[06:58:40][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.35 s).
[06:58:40][W][mqtt:259]: MQTT Disconnected: TCP disconnected.
[06:58:40][I][mqtt:174]: Connecting to MQTT...
[06:58:40][I][mqtt:214]: MQTT Connected!
[06:58:40][V][component:199]: Component mqtt took a long time for an operation (0.10 s).
[06:58:40][V][component:200]: Components should block for at most 20-30ms.
[06:58:40][V][mqtt:404]: Publish(topic='esphome/hallway/binary_sensor/duc_hallway_presence/state' payload='OFF' retain=1)
[06:58:40][V][mqtt:404]: Publish(topic='esphome/hallway/status' payload='online' retain=1)
[06:58:40][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:40][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:40][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:40][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:40][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:40][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:40][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
INFO 192.168.1.201: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for 192.168.1.201
WARNING Disconnected from API
INFO 192.168.1.201: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Successfully connected to 192.168.1.201
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: E2:B3:C5:C1:0D:CC (RANDOM)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -62
[06:58:54][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:54][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:54][VV][esp32_ble_tracker:527]:   Manufacturer data: E2.B3.C5.C1.0D.CC (6)
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E2.B3.C5.C1.0D.CC (13)
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: 73:C0:9C:0C:D4:13 (RANDOM)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -89
[06:58:54][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:54][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:54][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:54][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.06.2A.1E.87.15.3D.A4 (8)
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.08.0B.FF.4C.00.10.06.2A.1E.87.15.3D.A4 (18)
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: E2:B3:C5:C1:0D:CC (RANDOM)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -62
[06:58:54][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:54][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:54][VV][esp32_ble_tracker:527]:   Manufacturer data: E2.B3.C5.C1.0D.CC (6)
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E2.B3.C5.C1.0D.CC (13)
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: 7C:D1:C3:11:49:91 (PUBLIC)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -87
[06:58:54][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.24 s).
[06:58:54][V][component:200]: Components should block for at most 20-30ms.
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: C9:F9:18:6C:A3:0D (RANDOM)
[06:58:54][VV][esp32_ble_tracker:512]:   RSSI: -67
[06:58:54][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:54][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:54][VV][esp32_ble_tracker:527]:   Manufacturer data: C9.F9.18.6C.A3.0D (6)
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C9.F9.18.6C.A3.0D (13)
[06:58:54][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:54][VV][esp32_ble_tracker:510]:   Address: FA:B6:52:7B:50:4E (RANDOM)
[06:58:54][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.FA.B6.52.7B.50.4E (13)
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][W][mqtt:259]: MQTT Disconnected: TCP disconnected.
[06:58:55][I][mqtt:174]: Connecting to MQTT...
[06:58:55][I][mqtt:214]: MQTT Connected!
[06:58:55][V][component:199]: Component mqtt took a long time for an operation (0.10 s).
[06:58:55][V][component:200]: Components should block for at most 20-30ms.
[06:58:55][V][mqtt:404]: Publish(topic='esphome/hallway/binary_sensor/duc_hallway_presence/state' payload='OFF' retain=1)
[06:58:55][V][mqtt:404]: Publish(topic='esphome/hallway/status' payload='online' retain=1)
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][VV][esp32_ble_tracker:510]:   Address: 49:6D:1C:9D:22:63 (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -55
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:55][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:55][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.07.1D.1F.EE.08.4C.F9.18 (9)
[06:58:55][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0C.FF.4C.00.10.07.1D.1F.EE.08.4C.F9.18 (19)
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -61
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:55][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.13 s).
[06:58:55][V][component:200]: Components should block for at most 20-30ms.
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][VV][esp32_ble_tracker:510]:   Address: E7:93:41:CC:F8:EA (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:55][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.93.41.CC.F8.EA (6)
[06:58:55][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.93.41.CC.F8.EA (13)
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][VV][esp32_ble_tracker:510]:   Address: 52:6E:D5:BE:35:C2 (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -81
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:510]:   Address: F4:F8:39:CD:40:FD (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -75
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:55][VV][esp32_ble_tracker:527]:   Manufacturer data: F4.F8.39.CD.40.FD (6)
[06:58:55][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.F4.F8.39.CD.40.FD (13)
[06:58:55][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:55][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:55][VV][esp32_ble_tracker:512]:   RSSI: -69
[06:58:55][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:55][VV][esp32_ble_tracker:527]:   Manufacturer data: 01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (27)
[06:58:55][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:55][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.24 s).
[06:58:55][V][component:200]: Components should block for at most 20-30ms.
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -50
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: 12.02.00.02 (4)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 07.FF.4C.00.12.02.00.02 (8)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -48
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -55
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 47:ED:D0:EE:41:E2 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -74
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.13.18.67.66.34 (7)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.13.18.67.66.34 (17)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -62
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 3D:D4:FE:DC:26:38 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -69
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 1E.FF.06.00.01.09.20.02.B7.21.7F.C7.57.BB.A5.B8.40.46.DC.0D.CE.5A.E6.AD.6F.A3.EE.0A.72.18.C9 (31)
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 63:E1:C4:17:02:22 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -87
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0B.FF.4C.00.10.06.15.1A.F7.55.81.74 (18)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 7A:90:45:8B:59:83 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -42
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.02.18.F3.01.87 (7)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.18.0A.FF.4C.00.10.05.02.18.F3.01.87 (17)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 74:C5:81:8D:67:87 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.03.18.44.23.E6 (7)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.03.18.44.23.E6 (17)
[06:58:56][V][component:200]: Components should block for at most 20-30ms.
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: FA:D7:E3:2A:4D:BF (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -91
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: FA.D7.E3.2A.4D.BF.45.0C.05.A1.08.45.81 (13)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.10.FF.69.09.FA.D7.E3.2A.4D.BF.45.0C.05.A1.08.45.81 (20)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -58
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.46.BD.93.11.2F (6)
[06:58:56][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.46.BD.93.11.2F (13)
[06:58:56][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:56][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -50
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:56][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:56][VV][esp32_ble_tracker:510]:   Address: 63:E1:C4:17:02:22 (RANDOM)
[06:58:56][VV][esp32_ble_tracker:512]:   RSSI: -85
[06:58:56][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:57][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:57][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.06.15.1A.F7.55.81.74 (8)
[06:58:57][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0B.FF.4C.00.10.06.15.1A.F7.55.81.74 (18)
[06:58:57][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.21 s).
[06:58:57][V][component:200]: Components should block for at most 20-30ms.
[06:58:57][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:57][VV][esp32_ble_tracker:510]:   Address: E2:B3:C5:C1:0D:CC (RANDOM)
[06:58:57][VV][esp32_ble_tracker:512]:   RSSI: -65
[06:58:57][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:57][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: E2.B3.C5.C1.0D.CC (6)
[06:58:57][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E2.B3.C5.C1.0D.CC (13)
[06:58:57][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:57][VV][esp32_ble_tracker:510]:   Address: E7:93:41:CC:F8:EA (RANDOM)
[06:58:57][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:57][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:57][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.93.41.CC.F8.EA (6)
[06:58:57][VV][esp32_ble_tracker:510]:   Address: D8:09:BF:A4:6D:3E (RANDOM)
[06:58:57][VV][esp32_ble_tracker:512]:   RSSI: -82
[06:58:57][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: 12.02.00.03 (4)
[06:58:57][VV][esp32_ble_tracker:543]: Adv data: 07.FF.4C.00.12.02.00.03 (8)
[06:58:57][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:57][VV][esp32_ble_tracker:510]:   Address: E7:46:BD:93:11:2F (RANDOM)
[06:58:57][VV][esp32_ble_tracker:512]:   RSSI: -75
[06:58:57][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:57][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: E7.46.BD.93.11.2F (6)
[06:58:57][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E7.46.BD.93.11.2F (13)
[06:58:57][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:57][VV][esp32_ble_tracker:510]:   Address: 49:6D:1C:9D:22:63 (RANDOM)
[06:58:57][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.07.1D.1F.EE.08.4C.F9.18 (9)
[06:58:57][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0C.FF.4C.00.10.07.1D.1F.EE.08.4C.F9.18 (19)
[06:58:57][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:57][VV][esp32_ble_tracker:510]:   Address: 73:C0:9C:0C:D4:13 (RANDOM)
[06:58:57][VV][esp32_ble_tracker:512]:   RSSI: -92
[06:58:57][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:58][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:58][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:58][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.06.2A.1E.87.15.3D.A4 (8)
[06:58:58][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.08.0B.FF.4C.00.10.06.2A.1E.87.15.3D.A4 (18)
[06:58:58][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:58][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:58][VV][esp32_ble_tracker:512]:   RSSI: -50
[06:58:58][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:58][VV][esp32_ble_tracker:527]:   Manufacturer data: E2.B3.C5.C1.0D.CC (6)
[06:58:58][VV][esp32_ble_tracker:510]:   Address: 76:AC:51:D3:82:8C (RANDOM)
[06:58:58][VV][esp32_ble_tracker:512]:   RSSI: -87
[06:58:58][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:58][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:58][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:58][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.18.18.36.E0.9D (7)
[06:58:58][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.18.18.36.E0.9D (17)
[06:58:58][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.06 s).
[06:58:58][V][component:200]: Components should block for at most 20-30ms.
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -56
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: 47:ED:D0:EE:41:E2 (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -71
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.13.18.67.66.34 (7)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.0C.0A.FF.4C.00.10.05.13.18.67.66.34 (17)
[06:58:59][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.09 s).
[06:58:59][V][component:200]: Components should block for at most 20-30ms.
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: FA:B6:52:7B:50:4E (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -80
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: FA.B6.52.7B.50.4E (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.FA.B6.52.7B.50.4E (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:59][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:59][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.16 s).
[06:58:59][V][component:200]: Components should block for at most 20-30ms.
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: 4F:A3:DF:F3:CD:FD (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -95
[06:58:59][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.03.18.4D.AC.5B (7)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0A.FF.4C.00.10.05.03.18.4D.AC.5B (17)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -48
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:59][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -55
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: 74:C5:81:8D:67:87 (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -71
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:515]:   TX Power: 2
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 26
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: 10.05.03.18.44.23.E6 (7)
[06:58:59][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.21 s).
[06:58:59][V][component:200]: Components should block for at most 20-30ms.
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: C5:C6:DF:94:48:BC (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -46
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: 63:E1:C4:17:02:22 (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -83
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.1A.02.0A.07.0B.FF.4C.00.10.06.15.1A.F7.55.81.74 (18)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: E3:45:9C:38:42:FE (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -49
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: E3.45.9C.38.42.FE (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.E3.45.9C.38.42.FE (13)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: EA:E8:AE:0D:7F:9C (RANDOM)
[06:58:59][VV][esp32_ble_tracker:512]:   RSSI: -89
[06:58:59][VV][esp32_ble_tracker:513]:   Name: ''
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: 12.02.00.01 (4)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 07.FF.4C.00.12.02.00.01 (8)
[06:58:59][VV][esp32_ble_tracker:493]: Parse Result:
[06:58:59][VV][esp32_ble_tracker:510]:   Address: AC:BC:32:68:DE:57 (PUBLIC)
[06:58:59][VV][esp32_ble_tracker:521]:   Ad Flag: 6
[06:58:59][VV][esp32_ble_tracker:527]:   Manufacturer data: C5.C6.DF.94.48.BC (6)
[06:58:59][VV][esp32_ble_tracker:543]: Adv data: 02.01.06.09.FF.59.00.C5.C6.DF.94.48.BC (13)
[06:58:59][V][component:199]: Component esp32_ble_tracker took a long time for an operation (0.25 s).
[06:58:59][V][component:200]: Components should block for at most 20-30ms.
[06:59:00][I][mqtt:174]: Connecting to MQTT...
[06:59:00][I][mqtt:214]: MQTT Connected!
0nikola1 commented 2 years ago

Based on info you sent I think watch is ... 4C.00.10.05.03.18.XX.XX.XX as It's same as mine apple watch SE ...4C.00.10.05.06.18.XX.XX.XX and you need to change detection to use data_flags == 0x18) as below


  on_ble_advertise:
    - then:
      # Look for manufacturer data of form: 4c00 10 05 YY 98 XXXXXX
      # Where YY can be 01..0F or 20..2F; and XXXXXX is ignored
      - lambda: |-
          optional<int16_t> best_rssi = nullopt;
          for (auto data : x.get_manufacturer_datas()) {
            // Guard against non-Apple datagrams, or those that are too small.
            if (data.data.size() < 4 || data.uuid.to_string() != "0x004C" || data.data[0] != 0x10 || data.data[1] < 5) {
              continue;
            }
            const int16_t rssi = x.get_rssi();
            const uint8_t status_flags = data.data[2] >> 4;  // High nibble
            const uint8_t data_flags = data.data[3];
            if (data_flags == 0x98 || data_flags == 0x18) {  // Match unlocked Apple Watches
              if (status_flags == 0 || status_flags == 2) {
                best_rssi = max(rssi, best_rssi.value_or(rssi));
                ESP_LOGD("ble_adv", "Found Apple Watch (mac %s) rssi %i", x.address_str().c_str(), rssi);
              } else {
                ESP_LOGD("ble_adv", "Possible Apple Watch? (mac %s) rssi %i, unrecognised status/action flags %#04x", x.address_str().c_str(), rssi, data.data[2]);
              }
            }
          }
          if (best_rssi) {
            id(apple_watch_rssi).publish_state(*best_rssi);
          }
duceduc commented 2 years ago

Hi. Thanks for the help. I have changed the code as suggest above. Now in mqtt, I can see a sensor and the updating of rssi, but the binary_sensor is still Off even though the watch is right beside the node. My config settings is incorrect??

2022-02-16_8-27-21

config:

substitutions:
  roomname: hallway
  static_ip: 192.168.1.201
  yourname: Duc
  rssi_present: id(harssi_present).state
  rssi_not_present: id(harssi_not_present).state

esphome:
  name: $roomname
  platform: ESP32
  board: wemos_d1_mini32 # nodemcu-32s esp-wrover-kit

wifi:
  ssid: !secret ssid_3
  password: !secret ssid_pass
  fast_connect : true
  manual_ip:
    static_ip: $static_ip
    subnet: 255.255.255.0
    gateway: 192.168.1.1

captive_portal:

logger:
  level: VERY_VERBOSE

api:

ota:
  password: !secret ota_pass

mqtt:
  topic_prefix: esphome/$roomname
  discovery: false
  broker: 192.168.1.20
  username: !secret mqtt_user
  password: !secret mqtt_pass

esp32_ble_tracker:
  scan_parameters:
    interval: 1.2s
    window: 500ms
    active: false
  on_ble_advertise:
    - then:
      # Look for manufacturer data of form: 4c00 10 05 YY 98 XXXXXX
      # Where YY can be 01..0F or 20..2F; and XXXXXX is ignored
      - lambda: |-
          optional<int16_t> best_rssi = nullopt;
          for (auto data : x.get_manufacturer_datas()) {
            // Guard against non-Apple datagrams, or those that are too small.
            if (data.data.size() < 4 || data.uuid.to_string() != "0x004C" || data.data[0] != 0x10 || data.data[1] < 5) {
              continue;
            }
            const int16_t rssi = x.get_rssi();
            const uint8_t status_flags = data.data[2] >> 4;  // High nibble
            const uint8_t data_flags = data.data[3];

            if (data_flags == 0x98 || data_flags == 0x18) {  // Match unlocked Apple Watches
              if (status_flags == 0 || status_flags == 2) {
                best_rssi = max(rssi, best_rssi.value_or(rssi));
                ESP_LOGD("ble_adv", "Found Apple Watch (mac %s) rssi %i", x.address_str().c_str(), rssi);
              } else {
                ESP_LOGD("ble_adv", "Possible Apple Watch? (mac %s) rssi %i, unrecognised status/action flags %#04x", x.address_str().c_str(), rssi, data.data[2]);
              }
            }
          }
          if (best_rssi) {
            id(apple_watch_rssi).publish_state(*best_rssi);
          }

sensor:
  - platform: template
    id: apple_watch_rssi
    name: "$yourname Apple Watch $roomname RSSI"
    device_class: signal_strength
    unit_of_measurement: dBm
    accuracy_decimals: 0
    filters:
      - exponential_moving_average:
          alpha: 0.3
          send_every: 1
    on_value:
      then:
        - lambda: |-
            if (id(apple_watch_rssi).state > $rssi_present) {
              id(room_presence_debounce).publish_state(1);
            } else if (id(apple_watch_rssi).state < $rssi_not_present) {
              id(room_presence_debounce).publish_state(0);
            }
        - script.execute: presence_timeout  # Publish 0 if no rssi received

  - platform: template
    id: room_presence_debounce
    filters:
      - sliding_window_moving_average:
          window_size: 3
          send_every: 1

  - platform: homeassistant
    name: HA RSSI Present Value
    entity_id: input_number.duc_watch_present  #insert your input.number entity id here
    id: harssi_present
  - platform: homeassistant
    name: HA RSSI Not Present Value
    entity_id: input_number.duc_watch_not_present  #insert your input.number entity id here
    id: harssi_not_present

binary_sensor:
  - platform: template
    id: room_presence
    name: "$yourname $roomname presence"
    device_class: occupancy
    lambda: |-
      if (id(room_presence_debounce).state > 0.99) {
        return true;
      } else if (id(room_presence_debounce).state < 0.01) {
        return false;
      } else {
        return id(room_presence).state;
      }

script:
  # Publish event every 30 seconds when no rssi received
  id: presence_timeout
  mode: restart
  then:
    - delay: 30s
    - lambda: |-
        id(room_presence_debounce).publish_state(0);
    - script.execute: presence_timeout
0nikola1 commented 2 years ago

You need to set values in HA in input_number.present and input_number.not_present or whatever your name for it is

duceduc commented 2 years ago

Yes, I have those in HA

input_number:
  duc_watch_present:
    name: Duc Watch Present
    min: -100
    max: 0

  duc_watch_not_present:
    name: Duc Watch Not Present
    min: -100
    max: 0
0nikola1 commented 2 years ago

And in UI you need to set them to value which you want to be marked as detected

duceduc commented 2 years ago

Sorry, I've looked back at the readme and I think the author had updated the code a bit. Is this what I need to change in the input_number??

 input_number:
   duc_watch_present:
     name: Duc Watch Present
     initial: -77
     min: -100
     max: -40
     step: 1
     unit_of_measurement: dBm

   duc_watch_not_present:
     name: Duc Watch Not Present
     initial: -90
     min: -100
     max: -40
     step: 1
     unit_of_measurement: dBm
0nikola1 commented 2 years ago

No, these are entities in HA and in HA UI you need to set value D40A0BD1-4016-47A7-83A4-133A33DF70E2

duceduc commented 2 years ago

ok. sorry. after i posted. I looked in the ui more thoroughly and figure I had to move the sliders. This is what I have set, but no change in state.

2022-02-16_9-26-42

2022-02-16_9-27-04

0nikola1 commented 2 years ago

Can you check if sensor from esphome have rssi present and not present values as you set them in HA?

duceduc commented 2 years ago

You lost me there. How do I check in esphome if esphome is seeing these 2 entities I've set in HA?

0nikola1 commented 2 years ago

In esphome there are 2 sensors for rssi which you can see in HA too as hereimage

duceduc commented 2 years ago

Oh. I believe I don't have that because I have discovery: false in the config.

I have set discovery to be true. Seem to be working now. The binary sensor is switching to on or off and I do see the 2 sensors in HA.

dalehumby commented 2 years ago

Hi @duceduc In case you run into this problem again, you can temporarily hard code the present/not presenth threshold values in the ESPHome yaml by changing

  substitutions:
    roomname: hallway
    static_ip: 192.168.1.201
    yourname: Duc
    rssi_present: id(harssi_present).state
    rssi_not_present: id(harssi_not_present).state

to something like

  substitutions:
    roomname: hallway
    static_ip: 192.168.1.201
    yourname: Duc
    rssi_present: -77
    rssi_not_present: -90

The only reason HA sends threshold values to ESPHome is to make testing the values easier than recompiling each time you want to test new thresholds. But once you've found values that work you almost never need to change them so they could be hard coded in the ESPHome yaml.

I'm going to close this issue now. If you need any more help feel free to reopen or post a new issue.

andrelung commented 2 years ago

Sorry for commenting on a closed issue. However I am stumbling upon the same problem and I can't figure out where to set discovery to true. @duceduc , could you point me in the right direction?

duceduc commented 2 years ago
    However I am stumbling upon the same problem and I can't figure out where to set discovery to true.

Hi. You would need to add the discovery line in your esphome config file like so.

    mqtt:
      topic_prefix: esphome/$roomname
      discovery: true
      broker: 192.168.1.20
      username: me
      password: wish