ESPresense / Apple Watch / MQTT / HA sensor config: Problem getting HA sensor to work and show present and distance

Using ESPresent I am trying to get a sensor in HA that can show distance to my Apple watch. ESP32, MQTT broker/client, Apple IRK is working and I can see the sensor I make in config yaml, but I cannot get to work and show present and distance.

  • ESPresense (espresense.com) runing on ESP32
  • Sending MQTT telemetry to Home Assistant MQTT broker
    – Apple Watch BLE distance detection (IRK has been setup)
  • Telemetry data can be seen on Home Assistant MQTT browser

MQTT Home Assistant browser
///////////////////////////

Message 0 received on espresense/devices/irk:1234567890abcdefghijklmnopqrstuv/stue at 11:03 AM:
{
    "id": "irk:1234567890abcdefghijklmnopqrstuv",
    "disc": "0b18a48b30",
    "idType": 200,
    "rssi@1m": -65,
    "rssi": -59,
    "raw": 0.5,
    "distance": 0.62,
    "speed": -0.01,
    "mac": "7fe37b9e7dcf",
    "interval": 312
}

config YAML
////////////

sensor:
  - platform: mqtt_room
    device_id: "irk:1234567890abcdefghijklmnopqrstuv"
    name: "Kudahl_Apple_watch"
    state_topic: "espresense/devices/irk:1234567890abcdefghijklmnopqrstuv/stue"
    timeout: 10
    away_timeout: 120

In Developer Tools / States the sensor can be seen, but the state is “not_home” and distance is “null” (see below)
////////////////////////

Filter enterties:
sensor.kudahl_apple_watch

Filter states:
not_home 

Filter attributes: 
distance: null
friendly_name: Kudahl_Apple_watch
1 Like

For some reason the ”state” and ”distance” get set faulty in on ‘mqtt_room’ sensor. I made a workaround to use until I find the root course.

Changed the sensor in config yaml to a topic that does not get updatet

sensor:
  - platform: mqtt_room
    device_id: "irk:1234567890abcdefghijklmnopqrstuv"
    name: "Kudahl_Apple_watch"
    state_topic: "espresense/devices/no_device"
    timeout: 10
    away_timeout: 120

Made pyton script that change “state” and “distance”

inputEntity = data.get('entity_id')
inputStateObject = hass.states.get(inputEntity)
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()

newState = data.get('state')
if newState is not None:
    inputState = newState
    
newDistance = data.get('distance')
if newDistance is not None:
    inputAttributesObject['distance'] = newDistance

hass.states.set(inputEntity, inputState, inputAttributesObject)

Made a automation that listen for mqtt event of my apple watch and set the “state” and “distance” og the sensor.

alias: MQTT
description: ""
trigger:
  - platform: mqtt
    topic: espresense/devices/irk:1234567890abcdefghijklmnopqrstuv/stue

action:
    service: python_script.set_state
    data_template:
      entity_id: sensor.kudahl_apple_watch
      state: ON
	  distance: {{ trigger.payload_json.distance }}

Now I can use the sensor in a dashbord and it get updated :slight_smile:

I can get distance for my apple watch, but the values are all around 1. I’ve tried absorption extremes, as well as decreasing the signal strength calibration to -35db. Little changes. Do you get reasonably accurate distances now? Thanks

I get distance and RSSI readouts, also > 1 meter. My 1-meter setting is about -55 dBm

  • It is slow to get initial distance (due to it has to connect to get IRK)
  • The distance is slow to apdapt to movement, (due to the filtering that is done on RSSI in the kernel)
  • the RSSI/Distance is fluctuating quite a bit, but settles after a while, if Apple watch is stationary

I wonder if the newest watches with Bluetooth 5.3 are problematic dues to variable signal strength.

I have change the RSSI to as high as 30. I get very fast distance changes.

I did not anticipate the implementation problem of a multistory house. The only way I may be able to use these devices is very local. For example, is the watch on the nightstand.