Need to get notification if one of MQTT devices is offline for some time

I got stuck trying to get the following automation to work. It’s supposed to send me a notification if one of the binary sensors changes state for more than 5 seconds. I don’t want to receive the notification if the state changes for only a few seconds then reverts. If I remove the 5-second condition, it works fine, just send the notification with every change regardless if it changed for half a second.

- id: Phone Online Status
  alias: phone_online_status
  trigger:
    - platform: state
      entity_id: 
        - binary_sensor.zanzito_phone1_status
        - binary_sensor.zanzito_phone2_status
        - binary_sensor.zanzito_phone3_status
        - binary_sensor.zanzito_phone4_status
  condition:
    - condition: template
      value_template: '{{ (as_timestamp(now())-as_timestamp(trigger.to_state.last_updated)) | int > 5 }}'
  action:
    - service: notify.ep
      data_template:
        message: "{{ trigger.to_state.name }} status changed from {{ trigger.from_state.state }} to {{ trigger.to_state.state }} at {{ states('sensor.date__time') }}"

I’m guessing the problem is with “(trigger.to_state.last_updated)”, but I haven’t played around much with reusing the triggers inside conditions and actions.

BTW, here are the MQTT binary sensors where above data is coming from:

- platform: mqtt
  name: "Phone1 Zanzito status"
  state_topic: "zanzito/phone1/status"
  payload_on: "1"
  payload_off: "0"
  payload_available: "Online"
  payload_not_available: "Offline"
  sensor_class: connectivity
  
- platform: mqtt
  name: "Phone2 Zanzito status"
  state_topic: "zanzito/phone2/status"
  payload_on: "1"
  payload_off: "0"
  sensor_class: connectivity
  
- platform: mqtt
  name: "Phone3 Zanzito status"
  state_topic: "zanzito/phone3/status"
  payload_on: "1"
  payload_off: "0"
  sensor_class: connectivity
  
- platform: mqtt
  name: "Phone4 Zanzito status"
  state_topic: "zanzito/phone4/status"
  payload_on: "1"
  payload_off: "0"
  sensor_class: connectivity