Make "context" available in homeassistant scripts

I would like to create a script with user specific logic, but unless the trigger to start the script includes service_data, the script gets no information on what it triggered it. I would like to make “context” available in scripts (which is available in automations by using trigger.from_state.context).

My use-case:

  • I have two garage doors and a gate at the fence
  • I would like to create a script, which would open the fence gate as well as the right door (mine if I am arriving and my wife’s when she is).
  • I would trigger this script from lovelace (as I don’t have the triggers at this point). Since it involves opening the gate I am not sure I would want to automate this in the future, but I might if the security risks can be mitigated.

My attempts at discovering what’s possible and their problems:

  • when script.turn_on is invoked without service_data, there are no template variables defined in the script (e.g. no trigger)
  • lovelace allows me to specify a service_data, but that supports literal strings only (if I am not mistaken)
  • if I am using an automation that waits for a change in status, I can get to the user_id, but it is pretty cumbersome, as I need a lot of configuration boilerplate: 1) input_boolean, 2) an automation that polls it and then 3) I can include the script in actions or invoke a script with an explicit user_id argument).