Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a jpeg as part of the message? #16

Open
ambanmba opened this issue Sep 23, 2020 · 6 comments
Open

Send a jpeg as part of the message? #16

ambanmba opened this issue Sep 23, 2020 · 6 comments

Comments

@ambanmba
Copy link

My doorbell produces a static small .jpeg file at http://192.168.xx.xx/snap.jpeg ... would it be possible to embed that image (not a link to the image, but the actual image?)

@JohnF87
Copy link

JohnF87 commented May 20, 2021

Did you manage to fix this? I have the same question at this moment...

@ambanmba
Copy link
Author

@JohnF87 , I ended up switching to a different plugin (https://github.com/pponce/homebridge-script2) and then using a script to send the picture.

You can easily send a picture via a bash script (Google is your friend here... curl -X POST....)

@JohnF87
Copy link

JohnF87 commented May 20, 2021

Can you give me some help? I found this, but the JSON is invalid.
What is the code you used?

#!/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

@ambanmba
Copy link
Author

The exact code is below. Obviously you need to change the wget command (line 6) to point to where your image is and also change the "bot ID" and "chat ID" to match your circumstances. This will send a photo via the bot each time the doorbell script is activated.

`#!/bin/sh

current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_filename=$current_time.jpeg
new_message=$(date)
wget http://192.168.1.19/snap.jpeg
cp snap.jpeg ~/doorbell/$new_filename

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=111111111 -F parse_mode="MarkdownV2" -F text="${new_message} \- 🔔Doorbell Ring🔔"

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=1111111111 -F photo="@snap.jpeg"

rm snap.jpeg

`

@JohnF87
Copy link

JohnF87 commented May 21, 2021

The exact code is below. Obviously you need to change the wget command (line 6) to point to where your image is and also change the "bot ID" and "chat ID" to match your circumstances. This will send a photo via the bot each time the doorbell script is activated.

`#!/bin/sh

current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_filename=$current_time.jpeg
new_message=$(date)
wget http://192.168.1.19/snap.jpeg
cp snap.jpeg ~/doorbell/$new_filename

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=111111111 -F parse_mode="MarkdownV2" -F text="${new_message} - 🔔_Doorbell Ring🔔_"

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=1111111111 -F photo="@snap.jpeg"

rm snap.jpeg

`

Thanks for the code. Can you help me one more time. I have zero experience with scripting.
When I add the code to the JSON file it shows so errors in the code. What am I doing wrong?
Schermafbeelding 2021-05-21 om 08 23 56

@ambanmba
Copy link
Author

@JohnF87 , the code above needs to be placed into a separate file, not within the JSON. The JSON config is simply to call the file to execute when certain triggers are met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants