Template for timestamp when on and off

Hi,

I have a mailbox where i want to monitor both when mail gets delivered and pickup by a family member.

The mailbox will send 1 on mqtt when mail is delivered and 0 when emptied.

I need some help figuring out a template which can differentiate this.

This is what i currently have and it does correctly write the date when it changes to on.

But what im really looking for is two items, one describing each event, and this only updates when the entitiy updates, which means i still need the pickup of items.

- platform: template
  sensors:
    postkasse_hentet:
       friendly_name: 'Post hentet'
       value_template: '{{ as_timestamp(states.binary_sensor.postkasse.last_updated) | timestamp_custom("%a %H:%M", True) }}'

My question is therefore, how can i make a sensor which writes a timestamp for a specific state event?