Garage opening script - Notification issue

Hi all,

i have implemented a script to open or close my garage using the mobileapp/carplay.
And i have to come to a point/issue where i dont know how to solve it if even possible.

I wanted to send a notification to only the person/user/mobileapp that triggert the script, that does not seem to be possible as script do not seem to work with:

- service: notify.mobile_app_{{ trigger.actor }}

Is there a way to achieve this ?

Here is my script so far:

alias: Garagentor Steuern und Benachrichtigen
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: cover.garagentor
            state: closed
        sequence:
          - action: cover.open_cover
            target:
              entity_id:
                - cover.garagentor
            data: {}
          - delay: "00:00:05"
          - condition: state
            entity_id: cover.garagentor
            state: open
          - data:
              message: Das Garagentor wurde geöffnet.
            action: notify.notify
      - conditions:
          - condition: state
            entity_id: cover.garagentor
            state: open
        sequence:
          - action: cover.close_cover
            target:
              entity_id:
                - cover.garagentor
            data: {}
          - delay: "00:00:05"
          - condition: state
            entity_id: cover.garagentor
            state: closed
          - data:
              message: Das Garagentor wurde geschlossen.
            action: notify.notify
  - choose:
      - conditions:
          - condition: state
            entity_id: cover.garagentor
            state: unavailable
        sequence:
          - data:
              message: >-
                Fehler: Das Garagentor ist nicht erreichbar oder in einem
                ungültigen Zustand.
            action: notify.notify

BR

Felix

Look in the trace of the script, there should be a context object and within it information about how it was triggered and who triggered it.

I will check that out, thanks for the hint.

It seems that the user id is there 2 times:

  context:
    id: 01JJCC897HR6WG7NJGNPJZC8NC
    parent_id: null
    user_id: null
context:
  id: 01JJCCD93ABS48SDTNENTVENR3
  parent_id: null
  user_id: 09413b86fff7402881ab4a33a143f10f

Great, to go from that user id to the entity name

{{ states.person | selectattr('attributes.user_id', '==', '09413b86fff7402881ab4a33a143f10f') | map(attribute='entity_id') | first  }}

ok but thats static right? I thought i would somehow be able to dynamically change the receiver of the message depending on who opened the garage.

Right, so extract the user id from the context object, which should be addressable as context.user_id into a variable, then use that variable instead of the hard coded string to get the entity id of the person or the friendly name and use that information to construct the notify service to call.

Thanks for your help! Wouldn`t it be easier to use an automation triggering the script and send the message through the automation to the one that triggered the automation. Is a skript even possible to use context ? With an automation this seems to be possible…