Attribute to specify "Today" "Tomorrow" "x Days"

I am using Mushroom Template Card to give me a nice look for for the Garbage Collection Integration, and would like the count for days to show as “Today” “Tomorrow” or “x Days”.

Collection day is today and currently, my sensor reads “0 days”

secondary: ‘{{ state_attr(’‘sensor.recycling_bins’’,’‘days’’) }} day(s)’

Any help would be appreciated.

Thanks

secondary: >
  {% set days = state_attr('sensor.recycling_bins','days') %}
  {% if days == 0 %}
    Today
  {% elif days == 1 %}
    Tomorrow
  {% else %}
    {{ days }} days
  {% endif %}

@tom_l Appreciate your help, but unfortunately not working. More than likely my mistake, if you could push me in the right direction.

Does the mushroom card support multi-line templates?

I don’t know. I’ve never used it.

It does have a multiline secondary field but it isn’t working.

Might have to build it myself with the help of Google.

Thanks again @tom_l

Just create a template sensor of the yaml Tom posted.

Adding in == made it work :smiley:

Thanks both for your help here.

{% set days = state_attr('sensor.recycling_bins','days') %}
{% if days == 0 %}
  Today
{% elif days == 1 %}
  Tomorrow
{% else %}
  {{ days }} days
{% endif %}

For future reference, here are two other ways of producing the same result:

{% set days = state_attr('sensor.recycling_bins','days') %}
{{ 'Today' if days == 0 else 'Tomorrow' if days == 1 else days ~ ' days'}}
{% set days = state_attr('sensor.recycling_bins','days') %}
{{ {0: 'Today', 1: 'Tomorrow'}.get(days, days ~ ' days') }}
4 Likes

Apologies that was the last thing I did before bed. Obviously not quite awake. I have corrected the original post in case any one else copies it.

1 Like

It was a big help, and I just did a bit of Googling after. I have since used it again for a different sensor :smiley:

Thanks, mate

1 Like

I was wondering if anyone had suggestions in doing the opposite. My sensor reports the state as x days already however, when it is today or tomorrow it actually reports today or tomorrow. Which doesn’t work for auto-entities filter by date.

What would be the best way to make a template that turns the today into 0 days and the tomorrow into 1 day?

{% set days = states('sensor.xyz') %}
{{ {'Today': 0, 'Tomorrow': 1}.get(days, days) }}
1 Like

thanks for the reply @petro . What would the output be for when it is saying say 3 days?

It should just be 3, but I’m guessing what your sensor outputs because you said

The assumption is that the sensor is unitless and just outputs a number, but Today and Tomorrow are output when it should be 0 or 1.

1 Like

Great, I wasn’t sure if it would still pass on the normal value, however, looks like it is working as intended so far :slight_smile: thanks