Google home geofence example

There are options to track multiple Android phone locations using the GPSTracker binding with either Owntracks or GPS logger, however these have some drawbacks.

If what you want to do is trigger events when Android phones (people) wander in and out of locations you can use Google Home geo-fence.

What you need to do this is to set up
openHAB Cloud Connector
and set up
Google Assistant

Create a switch item in openHAB for each android and location you wish to track. See the example item definition below.

Switch  BobHomeGoogleGeoFence  "Bob at home"  ["Status","Presence"]  {ga="Switch"[roomHint="Outside"]}
Switch  BobWorkGoogleGeoFence  "Bob at work"  ["Status","Presence"]  {ga="Switch"[roomHint="Outside"]}
Switch  BillHomeGoogleGeoFence "Bill at home" ["Status","Presence"] {ga="Switch"[roomHint="Outside"]}

On each phone you whish to track you will need to download the Google Home App

On each phone connect Google Home to openHAB via the Cloud Connector, instructions at above links.

You will have to move your openHAB Google exposed devices to the appropriate Google Home App address (home) and add them to a room.

To add another address (home) to Google Home:
Open Google Home, press the +, select Create new home and type in a Home nickname, press continue and type in the address. Finally press next. The new home will appear in a drop down at the top of the App home page.

To move a geofence switch to this new address (home):
Open Google Home, long press the device mimic to be moved, press the settings icon (cog) in the top right hand corner then tap the home property. Click on the new address (home) and select next and assign it to a room, a custom room can be made at the bottom of the list.

Once complete the new home to which the device was moved will now show the “Set up home and away routines” button at the top.

Now set up each Google Home ‘Home and Away Routines’ for each home address, to toggle the appropriate switch made above. Follow the video linked below.

This video will help explain how to set up “Home and Away Routines” using geofences.
Now you are able to control rules / routines in openHAB based on the state of the switches defined.

Here is a simple rule to send a push notification to the openHAB android App. Replace email_address_for_cloud_connector with your openHAB cloud connector account email address.

rule "Announcement Arrives Home"
    when
        Item BobHomeGoogleGeoFence changed  to ON 
    then
        sendNotification("email_address_for_cloud_connector", "Bob will be home soon")
end

Enjoy

Google Home App is available for Apple but I’ve not tried it.

1 Like

Good stuff. How fast and accurate do you find this to be?

You’re communicating a lot of information in these two sentences. For the purposes of a tutorial, I’d suggest unpacking it a little to guide people through the individual steps.

There’s a typo in your video URL (“outube” instead of “youtube”). :wink:

I’d imagine it should work fine. The speed/accuracy may be be better or worse, depending on the location information.

It appears to be pretty quick, switching correct with about a minute resolution when leaving and entering the geofence.

Thanks, fixed now

Thanks for the review comments, I have added further detail on How to add extra homes to Google and move the switch across.
There is a limit of 5 homes per account.

I was actually referring more to the part about `Home and Away Routines’. When I first read that, it took me a minute to realize what you were talking about. Specifically:

  1. Open Routines in the Google Home app
  2. Open the built-in “Home” routine
  3. Add an action to toggle the BobHomeGoogleGeoFence switch to ON (which will send that command to openHAB)
  4. Save the “Home” routine
  5. Open the built-in “Away” routine
  6. Add an action to toggle the BobHomeGoogleGeoFence switch to OFF (which will send that command to openHAB)
  7. Save the “Away” routine

I try to lay out all of the steps in tutorials, even when they seem obvious to me. It helps people who are unfamiliar to understand the process and be confident that they’re doing things correctly. It’s also easier to identify where the confusion is if someone’s having trouble (or if/when Google changes their UI again).

That seems pretty reasonable.

I couldn’t figure out why you would need multiple homes in Google Assistant, but I think I get it now. You’re using this feature to pinpoint locations that may not actually be homes. So you could set up multiple locations that you frequent, such as your office, your friend’s house, and the grocery store. That enables openHAB to know whenever you’re in one of those places.

I think I’d be fine with just the Home/Away for one location, since I’m only going to want openHAB to do things when I leave and return. What kind of scenarios are you using beyond that?

Exactly.
While Google Home refers to these locations as Homes, you are free to define any location. There are a ton of Scenarios where this could be useful.

  1. Where you have multiple properties/ buildings and want to track who is where.
  2. Where you want to turn something on in advance. E.g. start your HVAC when you arrive at your local rail station.
  3. Inform someone you have arrived at a specific point. Perhaps you have caring duties and you want let them know you are on your way.
  4. When a dependent arrives at a location. Perhaps you want to know when your child arrives or leaves school.
1 Like