MQTT device tracker and consider home

It seems that the MQTT device tracker doesn’t take into consideration the consider_home setting. Anyone else that has the same problem?

How many tracker platforms do you have?

Device tracker will only look for the following global settings under the configuration of the first configured platform:

Parameter Default Description
consider_home 180 Seconds to wait till marking someone as not home after not being seen. This parameter is most useful for households with Apple iOS devices that go into sleep mode while still at home to conserve battery life. iPhones will occasionally drop off the network and then re-appear. consider_home helps prevent false alarms in presence detection when using IP scanners such as Nmap. consider_home accepts various time representations, (e.g., the following all represents 3 minutes: 180 , 0:03 , 0:03:00 )

I have 3 and the global settings are in the first one.

Well that’s not your problem then.

Did this ever get resolved? I’m running into the same issue, i’ve got my consider_home set to 300 (5 minutes). The mqtt topic is updated every minute. Yet, when there is only one update that is ‘not home’, it will immediately set the presence to ‘not home’. It should not.

device_tracker:
  - platform: mqtt
    consider_home: 300
    devices:
      sailfish_foo: 'presence/10.1.0.41'
      sailfish_bar: 'presence/10.1.0.42'
    payload_home: '1'
    payload_not_home: '0'
  - platform: ping
    hosts:
      android_foo: 10.1.0.43
      android_bar: 10.1.0.44

(in my case, presence/1.2.3.4 is updated from crontab with the result of an arping on that ip)

I’ve dug into the code, and it’s a bit weird. On the one hand, the code in components/mqtt/device_tracker.py just ignores the consider_home option in the config dict, and calls async_see in components/device_tracker/legacy.py without the consider_home keyword argument, but with a location_name. This triggers legacy.py to just set the state of the presence device, without considering consider_home.

I’m a bit puzzled as to how to fix this. I can see two solutions:

  • pass the consider_home configuration option along to async_see from within components/mqtt/device_tracker.py and fix the code in legacy.py
  • do not pass the location_name argument from within components/mqtt/device_tracker.py (but only when consider_home is None??)

Input would be appreciated, so I can prepare a PR.

Ok, so it actually works as advertised, the advertisement is just a bit unintuitive :slight_smile:

Basically, the presence detection code does the following:

  • when an update comes (either from a device_tracker platform or via the device_tracker.see service) in and the location_name is set in that update, it will unconditionally set the state of the presence item to home or not_home as instructed, ignoring the consider_home option
  • when an update comes in (either from a device_tracker platform or via the device_tracker.see service) that does not have a location_name argument, it is considered to be a 'hey i have seen this device so it is at home** periodically (every 5 seconds by default) it checks whether devices that were set tohomeby an update without alocation_namehave been updated withinconsider_home- if not it will mark the device asnot_home** note that aconsider_homesetting must be present on the device, which it is not if you haven't explicitly defined the device and set the globalconsider_home`

So yeah, it’s a bit complicated. What I ended up doing is not defining the devices I wanted to track with mqtt, but instead defined the following automation:

- alias: arping for sailfish_foo got response
  trigger:
    - platform: mqtt
      topic: presence/10.1.0.41
      payload: "1"
  action:
    - service: device_tracker.see
      data:
        dev_id: sailfish_foo
        consider_home: 180

- alias: arping for sailfish_bar got response
  trigger:
    - platform: mqtt
      topic: presence/10.1.0.42
      payload: "1"
  action:
    - service: device_tracker.see
      data:
        dev_id: sailfish_bar
        consider_home: 180

Note that I set no location_name on the calls to device_tracker.see. I do set the consider_home here, because the devices sailfish_foo and sailfish_bar have not been defined in the device_trackers section of the config. By explicitly passing the consider_home with the service, the device gets updated with the setting once it gets an update.

I’m still looking into a way to define a ‘dummy’ device_tracker entry, so that I don’t have to configure the consider_home per device.

2 Likes

I know it is a bit old topic, but I have this problem too. I can create automations to “workaround” the consider_home option, but on a per device is very annoying. Isn’t more easy to just add the option “consider_home” to the mqtt device tracker?