Sometimes DHL delivers a package when we are not at home.
When not home our alarm automatically arms the alarm, meaning that state changes of Door/Window or PIR sensors will trigger the alarm.
I could open our garage door in HA to let DHL put the parcel in our garage. However I must not forget to disarm the alarm. If not, opening the garage door will trigger the alarm.
I wonder if it is possible to create an automation with two triggers.
Trigger 1: physical press on wall switch to open the garage door
Trigger 2: door opened via the HA app on our mobile phones. (based on user that is logged in the HA app maybe?)
Trigger 1: should do nothing, a burglar should not be able to disarm the alarm via the garage door wall switch.
trigger 2: should, run a sequence that will first disarm the alarm and afterwards open the garage door.
Any idea how I could create these two different kind of triggers?
Automation actions allow for “if >> triggered by” action
Many other “if” conditions are allowed.
These are configurable in the GUI. Sorry i could not find it in documentation but when i do i will edit this post to include it.
platform: state
entity_id:
- light.X
to: ON
id: lamp
choose:
- conditions:
- condition: trigger
id: lamp
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.X
What I am looking for is, how I can distinguish who actually triggered lamp X.
Was the wallswitch manually pressed → ( `trigger.to_state.context.user_id == none’) or,
was it triggered in the the HA app → (trigger.to_state.context.user_id == username who was logged into the HA app)
I feel I need "trigger.to_state.context.user_id " for this instead of “triggered by”.
Any examples or alternatives how I could do this?
You can use trigger.to_state.context.user_id as it will be your user id when you do by HA or none when someone press the button.
So you can use this in an if..then..else.. statement:
- condition: template
value_template: >
{{trigger.to_state.context.user_id is none}}
platform: state
entity_id:
- light.X
to: ON
choose:
- conditions: # If triggered by user in HA
- condition: template
value_template: "{{trigger.to_state.context.user_id is not none}}"
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.X
- conditions: # if triggered by physical/manual switch
- condition: template
value_template: "{{trigger.to_state.context.user_id is none and trigger.to_state.context.parent_id is none}}"
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.X
trigger.to_state.context.user_id is none tells us it’s not triggered by user in HA trigger.to_state.context.parent_id is none tells us that it is not triggered by an automation or a script