Binary sensor template as device tracker (and attributes issues)

Hi everybody,
I’ve set a binary sensor as explained in the docs:
Template - Home Assistant (DEVICE TRACKER SENSOR WITH LATITUDE AND LONGITUDE ATTRIBUTES) but I’m stuck with a couple of issues:

  1. the binary sensor is not seen as device tracker, therefore I can’t insert into the person/user panel. How can I add it?
  2. the attributes piece of code rise an error as it is. I was unable to fix it.

Any suggestions?
Thanks

I’m going to state the obvious here but the reason it’s not seen as a device_tracker entity is because it’s a binary_sensor entity. There is no Template Device Tracker integration:

Template Integrations

You can’t force an entity of one domain (like binary_sensor) to become another domain (like device_tracker or person).

FWIW, there is an MQTT Device Tracker.

This is off-topic for your actual question, but hopefully helpful. To do the actual device_tracker job — in my case, for my car — I do the following:

Entry in known_devices.yaml (docs):

leaf:
  name: LEAF
  icon: mdi:car-electric
  track: true

Automation to manually update the device_tracker entity with separately-available lat/long:

- alias: LEAF - update device tracker

  description: Keep the device tracker aligned to the lat/long for zoning.

  id: UNIQUE_ID_HERE

  trigger:
    - platform: state
      entity_id: sensor.leaf_last_updated

    - platform: homeassistant
      event: start

    - platform: event
      event_type: automation_reloaded

  action:
    - service: device_tracker.see
      data:
        dev_id: leaf
        gps:
          - "{{ states('sensor.leaf_latitude')|float }}"
          - "{{ states('sensor.leaf_longitude')|float }}"
        battery: "{{ states('sensor.leaf_battery_percentage')|float }}"

Thank! I thought that much, still the title kinda misled me with the DEVICE TRACKER SENSOR starting title.
So I can set up a MQTT device tracker from a binary sensor?

Thanks, that’s interesting, I will check it out this evening!

You don’t need the Template Binary Sensor you created, just the information you used to create it. That information would be published, by an automation, to the MQTT Device Tracker’s topic.

The MQTT Device Tracker’s configuration is trivial. Basically it needs to know the MQTT topic representing the device’s state (home or away). If the device doesn’t use home or away to represent its states, then you can use two other options to specify what it uses.

device_tracker:
  - platform: mqtt
    devices:
      your_device: "location/your_device"
    qos: 1
    payload_home: "on"
    payload_not_home: "off"

Many thanks, I’ll check this out, but the gist of it is pretty clear!!! Now I need to dig into it.

I overlooked to point out that it’s all fairly trivial to create (including the automation) provided you are already using MQTT. Otherwise, you will first need to install an MQTT broker and the MQTT integration (and configure both of them). It’s not difficult but more than a few people have had trouble getting all the “plumbing” working properly.

Yeah, if I hadn’t had a working MQTT broker I would have mentioned it. :slight_smile:
And in that case I would have probably chosen a different path, like avoiding to use the person entity all together in favour of the binary sensors I implemented and move all the automations on them.