Zone names, and automation triggers

I’ve had several zones set up for work, church, extended family, etc. and have been trying to set up an automation so that when I leave one of those locations and head home, the HVAC turns on about 10 minutes before we are scheduled to get home, to heat/cool the house appropriately (automations adjust the climate when we’re not home so we’re not wasting power on heat/cooling when nobody is home). I’ve spent several days fighting this simple automation, and had various issues that I’ve been working through. But this last one really had me scratching my head. Here’s an example automation trigger to show what I’ve had set up for my wife when she leaves work):

automation heading_home:
  trigger:
  - platform: zone
    entity_id: person.wife
    zone: zone.w-work
    event: "leave"

One would expect this to work, and indeed when we are at work (or visiting family, or church, or whichever zone we happens to be in), our person entry actually shows that we’re in that zone (at least, it shows in the history and dashboard as such). However, this particular automation has been failing on the zone: zone.w-work and similar entries consistently. I’ve had 20+ zones set up at this point, and have been using several of them in this automation, with plans to add almost all of them, since I haven’t yet been able to develop a fool-proof way to set a way-point zone that triggers the automation when I or my wife get within 10 minutes of home… So, in the absence of that logic and configuration, I’m using the above logic. And these zones have all worked perfectly fine as far as showing where we are currently located (if my wife is visiting her sister or kids, for example, she always shows as being in the appropriate zone).
So my problem has been that after I created the automation to trigger on leaving a particular zone and set a variable to trigger a climate reset, I got the following error whenever I load the automations:


This had me pulling my hair out, but finally, after much trial and error and very little hair left, I discovered that in one of my trigger entries, I had made a mistake and used underscores instead of dashes in the zone name, such as follows:

  - platform: zone
    entity_id: person.me
    zone: zone.my_work
    event: "leave"

…instead of entering it correctly as zone: zone.my-work, as it had been named when I created the zone, and yet this particular entry did NOT get flagged with an error (I had moved it to the top of the list, so it was now the first one, which had always been flagged with an error)! So I subsequently renamed ALL of my zones to use underscores ‘_’ instead of dashes ‘-’ in their names, and reloaded the automations. Wouldn’t you know, that resolved the issue! No more errors!

I’ve spent a little time going through the documentation and so far have not found any indication that we should not use the dash in zone names, so I’m thinking that this might be a bug with the automation code. Anyway, wanted to post this on the chance that someone else might run into the same issue. If the docs do actually indicate not to use dashes in the zone names, please post a link. Thanks!

BTW, if anyone has a great idea regarding triggering the system to adjust the climate that doesn’t include leaving a zone, that would be awesome. I’ve thought about setting up small “zones” on the primary highways and streets that we use to reach our home, but we also use those streets when driving to other locations, so I’m hesitant to use that method… And I don’t particularly want to make a manual switch that I select on our phones, for instance, when we’re on our way home.
There are a lot of potential options, including setting up several zones along the various routes home and tracking our drive through those zones, but I’m not sure I want to get into setting up the AI scripts to handles that navigation… If anyone else has set up automations to do something similar, I’d love to hear what works for you, or something that’s been tried that doesn’t work for one reason or another…

It’s not a problem using dashes in zone names.

But…

HA will create the entity_id based on the zone name by (pardon the non-tech and likely incorrect use of the term) “slugifying” it based on the characters in the name.

dashes and any other “non-preferred”(?) characters get replaced by underscores in the entity_id. And any capital letters get converted to lowercase.

And the entity_id is what you use in your automations, not the zone name. That’s why “zone.my_work” worked and “zone.my-work” didn’t.

If you look in the dev tools->states page you will see what the actual entity_ids are.

2 Likes

Have you looked at Proximity - Home Assistant

2 Likes

Using this you can define triggers and conditions to check if someone is moving away from one zone and towards another, and even down to their distance from one or the other.

You could also then combine this with the activity sensors from the HA companion app if you use it, to determine if they are driving, walking, cycling, etc. Sensors | Home Assistant Companion Docs

1 Like

Thanks, @finity! That clears up a few things. I’ll go over that and try to memorize it. Otherwise I know it will bite me behind again some day soon…

@DerekO, I haven’t. But it sounds like I definitely need to give it a look. Might be just what I’m looking for…