Problem with an Automation sending Pictures via TG

Hi @ all…

I have a problem with an Automation…

Target: I just want the Automation to take 3 snapshots when the entry door changes its state from closed to open and send this snapshots via TG (Telegram Bot) to my cellphone…

Taking the pictures works perfect, but it can’t be send because the pictures will be created with a timestamp like HH:MM:SS

When i take a look to the Automation processes the part i want to send the snapshots via telegram has a time different of 3-4 seconds…
How can i fix it?
This is my Automation in Yaml:

alias: TG_Send_Picture
description: >-
  If entry door is opened take 3 snapshots and send them via TG
trigger:
  - type: opened
    platform: device
    device_id: dc59[...]935a9
    entity_id: binary_sensor.entry_door_contact
    domain: binary_sensor
condition: []
action:
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/media/camera/snapshots/snap_gr_floor_{{
        now().strftime("%Y.%m.%d_%H:%M:%S") }}.jpg
    target:
      entity_id: camera.gr_flur_hd_stream
  - service: telegram_bot.send_photo
    data:
      target: *censored*
      file: >-
        /config/www/media/camera/snapshots/snap_gr_floor_{{
        now().strftime("%Y.%m.%d_%H:%M:%S") }}.jpg
      caption: Urgent Security Message
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 50
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/media/camera/snapshots/snap_gr_floor_{{
        now().strftime("%Y.%m.%d_%H:%M:%S") }}.jpg
    target:
      entity_id: camera.gr_flur_hd_stream
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 50
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/media/camera/snapshots/snap_gr_floor_{{
        now().strftime("%Y.%m.%d_%H:%M:%S") }}.jpg
    target:
      entity_id: camera.gr_flur_hd_stream
  - service: telegram_bot.send_photo
    data:
      target: *censored*
      file: >-
        /config/www/media/camera/snapshots/snap_gr_floor_{{
        now().strftime("%Y.%m.%d_%H:%M:%S") }}.jpg
      caption: Urgent Security Message
    enabled: true
mode: single

I hope someone has an Idea to solve it…

Kind Regards…

Currently i try an other way to finalize the target…

Now i use a input_datetime.helper

this helper stores the date + time into some attributes:
timestamp, year, month, day, hour, minute & second…

i Play a little with the templates
This code:

{{ state_attr( 'input_datetime.helper_cam_gr_flur_1', 'year') }}.{{ '%d'|format(state_attr( 'input_datetime.helper_cam_gr_flur_1', 'month')) }}.{{ state_attr( 'input_datetime.helper_cam_gr_flur_1', 'day') }}_{{ state_attr( 'input_datetime.helper_cam_gr_flur_1', 'hour') }}:{{ state_attr( 'input_datetime.helper_cam_gr_flur_1', 'minute') }}:{{ state_attr( 'input_datetime.helper_cam_gr_flur_1', 'second') }}

give me the date & time who is set into the helper. But the leading Zero in case of 1 digit entrys is missing…
i want this: 2023.3.26_9:3:5
into this: 2023.03.26_09:03:05

How can i get it there?

in the code (currently only the month) i try to format it… But i don’t know how to add the leading zero…