How to make Hass to ignore device location at certain times

Hello Lovely People…

Scenario: Kid’s phone connected to HA and updates the location set home/away etc. However the phone is not allowed to school, so its left at home.

Requirement: On school days, between certain times, I want HA to ignore the location updates from the phone, instead set the location to school.

Setup: I will create a local calendar where I will populate the school days and times, and can create automation to tigger at the start and end of each day’s event to set the location to School.

Question: 1. How do I tell home assistant to ignore the phone location, when the location is set from the automation?
2. Is there a way to set manual location, other than adding a manual device tracker?

Thanks in advance

This scenario is difficult to address well, especially with a single device tracker entity. Unless it is turned off, the phone is going to push occasional location updates.

The only “fool-proof” method I know of is to use the custom services from Spook to remove and add device trackers to and from a person entity, though you will still need a second device tracker of some sort since a person entity without a device tracker usually returns an unknown state.

Another option you may also want to take a look at is the Composite Tracker custom integration. It will let you create a tracker by combine the phone tracker with other trackers or binary sensors, for example Workday or Schedule.

If your kid carries a school bag, wallet, or set of keys that could carry a BLE tracker, that is something you might want to consider.

Another method would be to create a manual device_tracker entity, and to remove all device trackers from the person and add only that manual entity. Then you can create automations that will update (or not update) the location of that manual entity based on whatever logic you want to come up with.

If you go to developer tools → services and choose device_tracker.see you can pick a name for your entity as the “Device ID”. So for example if you want a device tracker entity ID of device_tracker.bob_jones_manual_tracker then you enter bob_jones_manual_tracker as the device ID. Then call the service.

Once you call that service, you’ll be able to open the file called known_devices.yaml in your config directory and you should see an entry for that new device. If should have an entry under it of track: false and you’ll need to change this to track: true. Then you can restart HA and then you will see the new device_tracker entity. And you can now attach it to the person (and remove all other trackers) and then create automations to modify the location as you see fit. See the documentation for details on the service call.

It would be helpful to know how you’re using location tracking and what it is interfering with.

Ok So based on @mekaneck’s suggestion, here’s what I have done.

  1. Created a manual device tracker
  2. Assigned this to my kid’s user account
  3. Removed the mobile phone device tracker from the account
  4. Created an automation that would copy the GPS co-ordinates from mobile phone’s device tracker to manual tracker either every 5 minutes or when the mobile phone’s values change
  5. Created a local calendar called “School Days” and added the events for each day 8am to 4pm etc.
  6. Created an automation which triggers at the start of each event on the calendar and does 1) Disables the automation in step 4, and 2) set’s the manual tracker location to school
  7. Created an automation which triggers at the end of each event on the calendar and does 2) Enables the automation in step 4 and 2) copies the current gps values from mobile to manual tracker

Hope this should work. Lets see. I will update later.


But what are you actually doing with the result, once you have it? Is it just record keeping, or are you triggering other automations based on this updated/restricted location?

I assumed OP was trying to avoid false positives for occupancy-based triggers and conditions.

Just to let you know the steps above in my last post worked perfectly - although with a few minutes delay when switching from end of school (step 7) which I can live with. Thanks to @mekaneck for the idea.

@parautenbach I have automations for security and hvac running based on who’s at home. For example, when everyone leaves the automation arms the security - but this is defeated if the kids phone is at home… etc…

In that case you can avoid all the complexity of the device tracker updates and use your calendar as a condition in your automations, i.e. during these times, even if the entity is home, run the automation to arm the alarm.

I know, but this way gives me much more flexibility to build other automations based on the location.