If and else works, but not elif?

Hi, I’m trying to make some person cards on my dashboard.
The point is to change the badge icon and color, as well as the text, depending on if the person is home or not. For some reason the elif statements don’t work. Only the if and else statements. Any idea what’s wrong?

              - type: custom:mushroom-template-card
                entity: person.Mrs
                layout: horizontal
                primary: Mrs
                tap_action:
                  action: more-info
                hold_action:
                  action: more-info
                double_tap_action:
                  action: none
                badge_icon: |
                  {% if is_state(config.entity, 'home') %}
                    mdi:home
                  {% elif is_state(config.entity, 'away') or
                  is_state(config.entity, 'unavailable') %}
                    mdi:home-export-outline
                  {% endif %}
                badge_color: |
                  {% if is_state(config.entity, 'home') %}
                    green
                  {% else %}
                    red
                  {% endif %}
                picture: |
                  {{ state_attr(config.entity, 'entity_picture') }}
                multiline_secondary: true
                secondary: >
                  {% if is_state(config.entity, 'home') %}
                    Home
                  {% elif is_state(config.entity, 'away') or
                  is_state(config.entity, 'unavailable') %}
                    Away
                  {% else %}
                    Is {{ states(config.entity) }}
                  {% endif %}

Have you tried without " or "
elif
elif
endif

beside in both case you could might as well use " else " … save you some code also :wink:

You are missing the ELSE statement. See an example below.

        {% if is_state('sensor.season', 'spring')  %}
          Spring
        {% elif is_state('sensor.season', 'summer') %}
          Summer
        {% elif is_state('sensor.season', 'autumn') %}
          Autumn
        {% else %}
          Winter
        {% endif %}
1 Like

you are looking for away which is indeed how the UI displays it, BUT if you look in the developer states page you will see that away is actually not_home

:grin: Bummer , i didn’t even noticed that :laughing:

1 Like

You learn that one pretty quick when troubleshooting why away is not doing what you expect in automations lol

I know, guess that why i just overlooked it , anyway as both unavailable “or” away to OP is away, he might aswell just, cut it short , as his last “else” Is {{ states(config.entity) }} is kind of redundant also … basically he just want to see ( Home, else Away ) unless he expects his person.Mrs to be Unknown :grin:

Yup it can be reduced to:

{{ 'mdi:home' if is_state(config.entity,'home') else 'mdi:home-export-outline' }}
1 Like

Thanks! You simultaneously illustrated the best thing about HA (the knowledgeable and helpful community), and one of the most annoying (the not always straight forward states).

1 Like

Well spotted

One other common point people get tripped up on is that not_home (or away in the UI) actually means “not in any defined zone” and therefore doesn’t actually mean “not home”.

E.g. if you are in a zone called work then your state will not be not_home / away