Looking to add some automations that depend on who’s home or that are started when someone either gets home or leaves. To start, I’m using the Ubiquiti Unifi WAP component to track wireless devices like my phone. Hopefully I’ll have a post up soon about the set-up of my new network equipment. This component relies on having a Ubiquiti WAP, so it obviously won’t work for everyone. There are multiple options available, but this one seemed to be the most reliable for me with the least set-up. You can use Ping, SNMP, or anything else and the automations are the same, just a different initial set-up.

Ubiquiti Unifi WAP:

This is the basic entry for this platform, added to the configuration.yaml file:

device_tracker:
- platform: unifi
  host: !secret unifi_controller_ip
  username: !include unifi_username
  password: !include unifi_password
  verify_ssl: False
  ssid_filter:
  - CellarDoor

I also added in the “detection_time” option and set it to 30 seconds, rather than the default 300 seconds. This option sets how long from when the device was last seen before HA should list it as “Away”.

device_tracker:
- platform: unifi
  host: !secret unifi_controller_ip
  username: !include unifi_username
  password: !include unifi_password
  verify_ssl: False
  detection_time: 30
  ssid_filter:
  - CellarDoor

When HA is restarted, it sees that we’ve added a presence detector component and adds a ‘known_devices.yaml’ file in the HA directory. In the case of the Unifi WAP, it gives HA all devices that as they are connected which get entered into this file. Here’s an example of what shows up for my phone:

redmi_note_4x:
  hide_if_away: false
  icon:
  mac: XX:XX:XX:XX:XX:XX
  name: Redmi Note 4X
  picture:
  track: true

For all of the devices I don’t care about, I switched “track: true” to “track: false”. For the devices I do care about, I gave them a better name and added an option to prevent false “Away” notifications:

redmi_note_4x:
  hide_if_away: false
  icon:
  mac: XX:XX:XX:XX:XX:XX
  consider_home: 30
  name: Kyle
  picture:
  track: true

 

The consider_home option tells HA that when the time since the device was last seen exceeds the “detection_time”, wait another XX seconds before listed it as away. This takes some tweaking to get right and really depends on your devices and your access point. When your phone is inactive, it might disconnect from the WiFi for a few seconds or few minutes.  In an ideal world, this option should be set to 0 and the value of “detection_time” should work for all devices. In reality, all devices will be a little different, so this allows for finer control over specific devices. I started off with detector_time set to 30 and every device set with a consider_home set to 0 and watched the longs throughout the day. So far it seems reasonable and I’m not getting any false away notifications. If it keeps up, I’ll try to reduce the detector time. If I get periodic false away I’ll adjust each device as required.

The main reason for wanting to keep the total of detector_time and consider_away down is that this is the shortest amount of time it takes between you actually leaving and HA triggering any away statuses. Depending on what automations you write that are triggered upon you leaving, a delay might be critical or irrelevant. On the other hand, getting false away flags might be a huge pain depending on those same automations. I’d hate for my TV to turn off in the middle of a movie because my phone was idle.

Performance:

Discovery of Connection Time: 10 – 25 seconds

Discovery of Disconnection Time: Reliably 1 minute as set

False Disconnects: Looking back at the logs, it seems to be quite reliable. I haven’t noticed any random disappearances and reappearances. I’m considering setting it to ping my phone when I leave to see if I get any false triggers, but for now I’m pretty content.

Automation:

For now, I’ve set an automation to turn on the entryway light when I come home after sunset. I’ll see if I can get a little more creative in the future, but for now this post has been in draft form for a few months so I’m going to leave it as is for now 🙂

- id: welcome_home
  alias: Welcome Home
  trigger:
  - entity_id: device_tracker.redmi_note_4x, device_tracker.samsunggalaxys7
    from: not_home
    platform: state
    to: home
  condition:
  - after: sunset
    after_offset: -0:30:00
    condition: sun
  action:
  - service: switch.turn_on
    data:
      entity_id: switch.front_entryway_switch

Leave a comment

Your email address will not be published. Required fields are marked *