alias: 'Notification when someone arrives'
trigger:
- platform: state
entity_id: device_tracker.dereks_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.kalees_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.nolans_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.todds_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.kims_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.johns_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.briannas_phone
from: 'not_home'
to: 'home'
- platform: state
entity_id: device_tracker.brandons_phone
from: 'not_home'
to: 'home'
condition:
condition: or
conditions:
- condition: state
entity_id: device_tracker.dereks_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.kalees_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.nolans_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.todds_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.kims_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.johns_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.briannas_phone
state: 'not_home'
for:
minutes: 10
- condition: state
entity_id: device_tracker.brandons_phone
state: 'not_home'
for:
minutes: 10
action:
- service: notify.pushbullet
data_template: >
{% if trigger.entity_id == 'device_tracker.kalees_phone' %}
message: 'Kalee has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.nolans_phone' %}
message: 'Nolan has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.todds_phone' %}
message: 'Todd has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.kims_phone' %}
message: 'Kim has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.johns_phone' %}
message: 'John has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.briannas_phone' %}
message: 'Brianna has arrived!'
target: device/Galaxy S7
{% elif trigger.entity_id == 'device_tracker.brandons_phone' %}
message: 'Brandon has arrived!'
target: device/Galaxy S7
{% endif %}
So this is kind of long haha but what I’m going for is obvious, but I run into config errors for the action section because of the data template. Not sure how else to do it…
You can (or should) remove the condition block (the logic is not clear). The condition block is checking for state to be not_home, but the automation is triggered when the state is `home. So, the automation will never trigger.
Gotcha, that’s what I feared. Is there another way to determine this condition that you know of? Or am I doomed to be notified of every wifi connection?
I currently have a couple automations setup which trigger an IFTTT action based on entering on leaving zones like this:
- alias: Arrive at Work
trigger:
platform: zone
entity_id: device_tracker.bob_s8
zone: zone.work
event: enter
action:
service: ifttt.trigger
data:
event: work_arrive
value1: "Bob arrived at work"
- alias: Leave Work
trigger:
platform: zone
entity_id: device_tracker.bob_s8
zone: zone.work
event: leave
action:
service: ifttt.trigger
data:
event: work_leave
value1: "Bob left work"
And 2 more automations for the home zone.
I’m trying to combine this into 1 automation.
How can I implement a second condition in the IF-statement?
Example: I want to add values to the action based on 2 conditions in the trigger: zone and state (enter or leave).
This is what I have now:
- alias: Presence Log
trigger:
platform: zone
entity_id: device_tracker.bob_s8
zone: zone.home, zone.work
event: enter, leave
action:
service: ifttt.trigger
data_template:
event: >
{% if trigger.zone == "zone.work" %} ### This is where I have to put the second condition which checks wether the event is "enter" or "leave"
event: work_arrive
value1: "Bob arrived at work"
{% elif trigger.zone == "zone.work" %}
event: work_leave
value1: "Bob left work"
{% elif trigger.zone == "zone.home" %}
event: home_arrive
value1: "Bob arrived at home"
{% elif trigger.zone == "zone.home" %}
event: home_leave
value1: "Bob left home"
{% endif %}
- alias: Presence Log
trigger:
- platform: zone
entity_id: device_tracker.bob_s8
zone: zone.home, zone.work
event: enter, leave
action:
service: ifttt.trigger
data_template:
event: >
{% if trigger.zone == "zone.work" and trigger.event == "enter" %}
event: work_arrive
value1: "Bob arrived at work"
{% elif trigger.zone == "zone.work" and trigger.event == "leave" %}
event: work_leave
value1: "Bob left work"
{% elif trigger.zone == "zone.home" and trigger.event == "enter" %}
event: home_arrive
value1: "Bob arrived at home"
{% elif trigger.zone == "zone.home" and trigger.event == "leave" %}
event: home_leave
value1: "Bob left home"
{% endif %}
Gives me the following error:
2017-05-11 20:36:09 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID zone.home, zone.work is an invalid entity id for dictionary value @ data['trigger'][0]['zone']. Got None