Device Tracker - Binary Sensor

I have this binary sensor
indent preformatted text by 4 spacesbinary_sensor:

  • platform: template
    sensors:
    people_home:
    entity_id:
    - device_tracker.iphone7
    - device_tracker.ludovica

    value_template: >-
      {{ is_state('device_tracker.iphone7', 'home')
         or is_state('device_tracker.iphone7', 'home') }}
    

But I have now this situation:
one device is at home but the sensor don’t fire it.
immagine

These are the hystory for the device and sensor
immagine
immagine

what could be the situations?
Sandro

I have something similar. The formatting of your configuration is a bit off so it’s hard to tell exactly, but first, you don’t need to specify the entity_id’s. It will figure that out by itself. But assuming the formatting is correct, otherwise it looks ok. As a “working” example, here is what I have:

binary_sensor:
  - platform: template
    sensors:
      people_home:
        friendly_name: People Home
        device_class: presence
        value_template: >
          {{ is_state('device_tracker.person1', 'home') or
             is_state('device_tracker.person2', 'home') }}

Also, you can use group.all_devices if that is appropriate for you. This is an automatic group maintained by the Device Tracker component. If it makes sense for you, then you could do this instead:

binary_sensor:
  - platform: template
    sensors:
      people_home:
        friendly_name: People Home
        device_class: presence
        value_template: "{{ is_state('group.all_devices', 'home') }}"

This works because group.all_devices's state will be home whenever any of the devices is home, and will be not_home when all the devices are not_home.

Oh, I just noticed - your template is only specifying one of the devices:

value_template: >-
  {{ is_state('device_tracker.iphone7', 'home')
     or is_state('device_tracker.iphone7', 'home') }}

That’s your main problem. :slight_smile:

1 Like

Thank you so much, I was very stupid … just read the code before postig … :slight_smile:
Sandro

Funny, I was just posting about something similar. In your example, if I wanted to do an automation based on your binary sensor “binary_sensor.people_home”

What states would I use.

home, not_home
home, away
on, off?

I have a few newly created template sensors that are similar, and seem to be having issues with automation. for my “true” device trackers, home and not_home work as triggers, for mine they don’t seem to work the same.

The states of Binary sensors are (always, I think) ‘on’ and ‘off’, even if they display differently (e.g., due to the device_class.) And make sure to quote ‘on’ and ‘off’ when used in triggers and conditions, otherwise they will be automagically converted to True and False.

Thanks, that is what is looks like to me. Then what is the benefit of using them as a presence device class?

If you display it in the frontend, then it will show like this:
image
This is what it looks like when not home. Also if you look at it in History, it will show as Home or Away. But, the “raw” states are ‘on’ and ‘off’. I think that’s just how binary sensors work.

Got it, that makes perfect sense.

Thanks!!

I know this thread is a bit old, however I have a related situation that I’m trying to work with.

I have 3 “people” that I track:

  • my wife and I are both tracked by nmap and bluetooth device_trackers bunched in to groups. the groups show as “home” or “not_home” depending on the members of the group.
  • I have an input_boolean set by automation based on motion and door sensors for any babysitter, guest, etc. this shows as “on” or “off”.

I want to have a group which encompasses all of these. Unfortunately the group will ignore either the input_boolean, or the groups because it can’t seem to handle the “home” vs “on” and “not_home” vs “off” mis-match.

I tried making a binary_sensor using the presence device_class to replace the input_boolean, but despite displaying nicely in the front end, it too is “on”/“off” not “home”/“not_home”. I also tried making a sensor template that shows as “home”/“not_home”, but apparently because sensors aren’t boolean it still wouldn’t mesh properly with the other groups based on device_trackers.

Any idea how I can make an input_boolean and device_trackers use the same terminology such that putting them together in a single group will result in a group that reflects the state of all entities appropriately?

Thanks

If you have a group whose members have states that are 'home' or 'not_home', then it should work, even if some of those members are device_trackers and some are sensors. FWIW, device_trackers aren’t all “binary” either – e.g., GPS-based device_trackers can often have state values that are the name of a zone (which, as it turns out, can sometimes mess up the state of groups they are in.)

If you’re ultimately just trying to have an entity whose state indicates when at least one person is home, then why not use a binary template sensor? It could be as easy as:

binary_sensor:
  - platform: template
    sensors:
      someone_home:
        value_template: >
          {{ is_state('group.all_devices', 'home') or
             is_state('input_boolean.guest', 'on') }}
        device_class: presence