When my door opens an automation fires which calls a shell command to get the current picture from my front door camera and sends the pictures with telegram to my phone.
Sometimes it happens that the shell command takes longer and I receive pictures from the last time the door was opened.
Is there a simple solution to wait till the shell command is done and only after that continue the automation?
I know that there is wait_template, but I wouldn´t know how to use it for this purpose.
I don’t want to use a simple delay because I don’t know how long the shell command will take.
This is my automation:
- alias: notify_1_dafang_1_send_picture_door_open
initial_state: true
hide_entity: false
trigger:
- platform: state
entity_id: sensor.front_door_node_1_front_door_status
from: 'closed'
to: 'open'
action:
- service: shell_command.dafang_1_get_snapshot_door_open
- delay: '00:00:00'
- service: notify.notify_1
data_template:
message: Front Door Snapshot 1 - 5 from Door open
data:
photo:
- file: '/config/www/dafang_1/dafang_1_snapshot_door_open_1.jpg'
caption: "
*Open* Front Door Snapshot 1
{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
- file: '/config/www/dafang_1/dafang_1_snapshot_door_open_2.jpg'
caption: "
*Open* Front Door Snapshot 2
{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
- file: '/config/www/dafang_1/dafang_1_snapshot_door_open_3.jpg'
caption: "
*Open* Front Door Snapshot 3
{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
- file: '/config/www/dafang_1/dafang_1_snapshot_door_open_4.jpg'
caption: "
*Open* Front Door Snapshot 4
{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
- file: '/config/www/dafang_1/dafang_1_snapshot_door_open_5.jpg'
caption: "
*Open* Front Door Snapshot 5
{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
- delay: '00:00:02'
- service: notify.notify_1
data_template:
message: Get current snapshot?
data:
inline_keyboard:
- 'Get 1 current snapshot or get:/dafang_1_get_1_snapshot'
- ' 2:/dafang_1_get_2_snapshots, 3:/dafang_1_get_3_snapshots, 4:/dafang_1_get_4_snapshots, 5:/dafang_1_get_5_snapshots'
- 'Home:/home'
Shell command:
dafang_1_get_snapshot_door_open: 'bash /config/sh_bash_commands/dafang_1_get_snapshot_door_open.sh'
This is my bash script:
#!/bin/bash
curl --insecure https://root:[email protected]/cgi-bin/currentpic.cgi --output /config/www/dafang_1/dafang_1_snapshot_door_open_1.jpg
cp /config/www/dafang_1/dafang_1_snapshot_door_open_1.jpg /config/www/dafang_1/saved/`date '+%Y-%m-%d_%H.%M.%S'`_dafang_1.jpg
curl --insecure https://root:[email protected]/cgi-bin/currentpic.cgi --output /config/www/dafang_1/dafang_1_snapshot_door_open_2.jpg
cp /config/www/dafang_1/dafang_1_snapshot_door_open_2.jpg /config/www/dafang_1/saved/`date '+%Y-%m-%d_%H.%M.%S'`_dafang_1.jpg
curl --insecure https://root:[email protected]/cgi-bin/currentpic.cgi --output /config/www/dafang_1/dafang_1_snapshot_door_open_3.jpg
cp /config/www/dafang_1/dafang_1_snapshot_door_open_3.jpg /config/www/dafang_1/saved/`date '+%Y-%m-%d_%H.%M.%S'`_dafang_1.jpg
sleep 4
curl --insecure https://root:[email protected]/cgi-bin/currentpic.cgi --output /config/www/dafang_1/dafang_1_snapshot_door_open_4.jpg
cp /config/www/dafang_1/dafang_1_snapshot_door_open_4.jpg /config/www/dafang_1/saved/`date '+%Y-%m-%d_%H.%M.%S'`_dafang_1.jpg
curl --insecure https://root:[email protected]/cgi-bin/currentpic.cgi --output /config/www/dafang_1/dafang_1_snapshot_door_open_5.jpg
cp /config/www/dafang_1/dafang_1_snapshot_door_open_5.jpg /config/www/dafang_1/saved/`date '+%Y-%m-%d_%H.%M.%S'`_dafang_1.jpg