Image in Greeting message based on user login

Hi All,

Could you please assist me to get this working? I am looking for change of picture based on user login to home assistant.

type: custom:mushroom-template-card
primary: |
  {% set time = now().hour %}
  {% if (time >= 17) %}
  Good Evening, {{user}}!
  {% elif (time >= 12) %}
  Good Afternoon, {{user}}!
  {% elif (time >= 6) %}
  Good Morning, {{user}}!
  {% else %}
  Hello, {{user}}!
  {% endif %}
secondary: ""
picture: |
  /local/test123.png
fill_container: false
multiline_secondary: false
icon: mdi:human-male
tap_action:
  action: none
hold_action:
  action: none
double_tap_action:
  action: none

You can use a dictionary to map user names to a image file paths, then use the get() function:

type: custom:mushroom-template-card
primary: |
  {% set time = now().hour %}
  {% if (time >= 17) %}
  Good Evening, {{user}}!
  {% elif (time >= 12) %}
  Good Afternoon, {{user}}!
  {% elif (time >= 6) %}
  Good Morning, {{user}}!
  {% else %}
  Hello, {{user}}!
  {% endif %}
secondary: ""
picture: |
  {% set mapper = {
  "Person 1": "/local/test1.png",
  "Person 2": "/local/test2.png",
  "Person 3": "/local/test3.png",
  }%}
  {{ mapper.get(user, "/local/test_default.png") }}
fill_container: false
multiline_secondary: false
icon: mdi:human-male
tap_action:
  action: none
hold_action:
  action: none
double_tap_action:
  action: none

Thanks much, this definitely helps. But cannot I use the already available entity picture attribute for a user instead of hard mapping image to a user?

A related thread. Browser mod may still be an option. @Didgeridrew suggestion is better in my opinion, unless something has changed.

1 Like

Just a quick test:

type: markdown
content: xxx
card_mod:
  style: |
    ha-card {
      {% set PERSON = 'person.' + user -%}
      {%- set IMAGE = state_attr(PERSON,'entity_picture') -%}
      background-image: url({{IMAGE}});
    }


Adapt this code to your case.
(assuming that a username is same as a person.entity_id)

This sets the background image for the card as entity picture. I am not much into YAML and ginger to handle this :frowning:

THis was merely an example of jinja which you can use.
Kind of this (untested):

picture: >-
  {% set PERSON = 'person.' + user -%}
  {%- set IMAGE = state_attr(PERSON,'entity_picture') %}
2 Likes

Another option is to use the Deafult action of Browser Mod and send each user to different hidden sub views of the Dashboard. Then you don’t need to template but rather can create specific user views. While this may mean some near duplicate cards etc, it allows for them to be fully standard and you don’t need to do fiddle with any mods etc.

Example Default action

action: browser_mod.navigate
data:
  path: /my-dashboard/use1-view

Or use one standard Default action and put everything in a script. See Super charge Browser defaults with Default action · thomasloven/hass-browser_mod Wiki · GitHub

Tested and it works well!

type: custom:mushroom-template-card
primary: Hello, {{user}}
secondary: How are you?
picture: |
  {% set PERSON = 'person.' + user -%}
  {{state_attr(PERSON,'entity_picture')}}
   
1 Like

Thanks much, this worked and met the requirements