Bash script for sending snapshots using Telegram  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
MeneerKlaas
Posts: 11
Joined: Monday 25 September 2017 17:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Bash script for sending snapshots using Telegram  [Solved]

Post by MeneerKlaas »

Hi all,

Unfortunately there is not yet a function available in dzVents for sending a camera snapshot using Telegram.
I made some minor changes to a Bash scripts found in topic Motion detector with ESP8266 and HC-SR501.

Code: Select all

#!/bin/sh
# $1 = Chat ID
# $2 = Caption
# $3 = Disable Notification (true or false)
TelegramToken="12345678:AABBCCDDEEFFasdfjasdhfkashdf"
SnapFile="/var/tmp/camsnapshot.jpg"
# Get snapshot via Domoticz server
wget -O $SnapFile "http://192.168.123.100:8080/camsnapshot.jpg?idx=1"
# Send Telegram message with image
curl -s -X POST "https://api.telegram.org/bot$TelegramToken/sendPhoto" -F chat_id=$1 -F caption="$2" -F disable_notification=$3 -F photo="@$SnapFile"
# Remove SnapFile
/bin/rm $SnapFile
I have called the Bash file "telegram_snapshot.sh" and placed it in the /home/pi/domoticz/scripts/ directory.

Parameters:
1. Chat ID
2. Caption (Text shown under the snapshot send)
3. Disabled Notification (when true, the notification is silent)

In my dzVents script I added the line:

Code: Select all

os.execute('bash /home/pi/domoticz/scripts/telegram_snapshot.sh "-12345678" "Camera Snapshot" false  &>/dev/null &')
The addition of ''&>/dev/null &' will make sure the script is run in the background. Initially you may remove this part for trouble shooting.

More about running Bash files in the background: Running Bash Commands in the Background the Right Way
Klaas

Raspberry Pi 3: Domoticz, RFXtrx433, Zigbee2MQTT, MQTT, P1 meter, SMA Solar Inverter (modbus TCP/IP)
My Hobby Page about Domoticz & ESP8266
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest