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


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"
      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.


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

    # Pass this in, or figure out a way to look it up...
        description: 'person to check if home'
        example: person.luis
      # 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…


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.


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)