Automation to open the garage door only if the user is in home

Hi

Can someone help me to know how to create an automation that make this:

If (the user press one button in my UI) {
    if(the user is in home){
        send: "open" in the mqtt topic: "home/garage"
    }else{
      don´t send nothing
    }
}

the important is that the automation have to know which user press or trigger the button to check if he/she is in home or not.

thanks!

I can almost help…but I’m stuck too on figuring out how to tell who pushed the button.

script:
  garage_auth_open:
    # Pass this in, or figure out a way to look it up...
    fields:
      user:
        description: 'person to check if home'
        example: person.luis
    sequence:
      # Exit if person is not home
      - condition: state
        entity_id: "{{ user }}"
        state: 'home'
      - service: cover.open_cover
        entity_id: cover.garage

I can get a user_id from the following…

states.script.garage_auth_open.context.user_id

But I have no idea how to map a user id to anything meaningful.

It would be easy enough to create a custom button for each user that only they would see on their views…but there’s got to be a better way.

Hoping

Thanks, that is very helpful

Do you know what I´m doing wrong? (I want to create a button only visible to a specific user)