Device tracker --> set zone of group trackers

I’ve added BT to device tracking, to create a more reliable ‘home’ state.

ios:

device_tracker:

  • platform: bluetooth_tracker

These appear in the known_devices:
rick:
hide_if_away: false
icon:
mac:
name: Rick ios
picture: /local/Rick.jpg
track: true

rick_bt:
hide_if_away: false
icon:
mac: BT_??:??:??:??:??:??
name: Rick BT
picture: /local/Rick.jpg
track: true

I’ve made a group of the ios tracker and bt tracker.

group:

device_tracker:
name: Wie is waar
entities:
- group.device_tracker_rick

device_tracker_rick:
entities:
- device_tracker.rick
- device_tracker.rick_bt

This shows the group with icon image on the frontend, so far so good.
If either BT or ios is home, the status / zone changes to ‘home’.
I’ve made multiple zones.

The BT component always shows ‘away’, when not home.
The ios component is set to the according zone when entered (for example ‘Work’)

To clarify:
Rick-Location

Now: I want to set the zone of the whole group, if the ios component changes to f.e. ‘Work’
Can anyone help with this? I think i must put a few conditions into automations.
But can’t seem to get this to work.

Thanks in advance.

You could make a template sensor based on the BT sensor being home or away:

sensor:
  - platform: template
    sensors:
      my_device_tracker:
        value_template: >
          {{ states('device_tracker.rick_ios') if is_state('device_tracker.rick_bt','Afwezig') else states('device_tracker.rick_bt') }}

So you’ll get the bluetooth away/home resolution needed for home automation when home, and the sensor will display whatever your IOS stuff when absent. You may need to tweek the code if you get unwanted ‘leaving’. Maybe something that checks if your IOS device is still home when the bluetooth says your away:

sensor:
  - platform: template
    sensors:
      my_device_tracker:
        value_template: >
          {% if is_state('device_tracker.rick_bt','Afwezig') and states('device_tracker.rick_ios') != 'Home' %}
            {{ states('device_tracker.rick_ios') }}
          {% else %}
            {{ states('device_tracker.rick_bt') }}
          {% endif %}
1 Like

Petro, thanks for the reply!
Going to test it out this evening, now at work :wink:

A few questions: (still new to HA)

  • Does the sensor replace the group? (device_tracker.rick_bt & device_tracker.rick_ios)
  • Or will it ‘link’ the sensor to device tracker group with;
    sensors:
    device_tracker_rick:
    value_template: >
  • Wouldn’t it be the other way around?
    {% if is_state(‘device_tracker.rick_ios’,‘Afwezig’) and states(‘device_tracker.rick_bt’) != ‘Home’ %}
    {{ states(‘device_tracker.rick_bt’) }}
    {% elif is_state(‘device_tracker.rick_bt’,‘Afwezig’)} {{ states(‘device_tracker.rick_ios’) }}
    {% else %}
    {{ states(‘device_tracker.rick_bt’) }}
    {% endif %}

Thanks for your patience :slight_smile:

it won’t on it’s own, you’ll have to do that yourself, or add it to the group. Its a completely new sensor in addition to your group and other device_trackers. If you are using the group in automations, replace the group with the sensor in the automations.

I don’t think so, the IOS reports slower than the bluetooth will. So the ios will always be lagging behind the bluetooth sensor. So use the bluetooth as the primary and the ios as the secondary.

Thanks very much!
That’s very clear.

I now have set up the following;
I work with packages, so i’ve made one package: ‘device tracker’

homeassistant:

  ################################################################################
  ## CUSTOMIZE
  ################################################################################

  customize:
    sensor.device_tracker_rick:
      friendly_name: Rick
      entity_picture: /local/Rick.jpg


################################################################################
## IOS
################################################################################

ios:


################################################################################
## BT TRACKER
################################################################################

device_tracker:
  - platform: bluetooth_tracker


################################################################################
## SENSOR
################################################################################

sensor:
  - platform: template
    sensors:
      device_tracker_rick:
        value_template: >
          {% if is_state('device_tracker.rick_bt','Afwezig') and states('device_tracker.rick_ios') != 'Home' %}
            {{ states('device_tracker.rick_ios') }}
          {% else %}
            {{ states('device_tracker.rick_bt') }}
          {% endif %}

And then added the sensor to the group:

group:
  device_tracker:
    name: Wie is waar
    entities:
      - sensor.device_tracker_rick
      - group.device_tracker_myrna

Didn’t expect that i could use my .jpg to customize the sensor.
Really glad i could.
Going to test this code.
Will post modification if i make any.

The way these show in the frontend is not the same as the actual states. For device_tracker’s, the states are actually ‘home’ and ‘not_home’ (and sometimes they may be the name of a zone. At least that’s what I’ve experienced with them, but I haven’t used these same device tracker platforms.) So you probably want this instead:

{% if is_state('device_tracker.rick_bt','not_home') and not is_state('device_tracker.rick_ios','home') %}

Thank you. I believe that’s what i was missing! :smiley::+1:
When bt is not_home AND ios is NOT home, it must set the ios state.
Going to test it.