Create button visible only for a specific user

Hi.

can someone helpme to know how can I make a button only visible to an specific user? I want to create an automation that open the garage door only if the user that is asking for is in home.

thanks!

use the “state switch” custom lovelace card.

That shouldn’t be difficult as long as your system knows that the user is “in” the home. Does it already know that?

I don´t find the way to restrict the access to only a specific user, do you have a code example?

For this I will use the life360 integration that say in which “place” is each user.

Here is a code example that I use to show one set of switches for one user or another set of switches for another user depending who is logged in to HA:

  - type: custom:state-switch
    entity: user
    default: default
    states:
      user_1_here:
        type: entities
        title: Your title here
        show_header_toggle: false
        entities:
          - input_boolean.user_1_switch
      user_2_here:
        type: entities
        title: Your Title Here
        show_header_toggle: false
        entities:
          - input_boolean.user_2_switch
      default:
        type: markdown
        content: >
          ## Unknown user

Thanks, can you help me a little more? I tried everything and I still getting this message:

see the dash in front of line 1 in my code posted above?

either add that or move everything below line 1 over to the left two spaces.

type: custom:state-switch
entity: user
default: default
states:
  user_1_here:
    type: entities
    title: Your title here
    show_header_toggle: false
    entities:
      - input_boolean.user_1_switch
  user_2_here:
    type: entities
    title: Your Title Here
    show_header_toggle: false
    entities:
      - input_boolean.user_2_switch
  default:
    type: markdown
    content: >
      ## Unknown user

Thanks you were right.

But I still have some errors… do you know why?

did you install the state-switch custom card?

Nope, how i do that?

either follow the instructions on the custom card repo:

or install HACS and install it from there:

Done! But I still have some problems…

do you know what is happening?

there are two possibilities for the “user” - the username of the user or the name of the user.

When you created the user in HA it asked you for the users name in the first line. then on the second line it asks for your username.

the configuration above uses the “name” (what you put on the first line in the on-boarding setup) not the “username”.

my name and username is the same except my name is capitalized and my username is lower case so I use the capitalized version of my name in the state switch config.

Thanks! You are a genius!

1 Like