Skip to content

Instantly share code, notes, and snippets.

@progrmr
Created January 13, 2025 18:51
Show Gist options
  • Save progrmr/99b36a3a60e924614a7ffee8001e24e6 to your computer and use it in GitHub Desktop.
Save progrmr/99b36a3a60e924614a7ffee8001e24e6 to your computer and use it in GitHub Desktop.
Home Assistant fix for Home/Away location tracking
##############
# Part 1: create "distance" sensors in configuration.yaml, one for each person
# The two of us have phones running the HA app, so these are the ones used.
# This creates helper template devices that provide current distance to each person
sensor:
- platform: template
sensors:
distant_to_gary:
friendly_name: "Distance to Gary"
unit_of_measurement: 'mi'
value_template: "{{ distance(state_attr('zone.home', 'latitude'), state_attr('zone.home', 'longitude'), state_attr('person.gary_morris', 'latitude'), state_attr('person.gary_morris', 'longitude'))|round(1) }}"
##############
# Part 2:
# Using the HA interface, create Input Boolean helpers. One per person.
# Mine are called "Gary is Home" and "Gabriela is Home"
# Any automations you have can then trigger off these input booleans.
##############
# Part 3: this is an automation yaml file that keeps the Input Boolean helpers updated.
# Create one of these for each person being tracked.
# Change the names of devices and SSID's to match your WiFi network.
#
- id: '1700888273418'
alias: 'Helper: Home vs Away for Gary'
description: tracks when Gary is home vs away
triggers:
- entity_id:
- sensor.garym_iphone12_ssid
to: mggm.net
id: on_WiFi
enabled: true
trigger: state
- entity_id:
- sensor.garym_iphone12_ssid
to: mggm.net 5GHz
id: on_WiFi
trigger: state
- entity_id: sensor.distant_to_gary
for:
hours: 0
minutes: 0
seconds: 0
above: 0.15
id: is_Departing
trigger: numeric_state
- entity_id: sensor.distant_to_gary
for:
hours: 0
minutes: 0
seconds: 0
below: 0.15
id: is_Arriving
trigger: numeric_state
- entity_id:
- device_tracker.garym_iphone12
from: home
to: not_home
id: to_Away
trigger: state
- entity_id:
- device_tracker.garym_iphone12
from: not_home
to: home
id: to_Home
trigger: state
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- to_Home
- is_Arriving
- on_WiFi
- condition: state
state: 'off'
entity_id: input_boolean.gary_is_home
sequence:
- data: {}
target:
entity_id:
- input_boolean.gary_is_home
action: input_boolean.turn_on
- conditions:
- condition: trigger
id:
- to_Away
- is_Departing
- condition: state
state: 'on'
entity_id: input_boolean.gary_is_home
- condition: not
conditions:
- condition: state
entity_id: sensor.garym_iphone12_ssid
state: mggm.net
- condition: not
conditions:
- condition: state
entity_id: sensor.garym_iphone12_ssid
state: mggm.net 5GHz
sequence:
- data: {}
target:
entity_id: input_boolean.gary_is_home
action: input_boolean.turn_off
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment