Device tracker based on wi-fi name sensor issue

Hello!

I am trying to use the “wifi connection name” sensor from my (android) phone companion app to define my (home/not_home) presence, but I must be doing something wrong.

I created the following device tracker / automation:

trigger:
  - platform: state
    entity_id:
      - sensor.phone_diodorus_wifi_connection
condition: []
action:
  - service: device_tracker.see
    data:
      dev_id: diodorusphonewifiname
      location_name: >
        {% if states('sensor.phone_diodorus_wifi_connection') ==
        'name_of_my_wifi' %}
          home
        {% else %}
          not_home
        {% endif %}
      source_type: router
mode: queued
max: 10

…and also the following (similar) binary_sensor (to try to understand my issue):

{% if states('sensor.phone_diodorus_wifi_connection') == "name_of_my_wifi" %}
  on
{% else %}
  off
{% endif %}

…and this is how they (mis)behave/compare:

Why aren’t the state changes of the three entities perfectly aligned? The connection name sensor and the binary sensor (almost, but not completely) are, while the device tracker is quite off.

What am I missing?

Thanks!

Is the device tracker in question also reporting GPS to Home assistant or are there other networks that it might be connecting to? While device_tracker.see will change the state its target device tracker, that value will change again once the criteria for GPS-based state occur.

Otherwise, if the network connection you are triggering off of is “bouncy” enough, it may exceed the automation’s limit and you end up with mismatched values. This can sometimes be ameliorated by adding a duration so the trigger only fires on a more steady state, sacrificing a bit of responsiveness for accuracy and reliability.

Unless your use case cannot be handled using a person entity, you may find more reliable results by setting up a second device tracker using an integration based on actual router/network connection rather than trying to override your phone’s setting. Options include Ping, NMAP, and ArpScan, and others. Or you could use a different modality altogether such as Bluetooth.

Thanks, although I am not sure I understand some of your comments (I am not an expert in this!).

The device tracker in question (“diodorusphonewifiname”) is only and simply defined/updated by the automation above. I would therefore have expected for diodorusphonewifiname changes to perfectly mirror the sensor.phone_diodorus_wifi_connection status changes. (In other words: I am “happy” with the sensor.phone_diodorus_wifi_connection status changes, and would simply like to “translate” those into an equivalent device_tracker changes.)

(I was actually was using Ping before - and thought this would be more responsive/reliable!)

Which method did you use to set up device_tracker.diodorusphonewifiname?

I called the service “Device Tracker: See” (with device ID = diodorusphonewifiname) from developer tool → services (based on what I read somewhere on this forum on related threads)