Person entity_picture based on state

There’s about 800 ways to do this, just not through customize. They really just need to add it at this point.

Anyways, where are you trying to place your person in Lovelace?

In Overview , configure UI , Map Card Configuration, Show code editor.

I’ve tried adding the logic there as follows but it does not work.

default_zoom: 15
entities:
  - entity: zone.name1_work
  - entity: zone.home
  - entity: zone.name2_work
  - entity: person.name1
    entity_picture: '/local/img/name1_home.png'
    state_image:
      home: '/local/img/name1_home.png'
      not_home: '/local/img/name1_not_home.png'
  - entity: person.name2
type: map

I’ve tried adding that code to the Configuration , Customization, Entity person1
entity_picture (JSON formatted) text field. I’m not sure if I have the right syntax there…
I tried

{% if is_state(config.entity, 'home' %}  '/local/img/name1_home.png' {% else %} '/local/img/name1_not_home.png' {% endif %};

Do I need to change the config.entity to person1? or even get ride of the brakets or ending semi colon?

Hope you can point me and others in the right direction.

If you want it everywhere, you unfortunately have to jump through hoops. And I’m pretty sure it won’t change the image of the user on the sidebar, which i’m assuming you’re referring to as ‘overview’. You have 1 of 2 options:

  1. Create a template sensor with a picture_template. Place that in all the areas that you want a changing picture. You’d also need to add latitude and longitude attributes as the map card requires that.

  2. Use CustomUI. This requires you to install CustomUI and configure it to work. You’d also need to configure your ui items as well.

I haven’t used CustomUI in 3 years so I can’t really help you with that. I can help you set up a sensor that behaves the way you want though.

As a side note, You have to consult the documents when using cards. Not all cards have the same options. For example, you are trying to use entity options from the entities card inside the map card. The map card simply does not support any of that.

1 Like

the answer is up a few posts, both for a separate template sensor, and for setting the person entity in custom_ui… Person entity_picture based on state - #7 by Mariusthvdb

did you give it a try?

Ok, thanks to @Mariusthvdb I figured it out!

Will split the code into files later when initial HA config is done, but for now it is in configuration.yaml

Customize person entity

homeassistant:
  customize:
    person.roel:
      templates:
        entity_picture: >-
          return entities['sensor.roel_picture'].attributes.entity_picture;

Set the sensor:

sensor:
  - platform: template
    sensors:
      roel_picture:
        value_template: >
          {{states('person.roel')}}
        entity_picture_template: >
          /local/img/roel_{{states('person.roel')}}.png

Install CustomUI and activate it , DO NOT FORGET TO ACTIVATE IT!(you are a lifesaver @Mariusthvdb :joy:)

customizer: 
  custom_ui: local

So big shout out to @Mariusthvdb, and also thx @petro for the suggestions and feedback, much appreciated!

Does this trick work as well to dynamically change the picture of a Picture Element Card?
That way you would be able to change background pictures with for example an input_select.

hi im having trouble with custom ui could you help me?

i installed it in custom components
added this to configuration.yaml:

customizer:
  custom_ui: local

rebooted and no errors so i guess it is installed?

but now i want to add my custom template

  sensor.database_state:
     templates:
        unit_of_measurement: ${entities['sensor.database_state'].state}

but i dont now where to instal it and how?

you can always check on developer-tools/info, see below, at the bottom of the image

customizations go below:

homeassistent:
  customize:
    sensor.database_state:
      templates:
        unit_of_measurement: ${entities['sensor.database_state'].state}

have a look here home-assistant-custom-ui/docs/templates.md at 5274c9b1e51d8a4ba409cbf510d286472d42c328 · andrey-git/home-assistant-custom-ui · GitHub but be ware that many of these are no longer functional, because they were for States ui, and we now use Lovelace.

not sure about the sensor you use, I dont have that. If you have trouble, please post the sensor config.

1 Like

thank you for the response!!
i have this in develop tools:
image

and

is this ok?

the sensor i made is a tempalte sensor

nope, you’re missing the custom-ui section I showed you. You have to check carefully how to install and activate custom-ui.

please show the template sensor in yaml

sensor:
  - platform: template
    sensors:
        database_state:
            friendly_name: Database
            value_template: >
                {{ state_attr('sensor.db_record', 'count') }}
            #unit_of_measurement: 'none'
            entity_picture_template: >
                {% if is_state('device_tracker.oneplus', 'home') %} /local/images/entities/oneplus.jpg
                {% elif is_state('device_tracker.oneplus', 'away') %} /local/images/entities/oneplus_grey.png
                {% endif %}

Ok i think i maanged it
image

i pasted your given code
rebooted and just it worked MANY THANKS
image

Because this is something that a lot of users search ui will make a manual

For the ones who want a complete guide

just so you know there is also a ‘modern way’ of changing badges, which brings us back to the original topic:

badges:
  - entity: person.marijn
    style:
      ha-state-label-badge:
        $:
          ha-label-badge:
            $: |
              .label-badge .label span{
                {% if is_state('person.marijn','home') %} color: red;
                {% else %} color: black;
                {% endif %}
              }
        .: |
          :host {
            {% if is_state('person.marijn','home') %} --label-badge-red: green;
            {% else %} --label-badge-red: grey;
            {% endif %}
          }

and many more options using card_mod. Not always as easy and straightforward I must admit, but card_mod is heavily updated and maintained (custom-ui is abandoned and not supported unfortunately. We just happen to be lucky some customizations still work…)

1 Like

i will trie this out when im home

Hi all, I hope this is the right place for this question.
I’m trying to achieve something similar on a background for a view, where the bg image changes depending on a room’s global state (all light off / any light on).
Anyone knows if this is possible?

Search hacs for animated background
I made such thing based on the time (evening/Day) and the weather

If you need help you can pm me

wow awesome! I’ll try it today, thanks!

Worked instantly like a charm! Left those beautiful videos on my home and used my own pics for every room (each in one view), based on the state of the room. What a wonderful weekend, Huge thanks!

no problemo :slight_smile: