#Templating - Mushroom Entity Card - Jinja

1 messages · Page 1 of 1 (latest)

spring mango
#

Stuggling a bit with something that seems simple.

I want my entity card to change "icon color" based on the state of the entity. Using "Developer tools" I have confirmed that the entity is lock.back_door_lock and has two states: locked and unlocked.

what am I doing wrong?

type: custom:mushroom-entity-card
entity: lock.back_door_lock
primary_info: state
secondary_info: last-changed
tap_action:
  action: toggle
hold_action:
  action: more-info
icon_color: |
  {% if is_state('lock.back_door_lock', 'locked') %}
    green 
  {% else %}
    red
  {% endif %}

the icon is showing no color as if it is disabled. I believe this is possible based on posts here:
https://github.com/piitaya/lovelace-mushroom/issues/335

GitHub

It’s great that we can set the default color of the icons, but I would like to be able to set the color depending on state. A door lock will remain gray until toggled to lock in which case tot adop...

final tusk
#

Try {{ iif(is_state(entity,’locked’), ‘green’, ‘red’) }}

spring mango
#

icon_color: "{{ if(is_state('lock.front_door_lock', 'locked'), 'green', 'red') }}"

#

that exact line doesn't work, I tried with and without the double quotes at the beginning and end, and also without the single quotes on green and red

#

oh, iif wasn't a typo. one sec

#

icon_color: "{{ iif(is_state('lock.front_door_lock', 'locked'), 'green', 'red') }}" still no luck

#

but for reference it definitely is that element variable

final tusk
#

Huh, it may not take a template. I use template cards for this very reason.

spring mango
#

so just build the whole thing from a template card? I was avoiding that because I'm too dumb to figure it out

final tusk
#

They aren’t hard.

grave ore
spring mango
#

I'll give a template a shot. let's see

spring mango
#

I'm like 90%; only thing I can't get is the last updated time to show like it was on the lock card

#

I want the last updated time to show in relative terms

grave ore
#

time_since(blah blah.last_changed, 1)

spring mango
#

like that? took it off

grave ore
#

you might have to cast the last_changed to datetime first

#

you'll also need to add the "ago" in

spring mango
#

{{ time_since(states.lock.garage_door_lock.last_changed) }} fixed it

#

oh, you're right, I do 🙂

#

perfect. thank you two so much!

#

that took a lot of effort. lol. but we got it. whew

grave ore
#

but now it's done and you can leave it alone forever!

#

and definitely not fiddle with it incessently for months

spring mango
#

lmao 🙂 exaaactly

final tusk
#

So, one trick with the template card is that you can use entity for any calls if you have the entity defined at the top of the card.

#

So, for time since, you can just do {{ time_since(states[entity].last_changed) }} ago to get what you want as well.

grave ore
#

that's neat, i didn't know that

final tusk
#

It’s a real time saver.

#

Also applies to the mushroom template badges too.