Phone state doesn't change when phone leaves the house

Hi all,

I’m using Home Assistant 0.116.2 in docker on OMV5. I’ve installed the companion app , v2.5.0-full, on my Pixel 3a and connected both.

In Hass i can see an entity called device_tracker.pixel_3a and i checked in the app that it has access to my location.

When i check out the Home App integration in Hass i can see one device connected and 17 entities. While my phone is connected to the same network i can see the state change in Hass as it happens on the phone (for instance changing Do Not Disturb status). But when i disconnect from the Wifi or my phone leaves the house for 15min, i see no changes at all. The Wifi connection doesn’t change or the state of the device tracker stays to home.

What am i doing wrong? I read the companion.home-assistant.io pages. I checked out some other posts but nothing really seems to cover this?

I would assume that after the phone leaves the house and it can’t communicate over the network anymore that the state would change to away and the network connection would also change.

Any help pointing me in the right direction would be greatly appreciated.

I think phones (at least my Iphone) uses the (last?) location sensor, so turning of your wifi won’t do much

1 Like

Check your app permission settings as you may have only given the app permission to access your phone location while the app is open. You need to allow access to location all the time so HA can track it without you needing to keep opening the app.

Handy if you change the thread category to ‘Mobile Apps - Home Assistant Companion for Android’ too

As far as I know you can only get this to work when you have remote access from your phone to home assistant, otherwise the phone can’t update the location when you disconnect from WiFi and it will take the last known location as aceindy pointed out.

1 Like

I’ve checked that. It says it will send info in the background

Do you mean i need to open up port 8123 on my router and set up the app using my public ip?

I was hoping to avoid that since i’m pretty new to this and don’t want to open up ports to the outside, since i don’t understand too much about securing that yet

From what i understand, you should be able to set this up without opening up any ports to the outside. Am i correct in this?

I followed the setup guide, but that doesn’t mention anything about opening ports

If you don’t want to open up any ports, you can use Nabu Casa (5$ a month, supports development of Home Assistant as well) instead.

Which setup guide? For the app? The app “works” without remote access, however the phone can’t report anything when you’re not home.

Yeah i followed the setup guide from the app.
All it mentions is that you need to make sure you allow location access on your phone for the app. After that it just assumes you can use the tracker for these automations. It never metions at all that you need to open up ports for this to work

Ok, maybe this should be made more clear in the documentation. However, it’s “logical” that it doesn’t work, as your phone doesn’t know where it should report the data to when you are not home. The URL for Home Assistant you configured in the app is a local address and can only be reached when you are connected to your home network.

Yeah, i agree.
The documentation makes it sound like you really don’t need a connection to the outside.

I was assuming that when the phone would disconnect from the network it would just change those values, and change them back when the phone would re-connect to the network.

I’ll try opening up the port and see if that works. Is there an option generally that would only allow a certain mac address to connect?

If you just want home/not home then use the NMAP integration to track if your phone is on the home wifi or not

2 Likes

From your posts I assume that you don’t feel secure about opening a port on your router and that you don’t know much about port forwarding and securing your network properly. Therfore I suggest using NMAP or ping or something similar to track if your phone is connected to the network.
Another possibility could be the wifi-connection sensor from the app, but I don’t know whether this updates properly without remote access or not. When you leave home, does the wifi-connection sensor update or does it stay as it was?

I’ve opened up the port and now at least it’s noticing a change on the Wifi network when i turn it off on the phone. So when i change my automation the check the wifi connection it works when i turn the wifi on/off on my phone.

I’m just wondering if it is possible to set access to this port by mac address. That would secure it pretty much, no? Only allowing one mac address to go through. Just not sure if this is possible. I have a Netgear R6700 v2 router at the moment.

I’ll have a look at the NMAP integration. Specially if that makes everything a bit more secure

Having 8123 open should be pretty save, provided you use a strong password.
HA differentiates between local (trusted) networks and remote networks:
Also HA will report un-authorised access (attempts) :grinning:
configuration.yaml

  auth_providers:
    - type: homeassistant
    - type: trusted_networks
      trusted_networks:
        - 192.168.1.0/24

If you enable https, even more secure, as your data will be encrypted :wink:

Using NMAP you don’t need the port open, bit it will only give you wifi device tracking. If that’s all you need them simply do that and not have to worry about ports / security

Not as far as I know, as far as I understand, the request from outside will get the mac address of your router once it arrives in your network. MAC address features are in the Layer 2 and not available on Layer 3 (outside Local LAN).

Thanks for all the replies!

I’m looking at NMAP now. This is how i understand it so far:

I make a device tracker:

device_tracker:
  - platform: nmap_tracker
    hosts: 192.168.1.15

where the host ip is the ip address from my phone.

Then in my automation i just use that device tracker instead of the one from the phone? What do i check on? with the phone device tracker i check on the change of Wifi Network, what should i check on with this new device tracker?

I guess it makes sense to give my phone a fixed ip address via my router?

Does this sound pretty much correct?

ok, so i played around with the NMAP device tracker and got it all working!
It’s not as responsive as using the actual device tracker from the phone itself, mainly when leaving the network, but that’s not really an issue and better than having to open any ports.
It seems to respond quickly when it notices the device on the network and that’s the most important thing.

Thanks again for suggesting this option.

1 Like

Have you checked this setting?

Also look at the consider home settings for device tracker