Presence Detection using ping - do it right

Much has been said about presence detection using ping, but they did not help me to fix my issue.

Basically, to configuration.yaml added

device_tracker: !include device_tracker.yaml

And device_tracker.yaml contained:

- platform: ping
  track_new_devices: False
  consider_home: 0:05
  hosts:
    Me:          10.33.2.103
    She:         10.33.2.104

And the configuration checker complained that Me was not a valid key for hosts.

WTH?

The solution was actually simple, but took quite some time to find.

- platform: ping
  track_new_devices: False
  consider_home: 0:05
  hosts:
    me:          10.33.2.103
    she:         10.33.2.104

Yep, the configuration does not like the uppercase letter for the dictionary keys.

Were using uppercase in their host names:

The documentation could benefit from an update to mention this limitation, and also to add the undocumentated options:

Hopefully this helps a few ;-).

EDIT: :warning: Unfortunately this is not enough :warning: - adding a follow up message below.

1 Like

Yaml is always lower case.
So if that should be noted in those docs then it should be everywhere.

So I restarted HA, did not get any device_trackers based on ping, restarted, etc. No success.

I enalbed logging:

default: warning
logs:
  homeassistant.components.device_tracker: debug

and the log is only showing this for the device_trecker:

2021-10-09 15:19:20 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.ping
2021-10-09 15:19:24 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.owntracks
2021-10-09 15:19:24 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.mobile_app
2021-10-09 15:19:24 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.mobile_app
2021-10-09 15:19:24 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.mobile_app
2021-10-09 15:19:24 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.opnsense
2021-10-09 15:19:30 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.zha

I added more devices than shown above, some show up in “known_devices.yaml” (I changed the names to host1, etc:

# This one is from OPNsense
02_0f_b5_c0_38_75:
  name: 02_0f_b5_c0_38_75
  mac: 02:0F:B5:C0:38:75
  icon:
  picture:
  track: true


host1:
  name: host1
  mac:
  icon:
  picture:
  track: false

host2:
  name: host2
  mac:
  icon:
  picture:
  track: false

#etc

Only one of those ping trackers is reported in the Developer Tools > states with a value of ‘home’ and state attributes:

source_type: router
friendly_name: host2

FYI: First device entry above stms from tracking with OPNsense which I removed in the mean time. OPNsense presence detection does not work as devices macs are statically added to the ARP table (that is more secure) which is what seems to be checked by that integration.

I manually set “track” to “true”, which seems to help as Developer Tools > STATES gives some more value. However the other devices are shown as “not_home” while they are - I guess that is then due to the limitations of the ping trackers with sleepy devices.

Yes. And that is why it’s not a recommend way to track phones.
Use the mobile app as your tracker instead much more stable.

I understand the benefits of the mobile app, but not everybody is keen on installing it.

I am specifically trying to get teh “ping” wokring.

EDIT: HA require that entity names are lower case, and the host names are eventually part of an entity name. This was actually reminded in the detail for the hosts parameter of the presence detection documentation.

I understand that this can be how Home Assistant works, but when using it for swagger, it is mixed case .

The end user, just following instructions about a given feature, should not have to be proficient in Yaml.

In general, the keys are fixed and precise, so the documentation is already indicating that they must be lower case for most use cases.

However, to define the users, the keys are a free choice. I would not expect the end user suddenly has to be an expert in Home Assistant Yaml. I have a good expertise with Swagger Yaml, but apparently that is different.

Anyway, free key values are a particular case - there is no need to remind it everywhere in the docs.
Here the keys can be chosen, so I think that it is normal to remind that HA Yaml requires that keys are in lower case.

But IMHO, if HA Yaml would be standard Yaml, mixed case would be allowed.

I also checked the YAML 1.2.2 specification, and as far as I understand it, upper case is allowed for identifiers .
The rule was slightly different for YAML 1.1, but there too uppercase is allowed.

Home Assistants’s documentation says that it is case sensitive, but on the pages that I found it does not mention that it does not allow uppercase for keys (identifiers):

The documentation does mention that true,false,on and off should be lower case, which is expected as it is case sensitive and that is also true for standard yaml.

EDIT: The hosts parameter documentation points to the requirement that an entity name has to e lower case (so not “all” YAML keys):

In the end, the tracking seems to be working.

What may have helped:

  • Setting “track” to “true” ;
  • Adding “device_tracker.me”, “device_tracker.she” to “.storage/person” manually as they were not available for configuration through the UI;

Today, I added an optimisation to the recorder that has also hidden updates to the device_tracker state. I did not need to renable the recorder for the device_trackers, but it may help during debugging.
These are the relevant lines from my configuration.yaml that had device_tracker listed in the exclusions - I only added this configuration after trying most alternatives above, but I mention this in case you have it active:

recorder:
  exclude:
    domains:
      #- device_tracker