How to show a card only to users in a certain location

I managed to integrate alexa’s shopping list in home assistant, which is already pretty dope.

I want to take this to the next level and display the shopping list in a prominent place in the dashboard for users that are in the supermarket (I’ve defined my usual supermarket as a zone in home assistant).

However, I couldn’t find any information on how to find out who the current logged user. If i want shopping and my wife stayed at home, I want the shopping list to show for me but not for her, and the other way around.

If I only was able to know who the current logged user is, I could use a conditional card to display the shopping list.

I believe that this could be done with browser_mod, but I don’t care as much for the specific device as i do for the user, and HA clearly knows who the current user is, so this seems like something that should be possible without third party packages.

make 2 zones at the supermarket - 1 for her and 1 for you?

You should be able to do this with the custom-state-switch card:

Thanks! That worked for me quite well. It is odd however that you have to resort to a card like this instead of having some sort of UI property or sensor named “current user”. Maybe it could go in the WTF initiative of this month.

There are a lot of things that people want to do with Home Assistant that the core does not do, (and possibly never will). Fortunately we have a very active community of third party developers and Home Assistant has allowed a method of inclusion for these third party tools.

Can you share how you did this?

Check this thread: Sync your Alexa/Todoist shopping list to the Home Assistant shopping list!

I wish alexa exposed webwooks directly instead of having to use todoist as a middle man, which inevitably adds some extra delay, but i’ve found it perfectly usable.

1 Like

Just sharing examples for people ending there:

Edit: Solution updated with better templates suggested by KairuByte. :slight_smile:

type: custom:state-switch
entity: template
template: >-
  {{ user|lower }}_{{ 'home' if is_state('person.' ~ user, 'home') else
  'not_home' }}
default: unknown
states:
  julien_not_home:
    type: markdown
    content: You're Julien and you are not at home.
  morgane_not_home:
    type: markdown
    content: You're Morgane and you are not at home.
  julien_home:
    type: markdown
    content: You're Julien and you are at home.
  morgane_home:
    type: markdown
    content: You're Morgane and you are at home.
  unknown:
    type: markdown
    content: I don't know who you are.

Get current user with zone name (or away):

{{ user|lower }}_{{ states('person.' ~ user)|replace(" ", "_")|lower }}
1 Like