How can I assign the press of a physical switch to a user?

Hello,

I have an automation that checks whether a roller shutter has been activated or operated by a user.

The whole thing works quite well so far if I give the command to open or close the roller shutter by voice with my alexa, for example, or if I do it via the UI.

Here my code:

- condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.to_state.context.user_id is defined  }}"
      - condition: template
        value_template: "{{ trigger.to_state.context.id != none }}"
      - condition: template
        value_template: "{{ trigger.to_state.context.parent_id == none }}"
      - condition: template
        value_template: "{{ trigger.to_state.context.user_id != none }}"

This is the trigger works UI | Voice Command :

  • Home Assistant Cloud (Alexa voice command)
    “14:36:44 - 4 hours ago - Home Assistant Cloud”

  • Marc Schiller (UI - my logged in Username)
    (14:36:27 - 4 hours ago - Marc Schiller)

The problem is when I actuate the switch using a physical switch, HA recognizes it without assignment, only

  • The living room shutter was opened
    (18:39:23 - 6 minutes ago)

Is there any way to respond to the last situation? I need the whole thing to disable automation thats automaticly controls my covers, but when i interact over alexa,UI or physical switch the automation should be deactivated.

THX

has noone a idea?

The context is empty in the last situation. I.e. parent_id and user_id will be none.