People tracker with several devices which could be connected to the Wi-Fi?

Hi,
I’ve got a few devices which are connected to the local Wi-Fi, like phones and laptops.

For example

user1_workmac:
name: User1 Work Mac
mac: 98:XX:XX
icon : mdi:laptop
hide_if_away: false
track: true

user1_personalmac:
name: User1 Personal Mac
mac: 98:XX:XX
icon : mdi:laptop
hide_if_away: false
track: true

How can I show the User1 as “being at home” if one of the two devices are connected to the Wi-Fi ?
And “not at home” if zero devices are on the Wi-Fi ?
I’m currently using nmap for device tracking by the way.

for that you could use a template sensor:

sensor:
  - platform: template
    sensors:
      user1_location:
        friendly_name: "User1 Location"
        value_template: "{% states.tracker.user1_workmac.state == 'home' or states.tracker.user1_personalmac.state == 'home' %}home{% else %}not home{% end if %}"
1 Like

Thanks Lolouk44, I’ve also set in group.yaml

user1_group:
name: User1
entities:
- device_tracker.user1_personalmac
- device_tracker.user1_workmac

and now if I check /dev-state I can see
group.user1_group set to “not_home” or “home” automatically.

I guess that I just need to render that, it looks cleaner, no ?

yes that’s actually better :+1:

I think I’ve got something quite good like that, with a sensor and a binary sensor, to be used for automations :

in sensor to say at home or not

- platform: template
  sensors:
    user1_sensor:
      friendly_name: User1 Sensor
      value_template: "{% if (is_state('group.user1_group', 'home') ) %}at home{% else %}not at home{% endif %}"

in binarysensor to give an on/off state

- platform: template
  sensors:
    user1_binarysensor:
      friendly_name: User1 BinarySensor
      value_template: "{% if (is_state('group.user1_group', 'home') ) %}on{% else %}off{% endif %}"

in groups to show it all

user1_group:
  name: user1
  entities:
    - sensor.user1_sensor
    - binary_sensor.user1_binarysensor
    - device_tracker.user1_workmac
    - device_tracker.user1_personalmac

and with the two devices user1_workmac + user1_personalmac listed in known_devices.yaml

Looks good?

FYI, for the value_template of your Template Sensor, you could also do one of the following. They’re equivalent to your solution, and slightly more compact:

"{{ 'at home' if is_state('group.user1_group', 'home') else 'not at home' }}"
"{{ 'not ' if not is_state('group.user1_group', 'home') }}at home"

For your Template Binary Sensor, the value_template only needs to be:

"{{ is_state('group.user1_group', 'home') }}"

1 Like

Thanks for the recommendation I’ll use that :stuck_out_tongue:

Well big disappointment, the whole thing doesn’t work as expected

Current state :

device_tracker.use1_device1 = home
device_tracker.use1_device2 = not_home

I expect :

sensor.user1_sensor = home
binary_sensor.user1_binarysensor = on

But I got :

sensor.user1_sensor = not at home
binary_sensor.user1_binarysensor = off

OK I’ve changed the group from

user1_group:
  name: user1
  entities:
    - sensor.user1_sensor
    - binary_sensor.user1_binarysensor
    - device_tracker.user1_workmac
    - device_tracker.user1_personalmac

to

user1_group:
  name: user1
  entities:
    - device_tracker.user1_workmac
    - device_tracker.user1_personalmac

and it seems that now I get “home” if one or more of the devices is home, looks like it’s working !

1 Like