Hello
I want to create an automation which should send a notification alert when I reach home from a particular location only
Like Point to Point B
Hello
I want to create an automation which should send a notification alert when I reach home from a particular location only
Like Point to Point B
Create an automation that triggers when you enter the zone of point a, and then use a wait for trigger and wait until your person.your_name
state changes to home.
alias: Test
description: ""
trigger:
- platform: zone
entity_id: device_tracker.dp_iphone
zone: zone.station
event: enter
condition: []
action:
- wait_for_trigger:
- platform: zone
entity_id: device_tracker.dp_iphone
zone: zone.home
event: enter
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single
You need to use the 3 backticks ``` or press the </>
button to format the code properly.
eg:
```
some code here
across multiple
line
```
Aside from the obvious bad formatting of your code (see item 11 in the forum guidelines ), your condition is incorrect.
Your first condition of “enter zone” is correct, but to then wait for “enter zone” would never happen until a second instance. It’s saying “when I enter a zone wait for me to then enter the zone again before progressing”.
alias: Test
description: ""
trigger:
- platform: zone
entity_id: device_tracker.dp_iphone
zone: zone.station
event: enter
condition: []
action:
- wait_for_trigger:
- platform: zone
entity_id: device_tracker.dp_iphone
zone: zone.home
event: enter
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single
I am very new to Home assist, could you please guide me with an example
I guess instead of zone in the wait for trigger - you could just use state, and wait for the state of device_tracker.dp_iphone to become home
alias: Test
description: ""
trigger:
- platform: zone
entity_id: device_tracker.dp_iphone
zone: zone.station
event: enter
condition: []
action:
- wait_for_trigger:
- platform: state
entity_id:
- device_tracker.dp_iphone
to: home
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single
That looks more or less correct but bear in mind that the automation is in a wait state, meaning it’s using resources and if you restart home assistant then your wait is done. Your better option is two different automations, one for when they enter the Station zone and one when they enter Home zone.
But then they need to have helpers to store the state. Because they specifically only want to be notified when arriving home IF and ONLY IF they have been in the station zone.
template:
trigger:
- platform: state
entity_id: device_tracker.dp_iphone
sensor:
- name: Station Zone Status
state: >-
{% if states('device_tracker.dp_iphone') in ['station','home'] %}
{{ states('device_tracker.dp_iphone') }}
{% elif this.state in ['unknown','unavailable'] %}
{{ states('device_tracker.dp_iphone') }}
{% else %}
{{ this.state }}
{% endif %}
unique_id: station-zone-status-332246a9-7390-4b33-8480-c27cc4741621
I guess that would do it. Then your automation would simply check the state of this sensor changing. And specifically -
{{ trigger.from_state.state == 'station' and trigger.to_state.state == 'home' }}
Used in the condition.
alias: Test
description: ""
trigger:
- platform: state
entity_id: sensor.station_zone_status
condition:
- platform: template
value_template: "{{ trigger.from_state.state == 'station' and trigger.to_state.state == 'home' }}"
action:
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single
is there anywhere that is not in zone A or zone B that lies between those two zones that you will pass thru when going from point A to point B?
if so then it all falls apart.
you could trigger off of the phone leaving the station zone and the wait for a trigger when the phone enters the home zone. But that will still be at the mercy of not having the automation get interrupted while waiting for the wait for trigger.
If that is a concern (tho not really likely if you are travelling that your HA will get restarted, etc) then the only way I know to solve it would be to have two automations - one that triggers to turn on a boolean to say that you have left the station zone and then another that triggers when you enter the home zone but only if the station zone boolean is on to send the notification.
either way you should be using a trigger that is leaving the station zone instead of entering the station zone.
I am trying this, reaching to station from work
Is the code proper?
alias: "Test Location Notification "
description: ""
trigger:
- platform: state
entity_id:
- device_tracker.dp_iphone
to: Railway Station
condition:
- condition: zone
entity_id: device_tracker.dp_iphone
zone: zone.work
- condition: state
entity_id: device_tracker.dp_iphone
state: not_home
- condition: template
value_template: >-
{{ trigger.from_state.state == 'Work' and trigger.to_state.state ==
'Railway Station' }}
action:
- device_id: 988a4f085f3d570883bc33cd62e65418
domain: mobile_app
type: notify
message: Reached
mode: single
No there are several issues with it.
Work
and the zone Railway Station
- your state will be not_home
therefore the template will never be true.Work
and therefore cannot match the next condition which is not_home
This is the reason that I suggested creating a template sensor, because you can ignore the states that aren’t interested in, and thus you can trigger an automation based just on the state of the template sensor changing state, which will only be between the states you have configured it to output.
@mobile.andrew.jones’s solution should work, but I would set it up a little differently:
template:
- trigger:
- platform: state
entity_id: device_tracker.dp_iphone
to:
- home
- station
- platform: state
entity_id: device_tracker.dp_iphone
to:
- work
- home
for: "00:10:00"
id: reset
sensor:
- name: Station Zone Status
state: >-
{% if trigger.id == 'reset' %}
reset
{% else %}
{{ trigger.to_state.state }}
{% endif %}
unique_id: station-zone-status-332246a9-7390-4b33-8480-c27cc4741621
alias: Test
description: ""
trigger:
- platform: state
entity_id: sensor.station_zone_status
to: home
from: station
condition: []
action:
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single
Another option would be to set up a History Stat sensor with a time frame that matches the maximum amount of time you want to track if you had been at the station.
sensor:
- platform: history_stats
name: Time at Station
entity_id: device_tracker.dp_iphone
state: "station"
type: time
start: "{{ now() - timedelta(hours=6) }}"
end: "{{ now() }}"
Then your automation would use the sensor value being over 0 as a condition:
alias: Test
description: ""
trigger:
- platform: state
entity_id: device_tracker.dp_iphone
to: home
not_from:
- unavailable
- unknown
condition:
- condition: numeric_state
entity_id: sensor.time_at_station
above: 0
action:
- device_id: xyz
domain: mobile_app
type: notify
message: Reached Home
mode: single