Need help solving a simple IF statement, please help i'm stupid

Hi, I’m trying to create a conditional card on my dashboard for a trash calendar.
I created a sensor template to help me compare dates:

- platform: template
  sensors:
    sorting_date_tomorrow:
        friendly_name: "Datum voor sortering morgen"
        value_template: >
          {{ (as_timestamp(states('sensor.date_time_iso')) | timestamp_custom('%Y%m%d') | float(0) + 1) | round(0) }}
        icon_template: mdi:calendar-clock

If i check in the template editor:

{{ states('sensor.sorting_date_tomorrow')}}

the result is: 20230206
So far, great.

I want to compare this to a garbage collector sorting date:

{{ state_attr('sensor.rova_gft', 'Sort_date')}}

this result is: 20230206
What I expected.

but if i compare this in a simple If statement:

{{ is_state('sensor.sorting_date_tomorrow', state_attr("sensor.rova_gft", "Sort_date")) }}

it returns: False.

I’m sure i’m doing something wrong, but for the life of me don’t understand why this isn’t True.
Loving the Home Assistant stuff so far, i’m new to all of this. I hope someone can help me understand.

Maybe the output is a number in 1 case and a string in another?
What does

{{states('sensor.sorting_date_tomorrow') | int(0) == state_attr("sensor.rova_gft", "Sort_date") | int(0)}}

Give out?

Probably because the types are different. Sensor states are always strings even if they look like numbers. Attributes retain their type.

Try:

{{ is_state('sensor.sorting_date_tomorrow', state_attr("sensor.rova_gft", "Sort_date") | string) }}

You also simplify the conversions. This is maybe a bit cleaner.

{{ (now() + timedelta(days=1)) | as_timestamp | timestamp_custom('%Y%m%d') }}

Your answer is correct but your code does not work.
I also thought that sensor output was integer, it is not apparantly.
The correct answer is below. Thank you for your answer.

Thank you! This works. I thought sensor states output integers. It does not. Thank you for your answer.

1 Like