Override tracker with wifi SSID

Geolocation tracking is not working properly on one of our phones, the detected location regularly randomly changes to a location far away, even though the phone is home. This appears to be a bug. No idea if its with companion, home assistant or even google, two identical samsung phones, only one seems to suffer from this.

To work around this, and ensure the phone is detected home correctly, I want to use the fact it is connected to our home wifi to override the geolocation. I have the wifi connection sensor from companion, how do I use this to change the tracker to home while its connected to our wifi?

Ive looked in to tracker.see but I dont seem to understand how Im supposed to use it.

1 Like

You can use device_tracker.see in an automation, where you check the wifi SSID every time the zone of the device tracker changes from home to another state and if the SSID is still your home wifi. Set the location_name to home.

The way I do it is to add a second device tracker to my person. My network integrations (UniFi and Fritz Box) provide for each network device a device tracker, which I can use to determine if a certain network device (e.g. phone) is in the network/at home. Using two trackers prevents the jumping of the GPS location, affecting the zone of my person.

Im testing this in dev tools to set location to not_home (kinda hard to do the other way since we are home) but it doesnt do anything:

service: device_tracker.see
data:
  location_name: not_home
  dev_id: gsm_denise

The tracker entity id is device_tracker.gsm_denise. I tried using the full entity_id but that fails to execute with an invalid slug error.

The way I do it is to add a second device tracker to my person. My network integrations (UniFi and Fritz Box) provide for each network device a device tracker, which I can use to determine if a certain network device (e.g. phone) is in the network/at home. Using two trackers prevents the jumping of the GPS location, affecting the zone of my person.

My routers arent supported, and googling on this I found as many people having issues with this way of tracking, and I even read that people have issues that gps takes precedence even though the docs say otherwise, so it might not even solve it.

But companion wifi sensor does give the correct SSID, even when the location is way off, there has to be a way to use that. I can use the wifi sensor “manually” in all my automations, but thats rather silly and wouldnt work with alarmo.

I can just say it works very well for me.
If your router can’t provide the data you could manually create a device tracker and set the state in an automation according to changes in your SSID:

In regards to device_tracker.see: Not an expert here, have just used it once during testing and it worked for me setting the home state.

Ok, now Im getting somewhere, thanks. I can not update the location of my phone’s tracker, but device_tracker.see actually creates a new tracker entity

image

And then I can update its location through dev tools by calling the tracker.see service. Dont understand why I can update this tracker, and not my phone’s tracker, but ok.

Now lets find out if I add it as a tracker to my person whether it supersedes the companion GPS geolocation tracker or not. If it doesnt, it wont have helped, but lets hope.

Oh man, they arent making this easy and documentation seems lacking.

I added the wifihometest tracker to my person trackers, then spoofed a GPS location on my phone and immediately HA decided I was not_home, ignoring the new tracker.

Then I thought, why wouldnt it, since both trackers have “gps” as source type attribute, makes sense to use the most recent one or highest accuracy, how do I tell HA that the wifihometest tracker is no gps and what do I change it to? The services page doesnt provide such option, I cant find this in the docs, but I found elsewhere “router” is a valid source type, so I changed the attribute to router using dev tools:

That seems to work, Im not entirely sure as everytime I call tracker.see, it resets the source type attribute to gps. Help?

Ah, to answer my own question, this seems undocumented, its not even listed as available parameter in dev tools, but it works, just add source type parameter:

service: device_tracker.see
data:
  dev_id: wifihometest
  location_name: Moon
  source_type: router

Providing something other than router or gps also gives an error showing the valid options:

Failed to call service device_tracker.see. expected SourceType or one of ‘gps’, ‘router’, ‘bluetooth’, ‘bluetooth_le’ for dictionary value @ data[‘source_type’]. Got None

If this is documented somewhere, I didnt find it.

Well, its in developer docs:

Could you please let me know if this has been working well for you? And if so, what is the automation you use?

I defined this:

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

…but often the the device tracker diodorusphonewifiname changes to not_home (typically after around 3 minutes) even if sensor.phone_diodorus_wifi_connection does not change. it’s driving me crazy - I don’t get why that is happening.

here is what I have:

trigger:
  - platform: state
    entity_id:
      - sensor.gsm_jan_wifi_connection
    to: Tenda Mesh
    id: to
  - platform: state
    entity_id:
      - sensor.gsm_jan_wifi_connection
    from: Tenda Mesh
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: from
condition: []
action:
  - if:
      - condition: trigger
        id: to
    then:
      - service: device_tracker.see
        data:
          dev_id: tenda_mesh_jan
          location_name: home
          source_type: router
          gps_accuracy: 100
          gps:
            - 51.xxxx
            - 5.xxxx
    else:
      - service: device_tracker.see
        data:
          dev_id: tenda_mesh_jan
          location_name: unavailable
          source_type: router
mode: single

(edited GPS location for privacy)