Hi, title may be confusing. Very sorry for that. Let me to explain what I want to solve.
I am working on, taking camera snapshot and sending snapshot photo file to notify on mobile/telegram with message. It is working well after going thru many other post on this forum, Thanks to all for this.
I have 3 automations on 3 contact sensors. And having only one script. Automation sends message and camera-entity-id to the script. Script take snapshot on camera id that automation has sent and notify to mobile app/telegram with the snapshot and message received from automation.
Now, issue is new snapshot file overwrites previous snapshot file.
I am looking to generate file name in automation, e.g., backyard_2019_11_06_20_07_57_088904.jpg in automation and pass it to script like currently passing camera entity id and message.
I know in python, this can be achieved by datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S_%f"). But I don’t know how to write in automation yaml file.
Snapshot is copied as \myhost\config\www\frontdoor_2019_11_06_22_00_01_237712.jpg
Automation is
alias: Send photo when front door is opened.
trigger:
- platform: state
entity_id: binary_sensor.wyzesense_contact_sensor_in_front_door
from : 'off'
to : 'on'
condition:
action:
- service : script.notify_whole_family_with_photo
data_template :
i_camera_entity_id : camera.wyze_camera_02
i_message_string : 'Front door is opened by someone.'
i_file_name : "frontdoor_{{now().strftime('%Y_%m_%d_%H_%M_%S_%f')}}.jpg"
And script is
notify_whole_family_with_photo:
alias: "Notify whole family on ios and telegram with photo"
sequence:
- service: camera.snapshot
data_template:
entity_id: '{{i_camera_entity_id}}'
filename : /config/www/{{i_file_name}}
- delay : 00:00:05
- service: notify.whole_family
data_template:
message : '{{i_message_string}}'
data :
attachment:
url : https://mydomain.duckdns.org:8123/local/{{i_file_name}}
- service: notify.telegram_person
data_template:
message : '{{i_message_string}}'
data :
photo :
- url: 'https://mydomain.duckdns.org:8123/local/{{i_file_name}}'
caption: '{{i_message_string}}'