How do I turn an ESPresence MQTT Sensor into a device tracker?

I have a sensor set up that shows my room, but I want to turn that into a device tracker that I can attach to a Person so i can tell if the house is occupied.

I’ve seen other solutions that use the sensors and groups in automations but it would be nice to use the native HA Person object to do it. I want to be able to look at a panel and see who is home and who is away at a glance too.

I have this as an attempt at a device_tracker config in my config.yaml:

  device_tracker:
    - platform: mqtt
      name: stuarts_iphone_at_home
      state_topic: "espresense/devices/espresence_stuarts_iphone/+"
      source_type: bluetooth
      value_template: "{{ topic.split('/')[-1] }}"
      expire_after: 60

but I don’t see a device tracker of that name available after a restart.

device_tracker doesn’t support template as a platform which is a shame because that would work a treat.

This config for the sensor works as expected:

sensor:
    - platform: mqtt_room
      device_id: espresence_stuarts_iphone
      name: ESP Stuarts iPhone
      state_topic: espresense/devices/espresence_stuarts_iphone
      timeout: 60
      away_timeout: 120
      unique_id: espresence_stuarts_iphone
1 Like

Did you ever come up with a solution here?

No, best you can do is set up a boolean helper and an automation that sets it appropriately depending on the value of the room sensor.

If its an iphone if you can get IRK or OS equivalent you can use private ble device integration. I did it the other day with my android and espresence.
It gets round the frequent mac changes.

Does that let you use it as a device tracker?

Yes. Home or away

Cool, can you paste some config because that’s how I have mine set up in ESPresence, I just can’t get the HA side of things to work (see my original message)

Its setup in ui. All you need is IRK. If you attempt to pair you phone with the espresence having connected to espresence webpage and go into settings it will generate the IRK.

Is there a way so when you add it to the person, it will show which room you’re in as the person tracker instead of just home or away?

Don’t know. I only got it working a few days ago

I could be mistaken, but I thought that platform was deprecated and all MQTT config now uses mqtt as the top level key like:

mqtt:
  - device_tracker:
      - name: stuarts_iphone_at_home
        state_topic: "espresense/devices/espresence_stuarts_iphone/+"
        source_type: bluetooth
        value_template: "{{ topic.split('/')[-1] }}"
        expire_after: 60

But I think you’re going to run into issues with that value template if espresence is posting the area/room to the topic… a device_tracker would be expecting home or not_home as the state.