Just created “Presence detection” to detect the home-presence of my little daughter. This was a little difficult because she keeps her phone mostly at home. So NMAP or GPS will not work. Luckily she has a cheap fitness tracker (MI band 2 in this case).
Solution: the combination of a Bluetooth Fitness band and Mobile phone:
- (BT connected with phone and phone = home) = home
- (BT not connected with phone and phone = home) = not_home
- (BT connected with phone and phone = not_home) = not_home
- (BT not connected with phone and phone = not_home) = not_home
I have created a template_sensor:
daughter_presence:
friendly_name: "Daughter Presence Tracker"
value_template: >-
{% set pair = state_attr('sensor.app_daughter_bluetooth_connection', 'connected_not_paired_devices') %}
{% set mobile = states('device_tracker.mobiel_daughter') %}
{%- if pair != '[]' and mobile == 'home' -%}
home
{%- else -%}
away
{%- endif -%}
Next, I created two automations to update a device_tracker:
When she comes home:
- id: '123456789'
alias: 'daughter: set device tracker to home'
trigger:
- entity_id: sensor.daughter_presence
from: away
platform: state
to: home
condition:
- condition: state
entity_id: device_tracker.mobiel_daughter
state: home
action:
- data_template:
dev_id: miband2_daughter
location_name: home
service: device_tracker.see
mode: single
And another one when she leaves home (with a delay of 10mins, if the BT connection is temporary lost):
- id: '123456789'
alias: 'daughter: set device tracker to not_home'
description: ''
trigger:
- entity_id: sensor.daughter_presence
from: home
platform: state
to: away
- entity_id: device_tracker.mobiel_daughter
platform: state
to: not_home
condition: []
action:
- delay: 0:10
- condition: state
entity_id: sensor.daughter_presence
state: away
- data_template:
dev_id: miband2_daughter
location_name: not_home
service: device_tracker.see
mode: single