Get currently logged in user in a template?

Is there any way in templating to figure out which user is logged into the app? I want to do some minor conditional logic based on who is logged in, as well as using card_mod to display certain elements, or display them differently, depending on which user is logged in and use in conditional cards if possible. thanks

1 Like

I’m a bit late for this but I’m trying to figure out the same thing… odd no one seems to ever answer the question…

hass.user

It’s only accessible by cards that support JavaScript which currently means some custom cards (not standard cards).

Example:

1 Like

Now that makes sense!!! Thank you!!

Thomas Lovens browser mod integration can get this information, but you should understand the limitations:

  1. Multiple people can be logged in at the same time. Your template will have to account for that.
  2. The same person can be logged in from multiple locations.
  3. Browser mod will create a number of entities that represent each logged in endpoint. You have to always search these entities and new ones that are created.

TLDR: It’s possible with a custom integration, but it’ll be a complex template.

1 Like

Did anyone work on this? I’m curious, especially with recent login attacks.

nope

:frowning: Thanks for the quick response.

Hi

With the latest 2023.11 release, introducing conditional card based on user, is there perhaps a new/easier way to use the current user in a template?

Was hoping for {{ user }} but nope, lol

You can only get the user in the frontend. You can’t get the user in the backend. You’ll likely never be able to get the user in the backend (i.e. template entities).

1 Like

Is that a technical incapability or a a decision not to implement it for an end user implement?

I see the logged user icon is visible on the bottom left on desktop, maybe someway to replicate this inside a card perhaps?

As it was already told here:

  1. The currently logged in user is available in Frontend ONLY. The username may be acquired by using a “{{user}}” template - but only in cards which support templates.
  2. The currently logged in user is NOT available in automations, scripts, template sensors etc.