Using the my WiFi SSID for presence detection

You can use the logic you have in an automation and create a device tracker manually and use device_tracker.see service to set the device tracker to home or not home.

Was just going to say the same. See here for examples

Thanks all for your input, much appreciated!

I decided to go the “Composite Device Tracker” route to combine both the phone’s GPS tracker and the WiFi SSID tracker into one. I plan on eventually adding BLE presence detection as well and then I could add that to the tracker_device as well.

Anyhow, this is what I added to my configuration.yaml:

device_tracker:
  - platform: composite
    name: person1_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person1_iphone_wifi_tracker
      - device_tracker.person1_phone

    name: person2_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person2_wifi_tracker
      - device_tracker.peson2_phone

Now this creates the expected Composite Device Trackers device_tracker.person1_home_or_away and device_tracker.person2_home_or_away

The only problem is that only the second (device_tracker.person2_home_or_away) seems to work, it will correctly change state based on the values of sensor.person2_wifi_tracker and device_tracker.peson2_phone.

The first Composite Device Tracker (device_tracker.person1_home_or_away) always shows as “not_home” with source_type:null

Now if I change the order of the definition of the two Composite Device Trackers in my configuration.yaml like this:

device_tracker:
  - platform: composite
    name: person2_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person2_wifi_tracker
      - device_tracker.peson2_phone
    
    name: person1_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person1_iphone_wifi_tracker
      - device_tracker.person1_phone

then the other Composite Device Trackers is working instead (but still the last one to be defined), and device_tracker.person2_home_or_away always shows as “not_home” with source_type:null.

So it seems like only the second instance of a “Composite Device Tracker” I define is actually working. And I had to add a in after the second instance in configuration.yaml for the second one to even show up in HA. This is the last entry in my configuration.yaml by the way. It would pass “Configuration Validation” without the , but the last entry didn’t show up. So it seems it’s a bit picky of the file formatting by requiring an at the very end of the file, at least if Composite Device Trackers are defined at the end.

I tried to define a third one as well, then the first one I defined didn’t show up at all, the second showed up but didn’t work and the third and last worked as expected.

Now I’m completely new to HA, but this seems strange to me. Any idea why only the second (last) instance of “Composite Device Tracker” I define actually works? Can I only define one at a time? If that’s the case then that does not make any sense either.

Please bear with me if I made a trivial error, I only installed HA this week and I’m still learning. :slight_smile:

I finally figured it out, had to add “- platform:” for each instance, eg:

device_tracker:
  - platform: composite
    name: person1_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person1_iphone_wifi_tracker
      - device_tracker.person1_phone

  - platform: composite
    name: person2_home_or_away
    time_as: device_or_local
    require_movement: true
    entity_id:
      - sensor.person2_wifi_tracker
      - device_tracker.peson2_phone

It all works great now. Not really used to the syntax yet. :slight_smile:

Edit: Well, it works great NOW, turned out I had to change my sensor that checks my SSID to a binary sensor for for the “composite” component to actually use it.

4 Likes

Hi, this is awesome! but…when you say sensor.my_phone_ssid, sensor must be replaced by my phone entity id? otherwise, how to locate the device? Thanks in advance!

Hi, sensor.my_phone_ssid is my phone, ok, but how? sensor.myphoneid? how can I identify my phone?

I’m not sure if you got he answer elsewhere already but it’s the name you give in the HomeAssistant App on your phone, under settings> companion app > device name.
e.g. mine is sensor.daves_phone_wifi_connection

1 Like

Hi , can you give me please the example of the binary sensor ?

I am not sure if this is the best way,

but this is what I use in my configuration.yaml, which works perfectly for me.

template: 
  - binary_sensor:
      - name: s10_connect_home_wifi_tracker
        state: >
          {% if (states('sensor.my_phone_wifi_connection') == "Your Wifi SSID") %}
            on
          {% else %}
            off
          {% endif %}

Best regards.

1 Like

Sorry for the late response…

Look under “Developer Tools → States” and you should be able to find your phone’s wifi connection/SSID “tracker”. You might have to enable this sensor in the HW companion app.

Here is an example of my binmary sensor:

binary_sensor:
  - platform: template
    sensors:
      my_phone_wifi_tracker:
        friendly_name: My Phone WiFi Tracker (SSID = MySSID)'
        icon_template: >
          mdi:wifi
        value_template: >
          {% if (states('sensor.my_phone_ssid') == "MySSID") or ((states('sensor.my_phone_ssid') == "MySSID-5G")) %}
            home
          {% else %}
            not_home
          {% endif %}

So just like in my very first post above, except binary_sensor: instead of sensor:

1 Like

You could also do it like this:

binary_sensor:
  - platform: template
    sensors:
      my_phone_wifi_tracker:
        friendly_name: My Phone WiFi Tracker (SSID = MySSID)'
        icon_template: >
          mdi:wifi
        value_template: >
          {% if "MySSID" in states('sensor.my_phone_ssid') %}
            home
          {% else %}
            not_home
          {% endif %}

Is’t that the same as in my example, except that I’m comparing with two possible SSID’s since I have more than one network I might connect to at home?

Not really.
If the names are the same then you only need one if and no or.

Your example assumes that the SSID are the same, except that one ends with “-5G”. That’s not the case.

And besides, I much prefer the IF & OR approach for clarity. Coding style is a matter of taste I guess.

So does your example:

It’s just an example, I should know what my SSIDs are. And my example does not assume anything, they are examples for those who follow to put in their own SSIDs.

Hi, any idea please why I’m getting OFF from binary sensor while template is showing home? When I turn off wifi, template is not_home, but binary sensor is still off. Thank you.

Because you made it a binary sensor.
A binary sensor only has on/off, you give it home/not_home.

Hey guys I’m also having problems in setting this up.
I want to use the wifi_connection entity from the companion app.
HA shows the state properly so that’s not the problem.
From my understanding I would have to create a new sensor which
gives “home” or “not home” according to what the entity states.
I tried all the above samples.
What did work was to create an binary sensor in the configuration.yaml giving yes or no in respect to the entity state.
What does not work is to create a sensor in the sensor.yaml that would give “home” or “not home”.
I can add the code for a new sensor in the sensor.yaml without getting an error but obviously it doesn’t create a new sensor.
So what am I doing wrong?