hey guys, love the software and forum. I have setup a few zones, my work, home, my wife’s work, and the kids school.
i figured out how to get notifications on the app when anyone leaves or enters a zone. the problem is i have to write an automation for person 1 enters zone 1, person 1 leave zone 1, person 1 enters zone 2, etc. How do set it up so i get a notification when anyone comes or goes from a zone all in one automation?
- alias: notify on zone enter/leave
trigger:
- platform: zone
entity_id:
- person.brayden
- person.jordyn
zone: zone.centennial
event: enter
- platform: zone
entity_id:
- person.brayden
- person.jordyn
zone: zone.centennial
event: leave
action:
- variables:
event: "{{ 'left' if trigger.event == 'leave' else 'arrived at' }}"
person: "{{ trigger.to_state.attributes.friendly_name }}"
zone: "{{ trigger.zone.attributes.friendly_name }}"
- service: notify.mobile_app_craigs_s20_mobile_app
data:
message: >
{{ person + ' ' + event ' ' + zone }}
- service: notify.mobile_app_richelles_s10_mobile_app
data:
message: >
{{ person + ' ' + event ' ' + zone }}
You just need to add an enter and leave trigger for each zone. Unfortunately you can’t have one trigger for multiple zones or for leave and enter event.
Edit:
And please format your code correctly. Read the community guidelines here, point 11.
hey man, thanks so much for helping as i am in a little over my head right now, will try when i get home. do i enter these just in the automations.yaml file or try to do in the UI? also, if i wanted to add more people, just put them under person.jordyn? what about adding a few more zones? thanks again Burningstone, appreciate you taking your time to help.
thanks so much, can’t wait to try and get rid of about 20 automations, lol…
edit… just re-read your response… sorry about the code, i was on my cell phone. not 100% sure i understand about adding triggers for the zones, will have to do some reading…
Hi, @xman111 - here’s a possibility to consolidate things a bit.
First, create a notification group - then all you need to do is notify the group instead of each person individually. Place the following in your configuration.yaml under notify: (or in your notifications.yaml file if you are using that) and, unfortunately, there isn’t a reload for notifications so you have to re-start (unless someone else knows an easier method):
I used two “pairings” in the automation - one for home and one for school. You can copy/paste those to add more zones to the automation. I can’t find where these can be combined together into something like this that simplifies it even further (maybe a future update will address it):
zone:
- zone.home
- zone.school
The action section is then the service call to the group you set up in the notify: section of your config file. The template in the data section simply pulls the info from the trigger.event and the trigger.entity_id. Note that the template is generic and shouldn’t need to change when you had more zones to the trigger section.
Coming clean: I wasn’t able to test this completely, but it does pass the configuration check…
thanks KSC for typing all that out… you guys are awesome… i can’t wait to get home to try it out. I will just backup my config before i mess with everything. i really appreciate it sir!
Yea, I finally set up an automatic backup for all my config files… I’m embarrassed to say how many times I’ve had to recreate things because I didn’t have a recent backup…
yes, it’s quite a bit of work to recreate everything. that is one thing i couldn’t believe that you had to do in smartthings, was happy to see it available in Home Assistant… i have about 15 backups, before Zwave, before Caseta, etc… lol…
i was just thinking about this and have another question. In my arrives home automation, i have it turn on the front lights, turn off our alarm, then notify me and my wife. Can that be done with this as well or should the notify just be by itself and do the alarm and lights in a separate automation?
Definitely it can be done, and is the way I’d do it. Just add the other services to the action portion of the automation. For example:
action:
- service: notify.family_devices
data:
title: Notification
message: >
{% if trigger.event == "leave" %}
{{ trigger.from_state.attributes.friendly_name }} left {{ trigger.zone.attributes.friendly_name }}
{% else %}
{{ trigger.from_state.attributes.friendly_name }} entered {{ trigger.zone.attributes.friendly_name }}
{% endif %}
- service: light.turn_on
entity_id: light.front_lights
# You can add attributes, such as brightness and transitions here, too.
You can make it a little smarter by adding logic to determine if the sun is up or down with a service_template (make sure you have the sun component in your configuration.yaml file:
thanks again, can’t tell you how much I appreciate this. tbe wife and kids are annoyed at how much time I am spending on this, lol. can this all be done in the UI or don’t bother and just straight in the yaml files?
You can’t execute it, you need to enter/leave a zone. When you trigger it manually, it will skip all conditions and triggers and go directly to the action part and the action part doesn’t work because it uses data from the trigger, which is not available when you trigger it manually.
To test zones without leaving your home, you can use the device_tracker.see service.
You have a parameter listed more than once. If you post your automation, we can help figure it out. Sometimes it’s not the exact line, but one near it (depending on whether or not there’s a syntax error in there somewhere)
Yea, that’s why I couldn’t fully test what I posted…