Telegram dzvents script for doorbell cam still not working Topic is solved

Moderator: leecollings

Post Reply
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Telegram dzvents script for doorbell cam still not working

Post by pgielen »

Sending a snapshot through Telegram from a camera pointed at my front door when the door bell is pressed seems trivial. I have read several threads about it on the Domoticz forum and tried to brew a dzvents script for it. Unfortunately, with no success (yet).

First of all, I have set up the Telegram notification system and it is working when I press the Test button in Domoticz settings. Next, the script is triggered if the doorbell is pressed. But what happens next is obscure.

I have this in my script (the print statements below are only there for checking the strings sent by os.execute):

Code: Select all

return {
    on = { 
       devices = {'Doorbell'}
    },

    execute = function(domoticz, device)
            local teleTok   = '122356789:AABBCDEFGHIJKLMNOPQRSTUVWZYZabcdef'
            local chatId    = '987654321'
            local snapFile= '/var/tmp/camsnapshot.jpg'
            local domoReq   = 'http://123.45.67.89:8088/camsnapshot.jpg?idx=7'
            local teststring = 'wget -O "' ..snapFile..'" "' ..domoReq .. '"'
            print ("WGET string: " ..teststring)
            os.execute(teststring)
            local teststring = 'curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..chatId..'" -F photo="@' ..snapFile..'"'
            print ("POST string: " ..teststring)
            os.execute(teststring)
            local teststring = "rm " ..snapFile
            print ("RM string: " ..teststring)
            os.execute(teststring)
    end
}
Everything seems to work fine without errors, but unfortunately also without a message coming in via Telegram. The log file looks like this:

Code: Select all

2019-07-18 00:12:41.477 Status: dzVents: WGET: wget -O "/var/tmp/camsnapshot.jpg" "http://123.45.67.89:8088/camsnapshot.jpg?idx=7"
2019-07-18 00:12:41.510 Status: dzVents: POST: curl -s -X POST "https://api.telegram.org/bot122356789:AABBCDEFGHIJKLMNOPQRSTUVWZYZabcdef/sendPhoto?chat_id=987654321" -F photo="@/var/tmp/camsnapshot.jpg"
2019-07-18 00:12:41.725 Status: dzVents: RM: rm /var/tmp/camsnapshot.jpg
2019-07-18 00:12:41.739 Status: dzVents: Info: ------ Finished Doorbellphotoscript
Am I overlooking something? Is there something wrong in the syntax?

BTW the camera I am using is a cheap and simple ESP32CAM model. Typing 'http://123.45.67.89:8088/camsnapshot.jpg?idx=7' in the browser results in the download of a file named 'snapshot.jpg'.
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram dzvents script for doorbell cam still not working

Post by hoeby »

This is my script. It works for me.
Be sure you have a link that gives an image in your browser, not a download.
I have an axis camera. When having a string that downloads a image, like you have writen. Than it doesn't work.

Code: Select all

return {
    on = { 
       devices = {'Camera voordeur'},
    },

    execute = function(domoticz, device)
        if(device.state == 'On') then
            local teleTok   = 'your token'
            local chatId    = 'your chat ID'
            local snapFile  = '/home/pi/domoticz/scripts/camera_' 			--Location for saving the image
            local camName   = 'Voordeur' 							--The file name for the image
            local domoReq   = 'http://XXX.XXX.XXX.XXX/jpg/1/image.jpg' 	--This is the string for a axis camera
            
            os.execute('wget -O "'..snapFile..camName..'.jpg" "'..domoReq..'"')
            os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..chatId..'" -F photo="@'..snapFile..camName..'.jpg"')
            os.execute("rm " ..snapFile..camName..'.jpg')
        end
    end
}
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Telegram dzvents script for doorbell cam still not working

Post by waaren »

pgielen wrote: Thursday 18 July 2019 0:40 Sending a snapshot through Telegram from a camera pointed at my front door when the door bell is pressed seems trivial. I have read several threads about it on the Domoticz forum and tried to brew a dzvents script for it. Unfortunately, with no success (yet).
Did you test the individual steps from the command line ?
  • What is the result of the wget command ?
  • Is there an actual image in the jpg file ?
  • Is there a delay between the execution of the wget command and the creation of the jpg ?
  • What is the result of the curl command ?
  • Do you receive anything via telegram after the execution of the curl command ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Telegram dzvents script for doorbell cam still not working

Post by pgielen »

Thanks for your answers. It works now.

There were two problems with my script, actually. One was that the bot token did not work. I don't know why, because when testing it in the Domoticz notification settings it did work. However, I made another bot in Telegram and this does work in the script. It's still a mystery to me why one bot token will work in dzvents and another will not. A peculiarity of Telegram, I guess.

The other problem was that i entered the external url of the camera in Domoticz (seen in the status bar when hovering above the 'Take Snapshot' icon in Setup > More options > Cameras) as the url that should give me a snapshot. It should have been the url in the local network that tells the camera to take a snapshot (in my case 'http://192.168.178.75/capture').

Now, the next challenge will be to rotate the ESP32CAM image 90 degrees clockwise before sending it to Telegram. It's easy in CSS, but can it be done in dzvents?

Pierre
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Telegram dzvents script for doorbell cam still not working

Post by waaren »

pgielen wrote: Saturday 20 July 2019 16:09 Now, the next challenge will be to rotate the ESP32CAM image 90 degrees clockwise before sending it to Telegram. It's easy in CSS, but can it be done in dzvents?
Not directly but if you install imagemagick

Code: Select all

sudo apt-get install imagemagick
and give the the command

Code: Select all

convert original.jpg -rotate 90 rotated.jpg
from dzvents, you can
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Telegram dzvents script for doorbell cam still not working

Post by pgielen »

Thanks for the tip!
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest