What template to use both mdi:icon and entity_picture: svg

hi,
how could i use an mdi icon and an entity_picture in a template for an entity. The reason is the icon I need for the ‘else’ situation isnt an mdi icon, but was made for me today on the Mdi GitHub.

would need something like:

  templates:
    icon: >
      if (state === 'on') return 'mdi:ghost';
      return 'local/svg/ghost-off.svg';

or

“{% if state == ‘on’ %}mdi:ghost
{% else %}/local/svg/ghost-off.svg
{% endif %}”

not sure what template this should be… tried it before in another setting but wasnt successful , please have a look if this could be.

I think you will need to use a template sensor for this if you go here there is an example of exactly what you are trying to do.

sure, i use the template sensors, as posted btw, but cant find a way to use both icon and entity_picture in one template.

Have a look at my package called presence you find an example where I change my home status between icons and pictures.

1 Like

thanks! and of course, things couldn’t have been simpler… just never crossed my mind to use both icon_ and entity_picture_template for the same sensor… that is, this is what you where referring to isnt it?

  tina:
    friendly_name: "Tina Occupancy"
    value_template: >-
      {% if is_state('input_boolean.tina_home', 'on') %}
        Home
      {% elif is_state('device_tracker.admin_iphone', 'Kindy') %}
        Kindy
      {% elif is_state('device_tracker.admin_iphone', 'Stocklands') %}
        Stocklands
      {% elif is_state('device_tracker.admin_iphone', 'Parlour') %}
        Parlour
	      {% elif is_state('device_tracker.admin_samsung', 'UK') %}
        UK
      {% else %}
        Away
      {% endif %}
    entity_picture_template: >-
      {% if is_state('input_boolean.tina_home', 'on') %}
        /local/tina.jpg
      {% endif %}
    icon_template: >-
      {% if is_state('device_tracker.admin_iphone', 'Kindy') %}
        mdi:school
      {% elif is_state('device_tracker.admin_iphone', 'Stocklands') %}
        mdi:cart
      {% elif is_state('device_tracker.admin_iphone', 'Parlour') %}
        mdi:coffee
      {% elif is_state('device_tracker.admin_samsung', 'UK') %}
        mdi:earth
      {% else %}
        mdi:walk
      {% endif %}

yeah that’s the one sorry I wasn’t near my pc to show example.

1 Like

I just noticed there is a spacing error in that

{% elif is_state('device_tracker.admin_iphone', 'Parlour') %}
    Parlour
      {% elif is_state('device_tracker.admin_samsung', 'UK') %}
    UK
  {% else %}
    Away
  {% endif %}

the last elif should be inline with the rest

are these mutually exclusive?

 entity_picture_template: >-
      {% if is_state('input_boolean.tina_home', 'on') %}
        /local/tina.jpg
      {% endif %}
    icon_template: >-
      {% if is_state('device_tracker.admin_iphone', 'Kindy') %}
        mdi:school
      {% elif is_state('device_tracker.admin_iphone', 'Stocklands') %}
        mdi:cart
      {% elif is_state('device_tracker.admin_iphone', 'Parlour') %}
        mdi:coffee
      {% elif is_state('device_tracker.admin_samsung', 'UK') %}
        mdi:earth
      {% else %}
        mdi:walk
      {% endif %}

When tina is home, cant the admin be at the other places? (or is Tina the admin…) just asking…

I’m haven’t completely setup Tina Presence if you look at James Presence it uses input from a few presence trackers I take precedence from top down if the bluetooth trackers see any of our phone they trigger the first option of the input_boolean, if we at either of the other places we use own tracks to update and the icon/picture reacts to state changes of those. So no technically we can’t be in 2 places at once :slight_smile:

With Tina Presence I copied some variables from James Presence so there is a mix of my device trackers and hers just need to finish adding her bluetooth tracking details to the trackers I use own tracks exclusively for hers atm until I get a chance to grab her phone and set it up properly.