Timestamp for specific status

I am trying to show when a sensor last was in a specific status. More specifically, I want to show when my each of my doors were last in status “open”. I have been using this template to see when the status last changed:

value_template: '{{ as_timestamp(states.sensor.main_door.last_changed) | timestamp_custom("%a %d %b %H:%M") }}'

This works in a way, but the problem with this one is that when I restart HA, the state will be changed even if the door is not opened. I would rather have a status saying “unknown” or “N/A” if the door has not been opened since HA restart.

What I am looking for is a timestamp for a specific status, but I am unable to find this in any examples.

2 Likes