How to automatization depend of source of event?

Dears experts!
I’ve a problem how to setup automations depend of source of event. I means really example situation:
I’ve a Shelly device with physical button. It was integrated and working fine. I want to have checking what was a trigger of device to “off”. Below automatization working independent of source triggering action:

alias: 'Test_1'
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: 419bkjwhdncl2kwdhcofb36ee62e8c
    entity_id: switch.hol
    domain: switch
condition: []
action:
  - service: notify.mobile_app_kris
    data:
      message: Light turned off.
mode: single

It’s means - I can turn on/off by the wall switch or by the HA button. I want to have automatization which behavior will depend of source off trigger action. In logbook looks like:
by wall button - “Shelly hol turned off”
by HA interface - “Shelly hol turned off by Kris
by automatization: - “Shelly hol turned off by Auto_1: turn off when no motion detected

How to modify automations to react only when ie. user or other automations was trigger action?

Thanks’ in advance!

What does this show for each of the triggers?

action:
  - service: notify.mobile_app_kris
    data:
      message: Light turned off. {{ trigger.to_state.context.user_id }}

It show only message, nothing else :wink:
My idea is perform action depend of user/automation, not adding user to message.

Yes but to perform those actions I need to know what the exact context for each method is. If you are not willing to provide that information then I can’t help you.

Maybe will simplest, when I explain what I exactly want to achieve :slight_smile:

If turn off by wall switch (default) → send notifications
If turn off by Kris (user) → send notification and turn on automation_1
if turn off by automation_AD → send notification and turn on automation_2

It seems something like “options” in actions section.

Kris

I understand what you want but if you do not provide the information I requested I cant help you.

I need you to trigger the automation by each of the three methods and post the resultant message that contains {{ trigger.to_state.context.user_id }} here.

Then when I know what the context.user_id is for each of those trigger methods I can show you how to implement the automations you want.

tom_I,
please be a little patient, because I’m beginner in HA and sometimes incorrect understand what you ask me :wink:

Right now I’ve automation:

alias: '! test 2'
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: 419b5ae548e61377fffc5fb36ee62e8c
    entity_id: switch.biurko
    domain: switch
condition: []
action:
  - service: notify.mobile_app_kris
    data:
      message: Light turned off {{ trigger.to_state.context.user_id }}
mode: single

Results:
wall botton → Light turned off None
HA button → Light turned off ebe2fa210… (some id?)
other automation ->Light turned off None

I cannot add logbook (no privlieges).

Kris