I finally found my way to have Domoticz send me a telegram with a gif from my camera snapshot! (sorry, but I'm quite pround of it
Here is how I did it:
REQUIREMENTS
Linux Based Hardware
imagemagick software (install via sudo apt-get update && sudo apt-get install imagemagick -y )
a dedicated folder where to store frames (ie (home/pi/dzGif)
SCRIPT
you can choose to send messages via telegram as you like o wish, I use my method but feel free to use whatever you prefer
You will need 2 User Variables:
TELEGRAM_Interval - integer (default 2) - Time interval (in seconds) between capured frames
TELEGRAM_Frames - integer - The numbers of frame to capture - Note this is the SCRIPT TRIGGER
HOW IT WORKS
Once updated the Frame variable the script will start to counting down the frames by updating the variable (so it will keep updating and triggering it)
Once counted to 0 it will start the pack process and will send the doc
once finished it will delete all the clues
dzVents:
Code: Select all
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
local telegram = require('Telegram')
local destId = 'your ChatID'
local filePath = '/home/pi/dzGif/frame'
local domoReq = 'http://127.0.0.1:8080/camsnapshot.jpg?idx='
local frameDigit = 4
local frameDelay = 300
return {
on = {
variables = { 'TELEGRAM_Frames' },
},
logging = {
level = domoticz.LOG_FORCE,
marker = '[Telegram Multi Image]'
},
execute = function(dz, varTrig, trgInfo)
local varInterval = dz.variables('TELEGRAM_Inverval').value
if varTrig.value > 0 then
filler = string.rep('0',frameDigit - string.len(varTrig.value))
os.execute('wget -O "'..filePath..filler..varTrig.value..'.jpg" "'..domoReq..'2"')
varTrig.set(varTrig.value - 1).afterSec(varInterval)
elseif varTrig.value == 0 then
os.execute('convert -delay '..frameDelay..' -reverse -loop 0 '..filePath..'*.jpg '..filePath..'.gif')
risp = telegram.sendDoc(destId, filePath..'.gif')
os.execute('rm '..filePath..'*.*')
end
end
}destIdthe ChatID where to send the file
filePath the working directory included the filename prefix
domoReqAPI address to request the snapshot
frameDigit this is a wired trick I used to sort correctly the frames:
if you are using more than 10 frames they will be nemaned frame1, frame2, frame3...... frame9, frame10... but when you order them frame10 cames before frame1, so I use a fixed lengs numbering (4 digits) to name frames like frame0001, frame0002.... frame0010
frameDelay delay in msec between frames in the Gif file
in the line os.execute('wget -O "'..filePath..filler..varTrig.value..'.jpg" "'..domoReq..'2"') the last 2 identify the camera IDX
HOW TO TRIGGER IT
Update the TELEGRAM_Frames with the amount of frames you want...
KNOWN ISSUES
You could get the warning that the script is taking longer than 10sec... that is ok... the convert command could takes longer
...I'm not so far familiar with ImageMagick... the result GIF file is quite big and I did not found a way to compress it without loosing quality yet
I really hope you like, feel free to comment and improove it!!!
ciao
M