dalehumby / ESPHome-Apple-Watch-detection

ESPHome BLE Apple Watch presence detection
MIT License
328 stars 16 forks source link

Apple watch First Edition #19

Open ustunsoz opened 2 years ago

ustunsoz commented 2 years ago

Hi,

I am happily using first generation apple watch! I am starving to use this tool but I couldn't detect my watch ever.

LightBlue App shows my apple watch ID as UUID: 5F666A3B-2EA9-8653-46E8-298D92EAF408 08bd1756-161f-415b-8314-737909d35ac0

I will be grateful if you lead me to the right direction

dalehumby commented 2 years ago

Could you please try the following: On line 60 of the yaml, you can change it to

if (data_flags == 0x98 || data_flags == 0x18) {

If this doesn't work, please send your full yaml, and verbose debug log from startup, and let it run a few minutes while it scans bluetooth devices. Please make sure your Watch is very close (< 30 cm) to the receiver. Verbose logging can be set:

logger:
  level: VERY_VERBOSE
ustunsoz commented 2 years ago

Unfortunately if (data_flags == 0x98 || data_flags == 0x18) { didn't workout. Here is my log & yaml logs_presense_logs.txt presence.txt

Thank you for your kind help

dalehumby commented 2 years ago

Thanks for the debug logs.

  1. When you were testing this, were you wearing your watch, and was it unlocked? (i.e. didn't need a pin code to access the screen). If it was locked at the time of debug, please can you repeat the test, but with the watch unlocked (on wrist) and send the results?

  2. On line 60 try change the line

if (data_flags == 0x98 || data_flags == 0x18) {

to

if (data_flags == 0x98 || data_flags == 0x18 || data_flags == 0x1C) {
  1. I also noticed from the debug that your rssi present and not_present values are set at -40 and -50. This is too low, and should be more around -75 and -90. Even if you watch is on top of the ESP32 the rssi is probably not going to be stronger than -40. Try my values first, and once you detect your watch you can tweak them.
ustunsoz commented 2 years ago

Thanks for the prompt reply, yeah after last tweak now I can see my watch as online!

My watch was unlocked at first attempt . And again I have got the result as unlocked again.

As you have pointed out, in order to get online, I should get watch very close to esp32 it sensing only 5-10cm close. But normally my iPhone always in connect with my watch in a same room, shouldn't be that much close isn't it?

Finally if you lead me how to tweak distance I will appreciate very much.

I have shared latest log with you

logs_presense_logs (2).txt

ustunsoz commented 2 years ago

Here is the log after turn off very_verbose option logs_presense_logs (3).txt

dalehumby commented 2 years ago

Thanks. Both log files were helpful. Try changing line 61 from

              if (status_flags == 0 || status_flags == 2) {

to

              if (status_flags <= 2) {

Also, please see my point (3) above. But let me clarify more: In Home Assistant, you have

See the readme config file explanation

-77/-90 values are good defaults and you should only need to change them if your watch is being detected outside the room, or not being detected inside the room. Try the defaults fist, and then tweak later.

ustunsoz commented 2 years ago

Thank you Dale now working fine. I appreciate your assistance.

Last think, is there any way to send messages to mqtt only if certain distance change occurred. Because there is big data flow to mqtt and I afraid it will fill-up all SD card on raspberry pi (Home Assistant)

dalehumby commented 2 years ago

I'm glad we got it working.

Does it still work when your watch is off your wrist, and auto-locked?

Regarding 'too much data': That's a good point. The largest source comes from the apple_watch_rssi sensor. You can make that sensor internal to ESPHome, so the data is not shared with MQTT/HA. To do this, at about line 79, add a new line with

internal: true

You won't be able to see the rssi in HA any more, so maybe only do this after you've tweaked the input_number.rssi_present and input_number.rssi_not_present values for your room.

ustunsoz commented 2 years ago

However, there is also inconsistent action when I am away from esp32 sensor, it remains as detected and not going back not-home state and rssi value remains as last updated state. I couldn't justify somehow.

I have shutdown the watch and dale_lounge_presence state not switching to OFF

dalehumby commented 2 years ago

Could you send some debug logs of

  1. When you are wearing your watch, then take off the watch and it locks. The log should be over the time when your watch is unlocked and locked. Please include the time that you locked your watch, so I can find it in the logs.
  2. If possible, a log of when you power off your watch, or leave the house, or are far away from the esp32. The time of when you are far from the esp32 so that I can find it in the logs.
ustunsoz commented 2 years ago

Thank you for the reply,

I have attached the log, and sensor states as well as the yaml and automation.

When I take off the watch, the rssi pulses stopping after while, also complete shutdown the pulse stopped (roughly took a a minute to stop, I think during shutdown process pulse remains).

Watch shutdown at 16:21 and home assistant remains detected never turns to Clear.

The main issue is the automation not updating on the rssi signal stops.

image logs_presense_logs.txt lounge.txt automation.txt