Automation not triggered by device tracker

I have an old iPhone (too old for home assistant app :confused: ), and I would like to trigger some action whenever it enters or leaves home, i.e. the local wifi network.

I am using AVM FRITZ!Box Tools integration, the device_tracker is created from there.

This is my automation:

alias: iPhone tracking
description: ""
triggers:
  - device_id: f7892f3fd65d73f055d79a4ab9dbfb24
    domain: device_tracker
    entity_id: 432456a9f8c961b1635d917c15a48f85
    type: leaves
    zone: zone.home
    trigger: device
  - device_id: f7892f3fd65d73f055d79a4ab9dbfb24
    domain: device_tracker
    entity_id: 432456a9f8c961b1635d917c15a48f85
    type: enters
    zone: zone.home
    trigger: device
  - trigger: zone
    entity_id: device_tracker.iphone_von_mark
    zone: zone.home
    event: enter
  - trigger: zone
    entity_id: device_tracker.iphone_von_mark
    zone: zone.home
    event: leave
conditions: []
actions:
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: "{{  trigger.id }}"
      title: iphone
      data:
        vibrationPattern: 100, 1000, 100, 1000, 100
        channel: Motion
mode: single

The first two triggers where created by using the visual editor, I just selected the device in the drop down list
image

When that did not work, I added the other two triggers, based on one of the many guides around…

Unfortunately, the automation is not triggered (hence there is no trace), even though the device_tracker switches between home and away.

Is there any mistake in my definition? How can I trace the problem of not triggered automation?

I have little experience with device triggers, because I avoid them for several reasons. I use state and numerical state triggers instead. They are way more flexible and predictable, because they are not device dependent. So I would rewrite it to use state triggers on the entities (from: home and to: home) first. Also for the zone triggers.

Also check in the history graph of Home Assistant if the device trackers actually change soon enough. I seem tot remember fritzbox is particularly slow in marking devices offline. Maybe a ping sensor is more reliable, provided you set the phone not to switch mac address all the time when on the home wifi.

2 Likes

Yep, what Edwin suggests is the way to go.

Forget about device triggers and use a state trigger with home and not_home as the states.

Thanks for the quick response and the link, I will check that out :+1:

I already noticed the ‘slowlyness’ of the FB, and also had the idea of using the ping; unfortunately, the iPhone can only be pinged as long as it is ‘awake’. As soon as it turns off its screen, it also no longer responds to pings…

I’m currently investigating fbtr64toolbox.sh; scanning the connected wlan hosts directly on the FB seems to give a much faster response which I would probably then simply turn into a binary sensor

You could also check if the owntracks app runs on the old phone? Others use it for location tracking.

If the device is not pingable (i.e. probably turning off wifi most of the time) it is probably not reliably detectable from outside the phone. The fritzbox itself is showing devices connected that are disconnected already, so it would not matter much how it is queried.