Utility - Zones.yaml builder

I use a lot of zones with my home assistant, mostly for automated messages for my wife and I to know when we’ve arrived at the store or on our way home from work. My wife recently was promoted and when she’s traveling we wanted to have the same type of functionality (left her hotel, arrived at the storefront, left the storefront, etc). I manually created the zone yaml files for the locations near our house, but that’s a bit much for me to ask my wife to do. I instead made a simple HTML/Javascript tool that lets her put the information into a form instead of a text file. Then once she finishes the key locations for that area, she simply gives me the yaml file it creates and I throw it into my Home Assistant configuration.

Github Repo

Utility hosted on Github.io

Hope you will check it out and let me know what you think! My wife’s first question was wanting to use an address instead of latitude and longitude. I was unable to find an api-free way to do that (there are free APIs but of course are rate limited), but may break that function into a separate file so that I can get her something to work with (and allow others to do the same, just by providing their own API key).

Just an idea as an alternative to addresses: HTML5 Geolocation. If your generator would prefill the location-box with the location her phone recognizes, she would only have to give it a name (and radius if necessary). If you place some sort of “Send as E-Mail” button with a customizable recipient (to keep things generic), she would just need to do this whenever she’s at a new place.
Of course the limitation would be, that this has to be done while actually being there. But compared to finding out lat and lon it may be a lot more convenient to just quickly grab the phone and send the zone-data.

She knows ahead of time where she’ll be staying and the planned itinerary, filling it in the day of would be more of an interruption than convenience I think.

You have a good idea for adding a one-off zone though. A simple name+radius and the HTML5 location and a “add to Home Assistant” button might be useful.

Updated the utility. It now will let you use your current location or use an address for the location to add.

The rest still functions the same; add locations until you’re satisfied and download (or copy) the zones.yaml for your own use.

It might be a bit OT, but since you mention automations to notify you about location changes:
I assume you are using Owntracks or something alike? Because I am trying to get the same thing to run, and it basicly works, but the message is not limited to the zone name. What I get from “trigger.to_state” (trigger is state change of device_tracker.NAME) is a mess of probably mqtt related informations that I neither need nor want. Also, the state change triggers on basicly every owntracks update rather than zone change only.

Did you have a similar issue, or how do you setup these notifications? I want something like:
NAME left zone1 and entered zone2.

I was using Owntracks but switched a few weeks ago to GPSLogger, and have been a lot happier. It seems a lot lighter on my battery while still reporting location changes within a few minutes. It also isn’t mis-reporting, which was an issue my wife and I had with Owntracks.

As for the automation, I am using node-red and the basic flow is like this:

  1. Change in the state of device_tracker.* (if any tracked devices changes states)

  2. Discard if the old_state is the same as new_state (e.g. if I move from one end of my house to the other, GPSLogger may send an update, so if the zone is the same, I stop the automation)

  3. Parse the event

    a. Based on the name of the device, I set a “who” variable (equal to my first name for my device).

    b. Looking at the new zone, if it is “not_home” I simply say “left PREVIOUS_ZONE” and if it is a zone I say “arrived at ZONE”

  4. I send a message to a discord channel my wife and I are in.

The end result ends up looking like this:

chrome_2018-12-10_08-57-42

The code that sets the location part of the message (maybe this will help you):

[redacted switch/case for setting msg.who]

msg.leaving = msg.data.old_state.state;
msg.arriving = msg.payload; 

if (msg.payload === "Home")
    msg.message = msg.who + " arrived at home.";
else if (msg.payload === "not_home")
    msg.message = msg.who + " left " + msg.leaving;
else
    msg.message = msg.who + " is at " + msg.payload;

return msg;
1 Like