Sending snapshots to TG or email or both

Moderator: leecollings

Post Reply
User avatar
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Sending snapshots to TG or email or both

Post by habahabahaba »

Hi.
Made some scripts to send snapshots from ip-cameras to telegram or via email or both. May be it will be useful for somebody. It was made with help of AI so... :)
And I'm on Win so all pathes are for win and not tested on unix.
Features:
- easy to add or remove cameras
- for TG you can specify socks5 proxy - the global setting
- for TG - silent mode - local setting for each script
- for email - one global recipient and you can add more recipients localy in each script

Requirements:
Git for windows - for win users
Python 3.8+
Curl 8.4+

So... unzip attachment to Domoticz\scripts\dzVents\ so it will looks like Domoticz\scripts\dzVents\tg_email_notify\....
Check files for your own settings:
- sendtoemail.lua - only path to email_debug.log
- email_config.lua - settings for email account (the same as in Dz.settings)
- sendToTelegram.lua -settings for Telegram
- create user variable 'socksEnabled' type string and value 0 - needed parameter

Usage:

Code: Select all

		    -- =============================================
                    -- 3. Cameras table
                    -- =============================================
                    local cameras = {
                        {
                            url = "http://192.168.0.87/cgi-bin/snapshot.cgi",
                            caption = "Camera 1", -- any string
                            folder = "C:/Domoticz/screensfromcams/camDvorMelni4naya/" -- any folder you want the same or different for each camera
                        },
                        {
                            url = "http://192.168.0.97/image.jpg",
                            caption = "camera 2",
                            folder = "C:/Domoticz/screensfromcams/camVorotaMelni4naya/"
                        },
                        {
                            url = "http://192.168.0.93/webcapture.jpg?command=snap&channel=0",
                            caption = "Camera 3",
                            folder = "C:/Domoticz/screensfromcams/camMelni4yayaVpered/"
                        }
                    } 
                   
    	            -- =============================================
                    -- NEDEED VARIABLES Don't remove!! :
                    -- =============================================	
    	            local current_date_time = os.date("%Y-%m-%d_%H-%M-%S") 
    	            local deviceName = string.gsub(string.match(debug.getinfo(1, 'S').short_src, "[^/]+$"), '.lua', '') or 'Unknown'          
    	            
    	            
    	            -- =============================================
                    -- SAVING SNAPSHOTS:
                    -- =============================================                    
                    local snapshots = require("tg_email_notify/prepare_snapshots")
                    snapshots.prepare_snapshots(domoticz, cameras, current_date_time)
    	       
    	           
    	            -- =============================================
                    -- SENDING TO TG
                    -- check Domoticz\scripts\dzVents\tg_email_notify\sendtotg.lua for settins
                    -- =============================================
                    local sendToTg = require("tg_email_notify/sendtotg")
                    local silentMode = 'true' -- or false
                    
                    sendToTg.sendToTelegram(
                        domoticz, 
                        cameras, 
                        current_date_time,
                        silentMode
                    )
                    
                    
                    -- =============================================
                    -- SENDING TO EMAIL 
                    -- check Domoticz\scripts\dzVents\tg_email_notify\email_config.lua for settins
                    -- =============================================
                    
                    local emailConfig = require("tg_email_notify/email_config")
                    local emailModule = require("tg_email_notify/sendtoemail")
                    local recipients = domoticz.variables('deltaChatMy').value --..','..'[email protected]'  -- one or several
                    
                    emailModule.sendToEmail(
                        domoticz, 
                        cameras, 
                        emailConfig, 
                        recipients,
                        deviceName,  
                        current_date_time
                    )
Oh.. I used User variable 'deltaChatMy' for email - in order to replace main recipient in one place for all scripts.
Attachments
tg_email_config.zip
(6.86 KiB) Downloaded 36 times
User avatar
waltervl
Posts: 7012
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Sending snapshots to TG or email or both

Post by waltervl »

When the IP camera is connected to Domoticz you can use the dzvents snapshot function for email, for telegram you need other options indeed:

snapshot(cameraID(s) or camera Name(s)3.0.13,subject): Function. Sends email with a camera snapshots if email is configured and set for attachments in Domoticz. Send 1 or multiple camerIDs -names in ; separated string or array.
dz.snapshot() -- defaults to id = 1, subject domoticz
dz.snapshot(1,'dz') -- subject dz
dz.snapshot('1;2;3') -- ; separated string
dz.snapshot({1,4,7}) -- table
dz.snapshot('test;test2') -- ; separated string
dz.snapshot({'test', 'test2'}) -- table

reference: https://wiki.domoticz.com/DzVents:_next ... _scripting
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
habahabahaba
Posts: 283
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Sending snapshots to TG or email or both

Post by habahabahaba »

Thanks walter! :)
The main feature was to send email to several recipients because i need to send some events to me and to my wife :)
User avatar
waltervl
Posts: 7012
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Sending snapshots to TG or email or both

Post by waltervl »

And see also the camera wiki section about sending email notifications based on a switch. Eg you can attach a camera to a PIR switch and when motion is detected a camera snapshot is emailed without using a script.
https://wiki.domoticz.com/Camera_Setup# ... itch/Light
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply