Template strange value when attribute is gone

OK I hope someone can help me with this strange issue

I’ve got a sensor with a template which retuns a date:

template:
  - sensor:
      - name: "test"
        state: "{{ state_attr('cover.shutter','cmd_fired')|int(0) | timestamp_custom('%d-%m-%y') }}"

the result is as expected: “27-11-23”

But when I restart HA the attribute (cmd_fired) disappears from the shutter and sensor.test gives me a value like “01-01-70”

Where does 01-01-70 comes from?
When this happens I want to have a message like “unknown” or something but not this. Very confusing.

I’ve tested with this but gives me “True” AND “Unknown”
I would expect:

  • when the attribute is present: show the date
  • when the attribute is gone: show “unknown”
template:
  - sensor:
      - name: "test1"
        state: >-
          {% if states.cover.shutter %}
            {{ state_attr('cover.shutter', 'cmd_fired') is none }}
            Unknown
          {% else %}
            {{ state_attr('cover.shutter','cmd_fired')|int(0) | timestamp_custom('%d-%m-%y') }}
          {% endif %}

It comes from your default on the int… using 0 will cause it to return the starting point of Unix time if the attribute’s original value isn’t a number or numeric string.

template:
  - sensor:
      - name: "test1"
        state: >-
          {% set fired = state_attr('cover.shutter', 'cmd_fired') %}
          {% if not fired | is_number %}
            Unknown
          {% else %}
            {{ fired | int | timestamp_custom('%d-%m-%y') }}
          {% endif %}

thanks it works!