Page 1 of 2

Email Camera Snapshot

Posted: Wednesday 06 September 2017 13:46
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.

Re: Email Camera Snapshot

Posted: Wednesday 06 September 2017 20:03
by SweetPants
I think you can send camera snapshots if using Gmail email

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 8:12
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.

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 9:41
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']

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 13:50
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.

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 15:21
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.

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 19:13
by ultratoto14
Nice functionality !

Will try that.
Thanks.

Re: Email Camera Snapshot

Posted: Thursday 07 September 2017 19:36
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)

Re: Email Camera Snapshot

Posted: Friday 08 September 2017 8:01
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})

Re: Email Camera Snapshot

Posted: Friday 08 September 2017 9:09
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
	}
}

Re: Email Camera Snapshot

Posted: Monday 13 November 2017 19:12
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

Re: Email Camera Snapshot

Posted: Thursday 04 January 2018 9:14
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!

Re: Email Camera Snapshot

Posted: Thursday 04 January 2018 11:50
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 :-) :-( ]

Re: Email Camera Snapshot

Posted: Sunday 20 September 2020 15:26
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?

Re: Email Camera Snapshot

Posted: Monday 21 September 2020 12:34
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

Re: Email Camera Snapshot

Posted: Monday 21 September 2020 18:25
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.

Re: Email Camera Snapshot

Posted: Monday 21 September 2020 18:42
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

Re: Email Camera Snapshot

Posted: Monday 21 September 2020 18:48
by elgringo

Code: Select all

domoticz.sendCommand('SendCamera:'.. "1;2", "test")
does not work

Re: Email Camera Snapshot

Posted: Monday 21 September 2020 20:17
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?

Re: Email Camera Snapshot

Posted: Saturday 03 October 2020 11:45
by elgringo
Yes this does work