Template sensor state retention

I have created several template sensors to manage the messages from my smoke detector bridge (based on GitHub - C19HOP/WiSafe2-to-HomeAssistant-Bridge: Connect FireAngel WiSafe2 alarm networks to HomeAssistant).
The smoke detectors only send a status update if there’s a change, so I need HA to remember the previous state after a restart (that’s why I’m using trigger-based binary_sensor).

I’m using a connectivity sensor to check for the heartbeat of the bridge (every 25s).
If this connectivity sensor is offline, then all my other sensors become ‘unavailable’ (using the availability template).
If the connectivity sensor comes online again (e.g. after a restart of HA), I want the other sensors to go back to their previous state, but currently they all go to the ‘off’ state.
How can I solve this?

Here’s my template configuration (fireangel_data is the serial sensor coming from the bridge):

sensor:
  # FireAngel Gateway
  - platform: serial
    name: "FireAngel Data"
    serial_port: /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0
    baudrate: 115200

template:
  - binary_sensor:
      - name: "FireAngel Gateway Connectiviteit"
        unique_id: fireangel_heartbeat
        device_class: connectivity
        state: >
          {% if states('sensor.fireangel_data') !='unknown' and (now() - states.sensor.fireangel_data.last_changed).total_seconds() < 125 %}
            on
          {% else %}
            off
          {% endif %}
  
  - trigger:
      - platform: state
        entity_id: sensor.fireangel_data
      - platform: state
        entity_id: binary_sensor.fireangel_gateway_connectiviteit
    binary_sensor:
      - name: "FireAngel Radio"
        unique_id: fireangel_radio
        device_class: connectivity
        availability: "{{ states('binary_sensor.fireangel_gateway_connectiviteit') == 'on' }}"
        state: >
          {% if 'INIT OK' in states('sensor.fireangel_data') %}
            on
          {% elif 'Radio not ready - Trying to reset' in states('sensor.fireangel_data') or states('sensor.fireangel_data') == 'Initializing radio' %}
            off
          {% else %}
            {{this.state}}
          {% endif %}
      #------------------------------------
      #587813 | WHT-630-NEU | Heat | Keuken
      #------------------------------------
      - name: "FireAngel Hittemelder Keuken Connectiviteit"
        unique_id: fireangel_keuken_connectivity
        device_class: connectivity
        availability: "{{ states('binary_sensor.fireangel_gateway_connectiviteit') == 'on' and states('binary_sensor.fireangel_radio') != 'off' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='587813' %}
            {% if state_attr('sensor.fireangel_data', 'event')=='MISSING' %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}