WTH - script doesn't wait for first action to complete before starting second action

I have a driveway sensor (https://dakotaalert.com/product/dcpa-4k-plus-50-probe-wire/) that triggers a z-wave dry contact that feeds into my home automation that then triggers a snapshot of the Dahua camera on my front door and texts me a photo of it through Telegram. I used to use Domoticz before switching to HASS and I’d have the z-wave sensor trigger an external script to do all of that (see script below). This worked great, every time. The issue while trying to get HASS to do the same thing is that about half the time it will send me the last photo that was taken, not the current photo. So if I leave for work at 7am and it correctly sends me a snapshot of my truck in the driveway at 7 am, then when I get home at 5pm it might send the photo from 7 am again. Then maybe I’ll go somewhere that night and when I leave it’ll send the photo from 5 pm that it took.

The only thing I can guess is that when Domoticz triggered the script below to run, it would run as scripts do, executing one line after the next and not moving on until the previous line was done. With it set up in HASS, it seems like it doesn’t wait for the photo to save before sending it to Telegram.

#!/bin/bash

#This is a script that takes a snapshot of a camera and texts it to Telegram chat "House"

SnapFile="/var/tmp/camsnapshot.jpg"

# Get snapshot via Domoticz server

wget -O $SnapFile "http://uname:[email protected]/cgi-bin/snapshot.cgi? [channel=1]"

# Send Telegram message with image

curl -s -X POST "https://api.telegram.org/botXXX:XXXXX/sendPhoto" -F chat_id=XXX -F photo="@$SnapFile"

# Remove Image

/bin/rm $SnapFile

Below is the “script” that I set up in HASS that runs when my driveway sensor is triggered. Is there anything I can do to get this working correctly? I added up to 3 seconds of a delay in between taking the photo and sending it, but that still didn’t work every time. When executing the script above it doesn’t even take 4 seconds to run and I don’t want to unnecessarily add any extra time into it.

data:
  entity_id: camera.front_door_cam
  filename: /tmp/front_door_cam_snap.jpg
entity_id: camera.front_door_cam
service: camera.snapshot

data:
  data:
    photo:
      - caption: DRIVEWAY
        file: /tmp/front_door_cam_snap.jpg
  message: DRIVEWAY
  title: DRIVEWAY
service: notify.house

The problem is that if that is implemented then each light would have to light up before the next.

I know there was an exact the same WTH just a few days ago.

Not sure if your replied to the wrong thread or what, but I don’t have any issues with my lights.

if automations are waiting for each service call to finish then this will affect lights too.

My automation only has one action, and that is to run the script. The code I put up there was the scrips data. I would assume the script goes in the order that it’s actions are laid out which is to 1) take the photo
2) text it via telegram thru Notify

It does, but it doesn’t wait for the photo to be taken and saved before it sends the message.
Either you delay or you listen to the folder and see if the photo has been saved.

Use a wait template before sending the notification. You can use folder watcher, folder, or file integrations.