I configured Home Assistant to track my mobile phone state whether it is connected to the local wifi or not.
I am using a DD-WRT router and used the existing integration/functionality in HA.
HA seems to see and get information from the router since it does populate the known_devices.yaml file.
But it fails to update the information when my phone leaves the local wifi … as if it is not tracking the dd-wrt connection state at all.
Yesterday I left home (with the phone) for a couple of hours, so it also not an issue of the state not updating quickly enough.
What am I doing wrong, or how can I fix this?
I figured out my own problem: draft does not update the active device list.
It apparently only does so every 24 hours.
Bummer. Now I am trying to use nmap though it’s a PITA to purge all the device_tracker entities, and I may already have encountered a false away state.
Nmap does not seem to work either. No idea why.
While my phone is at home Nmap will report a false “away” status every couple of hours - which then corrects 2 minutes later.
But now the phone has been gone for 2 hours … and it still shows as “Home”.
That is obviously the exact opposite of reliable presence detection. False negatives when at home and false positives when away.
I too gave up on the DD-WRT integration, but that was a while ago. I’ve since found NMAP to be reliable, but by taking these additional steps. Hopefully, you might find them useful:
Reserve IP addresses for the devices you want to track on your router. You might need to disable the feature on some phones that randomises its MAC address when connected to WiFi network - usually you can set this on a per network basis - as the router obviously relies on associating a consistent MAC address with the device
Restrict the range that the NMAP scanner uses to just cover the IP addresses you have reserved on the router for your devices. This stops it adding all the devices on your network, and probably reduces the likelihood of the scans timing out as well - I use the ‘Network addresses to exclude from scanning’ option to basically cover most of the IP address range except the 4 phones I’m tracking
If the devices that you want to track effectively have static IP addresses, you can also track them with the Ping integration
We also track each phone with the HA mobile app - adding each of these 3 device trackers to each person (NMAP, Ping and App) has produced a pretty reliable way of presence detection for home/away which updates more or less when it should
Your Home Assistant server needs to be reachable from the internet via an open port in your router so your mobile device with the Home Assistant App installed can connect to it and share data.
@ [reste_narquois]
I greatly appreciate the responses. I will try the Ping integration.
What drives me up the wall is that Nmap apparently does NOT detect when the phone is away.
It currently shows as “Unknown” … what the hell?
February 22, 2023
Was detected at unknown
9:51:29 AM - 1 hour ago
Was detected at home
7:23:30 AM - 4 hours ago
Was detected away
7:19:32 AM - 4 hours ago
@[woempiej]
I specifically do NOT want to use the app on my phone to track home/away.
Of course I can’t guarantee that the steps I’ve suggested will work for you, but looking at the history for the 4 NMAP entities I have (one for each phone), they never report an unknown state.
I would particularly focus on restricting the range of addresses that you are scanning via NMAP, as from memory this was the key step for me.
You can’t get a good home/away status with nmap, ping or similar since the phone goes to sleep and stops responding.
The app however uses this to it’s advantage and reports states correctly.
It seems to reliably report the correct status for the last 15+ hours using PING.
(I have an Android phone)
I will continue to update this thread with results.
The assumption that the phone’s battery management would interfere with Wifi-based presence detection cannot be correct. How else would push email, etc work? The phone is still on the wifi network and should respond to incoming queries.
If you search for “ping wrong state” then you see this is a common issue. If you don’t have it then either your phone is always in a wake state or you are always using the phone. I really don’t believe there is that big difference between different models of phones.
[quote=“Hellis81, post:13, topic:538392”] your phone is always in a wake state
[/quote]
Given that I’ve not knowingly changed anything on our phones to achieve this, it still leaves the question of why it seems to be consistently reliable when reporting home/away here?
I appreciate what the documentation may advise, but I can only go on what I actually experience in trying to help others. I assume ping/NMAP give you unreliable results?
This is especially pertinent for the OP as they explicitly don’t want to use the app - should we really be advising e.g Bluetooth solutions as an alternative?
So far the PING method works 100% reliably for me on my phone.
Maybe it doesn’t work on some phones, but as I said in my first post: unless the phone actually turns the wifi off, then it should respond to an incoming ping. Otherwise, push email, notifications, apps would not work.