Email Camera Snapshot  [Solved]

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

Moderator: leecollings

ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Email Camera Snapshot

Post by ultratoto14 »

Hi Guys,
I'm trying to convert some of my scripts to dzVents to use the new features introduced with it (like history).

I'm looking for the api to send a camera snapshot by email but it seems to be lacking.
Is someone using that ?
Is this something easy to implement ?

Thanks,
U.
SweetPants

Re: Email Camera Snapshot

Post by SweetPants »

I think you can send camera snapshots if using Gmail email
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Email Camera Snapshot

Post by ultratoto14 »

Hi SweetPants,
I already send camera snapshots using the api:
/json.htm?type=command&param=emailcamerasnapshot&camidx='..camIdxs..'&subject='..urlencode(subject)

I just do not find this api in the dzVents implementation.
Regards,
F.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Email Camera Snapshot

Post by BakSeeDaa »

ultratoto14 wrote: Thursday 07 September 2017 8:12 Hi SweetPants,
I already send camera snapshots using the api:
/json.htm?type=command&param=emailcamerasnapshot&camidx='..camIdxs..'&subject='..urlencode(subject)

I just do not find this api in the dzVents implementation.
Regards,
F.
Why don't you just use

Code: Select all

domoticz.openURL(url)
Have a look in the documentation at here

You can build up your URL based on

Code: Select all

domoticz.settings['Domoticz url']
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Email Camera Snapshot

Post by ultratoto14 »

@BakSeeDaa thanks for the help.

My goal is to enhance dzVents, more than finding a workaround.
I already use my own lua modules to do most of the things.
I was trying to move to dzVents to see its potential.

I solved it by adding in runtime/domoticz.lua:

Code: Select all

 -- have domoticz send an email with camera snapshot                                                                                                                                                                                                                                                                                               
 function self.emailCamera(subject, indexes)
    if (indexes == nil or #indexes == 0) then
       utils.log('No camera indexes provided', utils.LOG_ERROR)
    else
       if (subject == nil) then subject = '' end
       self.sendCommand('SendCamera:'..table.concat(indexes,';'), subject)
    end
 end
Maybe @dannybloe will add it in the future.
Thanks again to the helpers.
F.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Email Camera Snapshot

Post by BakSeeDaa »

ultratoto14 wrote: Thursday 07 September 2017 13:50 @BakSeeDaa thanks for the help.

My goal is to enhance dzVents, more than finding a workaround.
I already use my own lua modules to do most of the things.
I was trying to move to dzVents to see its potential.

I solved it by adding in runtime/domoticz.lua:

Code: Select all

 -- have domoticz send an email with camera snapshot                                                                                                                                                                                                                                                                                               
 function self.emailCamera(subject, indexes)
    if (indexes == nil or #indexes == 0) then
       utils.log('No camera indexes provided', utils.LOG_ERROR)
    else
       if (subject == nil) then subject = '' end
       self.sendCommand('SendCamera:'..table.concat(indexes,';'), subject)
    end
 end
Maybe @dannybloe will add it in the future.
Thanks again to the helpers.
F.
Instead of changing dzVents I believe a better idea would be to create a shared helper function. Doing so, your code will not disappear when you upgrade Domoticz.
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Email Camera Snapshot

Post by ultratoto14 »

Nice functionality !

Will try that.
Thanks.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Email Camera Snapshot

Post by BakSeeDaa »

ultratoto14 wrote: Thursday 07 September 2017 19:13 Nice functionality !

Will try that.
Thanks.
You can also use the dzVents logging functionality.

Code: Select all

domoticz.log('No camera indexes provided', domoticz.LOG_ERROR)
But then, you'd also need to pass the domoticz object to your function.

The function can then be defined as

Code: Select all

	emailCamera = function(domoticz, subject, indexes)
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Email Camera Snapshot

Post by ultratoto14 »

Thanks a lot BakSeeDaa, this is exactly what i did and i just see your message.

Thanks for your time
The complete code

Code: Select all

return {
    helpers = {
       emailCamera = function(domoticz, subject, indexes)                                                                                                                                                                   
         -- have domoticz send an email with camera snapshot
         if (indexes == nil or #indexes == 0) then
            domoticz.log('No camera indexes provided', utils.LOG_ERROR)
         else
            if (subject == nil) then subject = '' end
            domoticz.sendCommand('SendCamera:'..table.concat(indexes,';'), subject)
         end
      end
    }
}
Then use

Code: Select all

domoticz.helpers.emailCamera(domoticz, subject, array_of_indexes)
example:

Code: Select all

domoticz.helpers.emailCamera(domoticz, 'Alarm triggered', {1, 2})
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Email Camera Snapshot

Post by BakSeeDaa »

Looks great!

But you should use the domoticz.LOG_ERROR.

I took me the liberty to change your code a little bit like this:

Code: Select all

return {
	helpers = {
		emailCamera = function(domoticz, subject, indexes)
			subject = subject or ''
			-- have domoticz send an email with camera snapshot
			if not indexes or #indexes == 0 then
				domoticz.log('No camera indexes provided', domoticz.LOG_ERROR)
			else
				domoticz.sendCommand('SendCamera:'..table.concat(indexes,';'), subject)
			end
		end
	}
}
Gravityz
Posts: 587
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Email Camera Snapshot

Post by Gravityz »

i am working my way in dzVents(coming from lua) but i really do not see how this works

can anybody explain it to me in a way i can implement this code/function so i can use it to send an email snapshot from my camera

eg:
where do i put the camera info
do i use the complete api string i curently use in lua
anasazi
Posts: 43
Joined: Saturday 06 August 2016 9:53
Target OS: Windows
Domoticz version:
Location: Sweden
Contact:

Re: Email Camera Snapshot

Post by anasazi »

Hi,

I'm using this command within dzvents:

Code: Select all

domoticz.openURL('http://x.x.x.x/json.htm?type=command&param=emailcamerasnapshot&camidx=1&subject=Test')
I am receiving an e-mail but the image seems to be base64 decoded beacuse all I see is some random tect and not the image.
Do you have any idea how to fix this?

Code: Select all

<img src="data:image/jpeg;base64,(here comes the random text).
Thanks!
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Email Camera Snapshot

Post by Derik »

Perhaps a someone have a script to send the [ or some of them ] pictures directly to a gmail drive???
So we can use the drive as a backup... [ for when you see after x days you miss something in the garden :-) :-( ]
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
elgringo
Posts: 94
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: Email Camera Snapshot

Post by elgringo »

I use this script above:

Code: Select all

		emailCamera = function(domoticz, subject, indexes)
			subject = subject or ''
			if not indexes or #indexes == 0 then
				domoticz.log('No camera indexes provided', domoticz.LOG_ERROR)
			else
        domoticz.log('SEND '..table.concat(indexes,';'), domoticz.LOG_ERROR)
				domoticz.sendCommand('SendCamera:'..table.concat(indexes,';'), subject)
			end
		end,
		
This works without problem for a single camera, but for 2 it does not work.
Is it possible to send multiple camera pictures in a single email?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Email Camera Snapshot

Post by waaren »

elgringo wrote: Sunday 20 September 2020 15:26 Is it possible to send multiple camera pictures in a single email?
Currently not but maybe it could be implemented. What do you get when you
http://<domoticzIP:domoticzPort>/json.htm?type=command&param=emailcamerasnapshot&camidx=1;2&subject=Test
or
http://<domoticzIP:domoticzPort>/json.htm?type=command&param=emailcamerasnapshot&camidx=1,2&subject=Test
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elgringo
Posts: 94
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: Email Camera Snapshot

Post by elgringo »

waaren wrote: Monday 21 September 2020 12:34
elgringo wrote: Sunday 20 September 2020 15:26 Is it possible to send multiple camera pictures in a single email?
Currently not but maybe it could be implemented. What do you get when you
http://<domoticzIP:domoticzPort>/json.htm?type=command&param=emailcamerasnapshot&camidx=1;2&subject=Test
or
http://<domoticzIP:domoticzPort>/json.htm?type=command&param=emailcamerasnapshot&camidx=1,2&subject=Test
The ; separated version works like a charm :)

I assume there is currently not a way to trigger this via DzVents?
For now I just use the url.
Last edited by elgringo on Monday 21 September 2020 18:46, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Email Camera Snapshot

Post by waaren »

elgringo wrote: Monday 21 September 2020 18:25 I assume there is currently not a way to trigger this via DzVents?
not natively in the current version but can you check if

Code: Select all

domoticz.sendCommand('SendCamera:'.. "1;2", "test")
works?
if that does not work, below dzVents command should

Code: Select all

domoticz.openURL("http://<domoticzIP:domoticzPort>/json.htm?type=command&param=emailcamerasnapshot&camidx=1;2&subject=Test") 
If one of the above does work I will implement as a native option in a next version
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elgringo
Posts: 94
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: Email Camera Snapshot

Post by elgringo »

Code: Select all

domoticz.sendCommand('SendCamera:'.. "1;2", "test")
does not work
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Email Camera Snapshot

Post by waaren »

elgringo wrote: Monday 21 September 2020 18:48

Code: Select all

domoticz.sendCommand('SendCamera:'.. "1;2", "test")
does not work
And can you confirm the domoticz.openurl does?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elgringo
Posts: 94
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: Email Camera Snapshot

Post by elgringo »

Yes this does work
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest