I have tried with ping and nmap to reliably detect my Samsung Galaxy S8. I have not gotten that to work well.
Since I don’t have a router which is supported by Device Tracker I created my own solution because I did know that I can reliably detect it using the command arping(8).
Script:
#!/bin/bash
# This script uses arping(1) to detect if a Samsung Galaxy Android phone is on the network
# using a given IP. This phone is not detectable with ping or nmap in a reliable manner.
HOST=$1
/usr/bin/arping -q -I eth1 -f -c 10 $HOST
if [ "$?" -eq 0 ]; then
# Host is alive
echo HOME
else
# Host is dead
echo AWAY
fi
configuration.yaml:
binary_sensor:
- platform: command_line
name: Detect Phone
command: /home/homeassistant/bin/detect_galaxy.sh 192.168.1.100
payload_on: 'HOME'
payload_off: 'AWAY'
scan_interval: 300
automation.yaml:
- alias: Change device tracker phone to home based on binary sensor
initial_state: True
hide_entity: False
trigger:
- platform: state
entity_id: binary_sensor.detect_phone
from: 'off'
to: 'on'
action:
- service: device_tracker.see
data:
dev_id: phone
location_name: home
- alias: Change device tracker phone to away based on binary sensor
initial_state: True
hide_entity: False
trigger:
- platform: state
entity_id: binary_sensor.detect_phone
from: 'on'
to: 'off'
action:
- service: device_tracker.see
data:
dev_id: phone
location_name: not_home