Person entity_picture based on state

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:

Hi ALl,

I have this part in Lovelace, only problem is its a tracking device.
When I’m at home there state will be home. When im away it will show different states.

How can add something that when its not home then show this image… (The part not_home)

- entity: device_tracker.cenkay_xr
  show_state: false
  show_name: true
  name: iCloud3
  tap_action:
    action: toggle
  state_image:
    not_home: /local/images/person/kay_away.png
    home: /local/images/person/kay_home.png

Cheers,
Peter

Being that I’m trying very hard to learn this… Is this what I want to show a picture instead of my name? Currently it shows John - Home or John - Away… I’d like to use pictures instead.

AND not really sure where to put the above is this is the code I need.

Thank you ALL in advance!!

no, its not, this mod is about styling the various parts of the badge.

if you want to use picture thats totally possible of course, in various ways. Here’s what I do:

homeassistant:

  customize:

    person.marijn: &picture
      templates:
        entity_picture: >
          var id = entity.entity_id.split('.')[1].split('_')[0];
          var sensor = 'sensor.' + id + '_picture';
          if (entities[sensor]) return entities[sensor].state;
          return '/local/family/' + id + '_not_home.png';

and use the anchors on all other person entities

and that uses custom-ui (to be able to use templates)

the sensor.*_picture is somewhat complex in my setup,

template:

  - sensor:

      - unique_id: marijn_picture
        state: >-
          {% set id = 'marijn' %}
          {% set state = states('device_tracker.' ~ id ~ '_app') %}
          {% set activity = states('sensor.' ~ id ~ '_app_activity') %}
          {% set zones = states.zone|map(attribute='name')|list %}
          {% if state in zones %} /local/family/{{id}}_zoning.png
          {% elif activity in ['Automotive','Cycling','Walking']
                  and state != 'home'%} /local/family/{{id}}_not_home.png
          {% else %} /local/family/{{id}}_{{state|slugify}}.png
          {% endif %}

but you get the idea.

a simpler variant would be:

        entity_picture: >
          var id = entity.entity_id.split('.')[1];
          return '/local/family/' + id + '_' + state + '.png';

1 Like

Got it!! Thank you!!! I’ll give it a whack, time to start learning stuff or I’ll never get this to where I want it :slight_smile:

I do some like this:

media_player.android_tv:
  templates:
      entity_picture: >
        {% set app = states.media_player.android_tv.attributes.app_id %}
        /local/img/googletvicons/{{app}}.png

but it don’t work…
I check in developer-tools/template:
{{ states.media_player.android_tv.attributes.entity_picture }}
“UndefinedError: ‘homeassistant.util.read_only_dict.ReadOnlyDict object’ has no attribute ‘entity_picture’”

wrong topic? (this is about person pictures)

and if you got the wrong attribute, you should check the tab next to that, dev tools/states and see in the attributes column which attributes Are available

I use this template…

If there isn’t attribute how can I add new one? It’s Android TV integration.

You can not add an attribute, the integration sets attributes. (Unless you want to customize those )

This topic is about person entities and you ask about media_player entities which are different integrations alltogether.

If you check like I suggested, in dev tools states, you can see which attributes the entity has. En adapt any template to those.