Unifi G4 Doorbell Pro person detected snapshot via Telegram

Hello, I am having issues with this automation. Now it is not working at all. But usually, the snapshot is from long time before the automation get triggered, and/or it doesn’t get sent.

I also tried with giving the filename a standard name without variables, still the same. What I am doing wrong?

alias: "Telegram: Frontdoor person detected"
description: ""
trigger:
  - type: turned_on
    platform: device
    device_id: 347fc630b5ff31a1e35b775f1ff0ae80
    entity_id: binary_sensor.g4_doorbell_pro_person_detected
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/cam_snaps/{{ trigger.to_state.last_changed | as_timestamp | 
        timestamp_custom("%Y-%m-%d_%H-%M-%S") }}-frontdoor.jpg
    target:
      entity_id: camera.g4_doorbell_pro_high
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: telegram_bot.send_photo
    data:
      file: >-
        /config/www/cam_snaps/{{ trigger.to_state.last_changed |              
        as_timestamp | timestamp_custom("%Y-%m-%d_%H-%M-%S") }}-frontdoor.jpg
      caption: You got visitors {{ now().strftime('%H:%M:%S') }}
mode: single