Thanks for the great automation
i have one question but can i modify the notification i receive:
actually : the notification says that : Iphone de “name” entered SAMCHA (it’s my zone home), can i have something more explicit ? For example : “name” vient de rentrer à la maison
Thanks
Hi Guys,
I would like to do something similar.
The idea is, after a certain time (like 10 p.m.) check the location of people and if they are all in the house turn on a green light, if one is out of the house turn on a red light until they come back in.
This is what I did and it is working
alias: Back Home
description: “”
trigger:
platform: time_pattern
minutes: /10
condition:
condition: time
after: “22:00:00”
before: “02:00:00”
condition: zone
entity_id: device_tracker.iphone_di_rosy
zone: zone.home
condition: zone
entity_id: device_tracker.iphone_di_sofy
zone: zone.home
condition: zone
entity_id: device_tracker.iphone_13_di_bea
zone: zone.home
condition: zone
entity_id: device_tracker.unknown
zone: zone.fede_home_milan
action:
service: scene.turn_on
target:
entity_id: scene.lamp_green
metadata: {}
mode: single
But I do not like that the time pattern is always running, I did not find a way to start it after a certain time. And also I have to run in parallel another automation that turn a red light after 9:59PM like this:
alias: Turn ON Red Lamp
description: “”
trigger:
platform: time
at: “21:59:00”
condition: []
action:
service: scene.turn_on
target:
entity_id: scene.lamp_red
metadata: {}
mode: single
but now that call service I guess isn’t supported. Looks like you need to use Notification service. Where do i put this information so it specifies the person and the zone in question instead of a generic message?
I was also looking to setup this same automation and I think your solution is the best for what the OP was asking. I didn’t want to have to create a trigger for every zone. I find myself adding new zones all the time and I just wanted to be notified when my family enters and leaves these zones without having to update the automation. It was stated that you can’t have one trigger for multiple zones but your strategy does this perfectly. I’m surprised no one responded to you to help you figure out your syntax. Anyway, better late than never. Here is how I used you started to setup this automation:
alias: "Notify: Zone Changes"
description: ""
trigger:
- platform: state
entity_id:
- device_tracker.laura
id: Laura
- platform: state
entity_id:
- device_tracker.robert
id: Robert
condition:
- condition: template
value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"
action:
- variables:
person: "{{ trigger.from_state.attributes.friendly_name }}"
to_zone: "{{ trigger.to_state.state }}"
from_zone: "{{ trigger.from_state.state }}"
- choose:
- conditions:
- condition: trigger
id: Laura
sequence:
- device_id: [DEVICE ID]
domain: mobile_app
type: notify
message: >-
{{ person }} {% if to_zone == 'not_home' %} left {{ from_zone }}{%
endif %}{% if from_zone == 'not_home' %} arrived at {{ to_zone
}}{% endif %}
- conditions:
- condition: trigger
id: Robert
sequence:
- device_id: [DEVICE ID]
domain: mobile_app
type: notify
message: >-
{{ person }} {% if to_zone == 'not_home' %} left {{ from_zone }}{%
endif %}{% if from_zone == 'not_home' %} arrived at {{ to_zone
}}{% endif %}
mode: single
Thank you. Aside from editing the person.1, person.2 etc…
1- Is there anything I should change in your code to make it work for the Home zone?
2- Does this code notify the person that they themselves left/arrived at the Home zone? Or does it only notify about other persons (which I think is ideal)?
My message template includes the translation of the word ‘home’ in italian. So now my message is perfectly readable. I also changed the logic a bit. This will avoid empty messages when passing from zone to zone, without reaching a ‘not_home’ status
message: >-
{% set from = trigger.to_state.state %} {% set to =
trigger.to_state.state %} {% set person =
trigger.to_state.attributes.friendly_name %} {% if from == 'home' -%}{%
set from = 'casa' %}{%- endif %} {% if to == 'home' -%}{% set to = 'casa'
%}{%- endif %} {{person}} {%if from != 'not_home' -%}ha lasciato {{from}} {%
if to != 'not_home' -%} e {%- endif %}{%-endif %} {% if to != 'not_home' -%}
ha raggiunto {{to}} {%- endif %}
How would you specify that only person.1 receive notifications about person.2, and vice versa. I’ve tried a few things, but I’m pretty new to HA (only about two weeks) and haven’t figured out a lot yet. Thanks.
Maybe there’s an elegant way to do it, but you could used 2 automations, one for person 1 monitoring person 2 and one for person 2 monitoring person 1 and use the specific notify.mobile person.
#1 - device_tracker.bens_iphone is tracked to notify notify.mobile_app_brads_iphone
#2 - device_tracker.brads_iphone is tracked to notify notify.mobile_app_bens_iphone
Thanks for posting the cod above, I also added this to give a date/time stamp to the message:
{{now().strftime("%H:%M:%S on %m/%d/%y")}}
message: >
{{ trigger.to_state.attributes.friendly_name }} {% if
trigger.to_state.state == 'not_home' %}left {{ trigger.from_state.state
}} {{now().strftime("%H:%M:%S on %m/%d/%y")}} {% endif %}{% if trigger.from_state.state == 'not_home' %}arrived at
{{ trigger.to_state.state }} {{now().strftime("%H:%M:%S on %m/%d/%y")}} {% endif %}
Sorry for this newbie question (I just discovered HA few days ago)
Where do I have to put this code?
I tried to append it in my “configuration.yaml” (after having substituted correct persons and zone IDs) and keeping correct indentation but that produce parsing errors.
I have two problems with it…
1 - Periodically I get a ‘blank’ notification…in that it has the person’s name, but nothing else…which tells me that the person is neither entering or leaving a zone, and in fact…I’m sitting in the same room with them when it happens…they haven’t been able to identify what activity they are doing that’s causing it either…so, there is that…
2 - Reading up on Templating - Home Assistant it says “Avoid using states.sensor.temperature.state , instead use states('sensor.temperature').” as this can cause errors…this specifically uses those…so, I’m wondering if anyone with more skill on this has suggestions for changes that would prevent me from getting blanks, and to use the ‘suggested’ syntax
I noticed your trigger is “not_from” and “not_to”. I’m thinking rather than using that, why not use “from” and “to” instead and use “home” and “not_home”, then it won’t trigger only on those known states (and the states you want)?