Automation for turning on lights when I am returning home

I created a zone called “Near home”. It is a large circle centered on my house. I want lights to turn on when I enter Near home. I have actually seen my automation work, but most of the time it does not turn on the lights until after I enter the house.

I am using the location of my phone as the trigger. I have that device assigned to me, so I believe that I could equivalently use person.my_name as the trigger.

I chose a radius for the Near home circle so that I have another 5 minutes of driving after entering the zone before I get home. I have seen documentation that it can take 2-3 minutes for location to update, so I allowed even more time.

On the Companion app, under Manage sensors | Location sensors, I have Background location and Location zone enabled. I have Allow background usage enabled for Home Assistant Companion app.

When I leave home, History shows me Home initially, then I am Near home, as I expect. However, I am then Home again as I reach my destination (weird), and then I am Away (as expected). When I returned home, History shows my location going directly from Away to Home. The lights go on after I am in the house. The trace for the automation shows that it triggered on zone.near_home, but History does not show that I was ever in Near home, and the automation certainly did not trigger when I entered the Near home zone 5 minutes before I got home.

I had Airplane mode off all the time. I was running Google Maps in Android Auto because I read that the phone updates its position more regularly when running Google Maps. My position was correct in Google Maps.

I do not see any errors in the Log around the time of my return.

Does anyone have any idea what I need to do to get the Near home zone working reliably?

You have some other device attached to your user/person.

Are you logging into multiple devices around your house with your user credentials? E.g. An iPad with the companion app?

I have a Chromebook that I use to access Home Assistant. I access it with a browser through the address homeassistant.local:8123, so I think that it is not running Companion app. In any case, the Chromebook was not powered on when I went out yesterday.

Furthermore, the automation triggers on my phone:

trigger: zone
entity_id: device_tracker.pixel_10_pro
zone: zone.near_home
event: enter
enabled: true

so even if there were another device running Companion I do not see how it would interfere.

When I look at Settings | People, I see one device associated with me (the phone).

Try setting High Accuracy Mode for your home zone. There’s an option named High accuracy mode trigger range for zone (meters) which does exactly the same thing you’re trying to accomplish with your near_home zone, but reports more frequently.

This means that you have to delete your near_home zone & switch your automations to use the automatically created zone.home_expanded

ShadowFist:

Your suggestion to use High Accuracy Mode with the option High accuracy mode trigger range for zone (meters) is interesting because it also addresses another concern about my Near home zone: Because Home and Near home are concentric, I am actually in both Home and Near home when I am home. I was Home last night, but when I had breakfast this morning I was in Near home – not wrong, but not ideal. With your solution, the high resolution zone is an annulus which disappears once I am in the Home zone, so I would never be in the high resolution zone when I am in the Home zone.

For the benefit of other readers, it took me a while to find this option. The option appears when you enable Background location and then High accuracy mode. You can then interact with the High accuracy mode only when entering zone and the High accuracy mode trigger range for zone (meters) sub-options.

All:

The Location sensors category under Sensors has an option (referred to above) called Background location. It makes it possible for Companion to “Update your location behind the scenes, periodically”. Back at the top level of the Companion app options, there is one called Background access: “Home Assistant has access to run in the background”. “Running in the background” sounds a lot like “[updating] behind the scenes”. Do both of these options need to be set? Furthermore, Android itself has a setting for the Home Assistant app under App battery usage called Allow background usage. Do all three of these options need to be enabled for the location sensor to work?

Last night, I tested the automation with High Accuracy Mode enabled and High accuracy mode trigger range for zone (meters) set to 1000m. That configuration did not work either. It failed in the same way the automation has always failed: My location changes from Away to Home after I drive into the garage, which with these settings is about 1.5 minutes after the automation should have triggered. I had Google maps running to be sure that my location was getting updated regularly. I had Background location, Background access, and Allow background usage all enabled. I give up. Funny how it used to work before I changed nothing.

That sounds to me like your phone isn’t connected to HA until you’re home and on WiFi. Does your location show correctly in the HA app as you approach?

Have you tried waking up your phone to see if the location updates then?

No sly phone updates?
Do you have random MAC address option turned on in your phone network configuration? A random or static IP address on your router in the DHCP configuration for when your phone connects?
See what happens when you change these.

bazfum, I have not had an opportunity to test your theory properly yet, but sitting here in my house this morning I see that Home Assistant thinks that I am two blocks away from my house. When I run Maps on my phone, it too has me in the wrong location – no, I just got moved to the right location both on Maps and Home Assistant. I am downstairs in my house, so could it be that I am not getting a good GPS signal here? I will try the test again when I am driving around later today. Certainly I have never seen a mistake like this in Maps when I am driving around, but I will keep an eye on the Map in Home Assistant as well.

IOT7712: Yes, “use randomized MAC” is turned on for my wifi. It is not clear to me how the settings for wifi can affect the problem I have when I am driving back to my house and do not have a wifi connection. The automation is supposed to detect that I am approaching my house, but at a point too far for a wifi connection.

I switched to using the Proximity integration. It works.