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