This is the simplest example, but I have several automatons for my wife and I that are similar. Looking for ideas for two different enties to take different actions based on the trigger entity.
I don’t believe this works. Saw another thread about this a week or so ago.
@ptdalen the end solution provided by @pnbruckner was to create a condition and omit the event_data from the trigger.
The action will take some massaging to get it to work correctly, as you need to select the opposite person. I’ll be heading home soon and I can take a look at it. I believe @lolouk44’s action section should work fine too with a minor change. The event trigger doesn’t contain an entity id, the trigger.event.data contains the entity id. Trigger template stuff is here:
What if I had condtions that were different depending on the entity triggering? Too complex, not worth it?
the trigger and the actions are pretty much the same. I use this to auto unlock the door when I 1st arrive (timer automation above), but only once. The input boolean keeps it from opening multiple times in while the timer runs. I guess I could cancel the timer instead of the boolean, but when I did the timer, I had plans on doing other automations while the timer was on, so maybe not
- alias: 'Unlock Back Door for person1'
trigger:
- platform: state
entity_id: binary_sensor.backyard_line_crossing
to: 'on'
condition:
- condition: state
entity_id: timer.person1_just_arrived
state: 'active'
- condition: state
entity_id: input_boolean.back_door_opened_for_person1
state: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.back_door_opened_for_person1
- service: lock.unlock
entity_id: lock.lock_back_door_lock
- alias: 'Unlock Back Door for person2'
trigger:
- platform: state
entity_id: binary_sensor.backyard_line_crossing
to: 'on'
condition:
- condition: state
entity_id: timer.person2_just_arrived
state: 'active'
- condition: state
entity_id: input_boolean.back_door_opened_for_person2
state: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.back_door_opened_for_person2
- service: lock.unlock
entity_id: lock.lock_back_door_lock
It’s definitely possible, the only thing is although you reduce the number of automations, you increase their complexity. This doesn’t make much difference for HA, but it will give you grey hairs when you need to troubleshoot what went wrong…
This specific automation doesn’t trigger based on a person so it might actually turn up a lot more complex and lengthier than 2 automations…
- alias: 'Unlock Back Door for person1'
trigger:
- platform: state
entity_id: binary_sensor.backyard_line_crossing
to: 'on'
action:
- condition: template
value_template: >
{% set people = [
states.timer.person1_just_arrived,
states.timer.person2_just_arrived,
states.timer.person3_just_arrived ] %}
# get the people who arrived.
{% set arrived = people | selectattr('state','eq','active') | list %}
# did anyone arrive?
{% if arrived | length >= 1 %}
# find the first person who arrived home and get 'who' did.
{% set person = arrived[0].split('.')[-1].split('_')[0] %}
# make sure their boolean is off
{{ is_state('input_boolean.back_door_opened_for_%s'%person, 'off') }}
{% else %}
False
{% endif %}
- service: input_boolean.turn_on
data_template: >
{% set people = [
states.timer.person1_just_arrived,
states.timer.person2_just_arrived,
states.timer.person3_just_arrived ] %}
# get the people who arrived.
{% set arrived = people | selectattr('state','eq','active') | list %}
input_boolean.back_door_opened_for_{{ arrived[0].split('.')[-1].split('_')[0] }}
- service: lock.unlock
entity_id: lock.lock_back_door_lock