Page 1 of 1

dzvents cam screenshot

Posted: Saturday 19 January 2019 16:24
by pvklink
Hi, i converted my last three blockly devices and one of them is a alarmscript.
I got the dzvents script working when it detects smoke or a burgler is active, the alarm switch is put on and several devices are triggered

In my old blockly script i had a rule "send camera_snapshot <camera> with subject <subject> after <x> seconds.
This part worked quit well! Is there a simular option in dzvents? i cant find it!

Code: Select all

return {
	on = {devices = {'smoke*','Smoke*'}},    -- alle devices die met Smoke beginnen worden door dit script opgepakt 

    logging =   { level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                  marker  = "Security"},
	
    execute = function(dz, device, info)
    local switch = dz.devices('Alarm_knop')

    if device.state == 'On' then                                -- huis op alarm, iedereen is weg
        switch.switchOn().checkFirst()   --.silent() is als je volgende events niet wil starten
        dz.log("Script: " .. info.scriptName .. " Er is een smokealarm, scenes worden geactiveerd....", dz.LOG_INFO)

    elseif device.state == 'Off' then                                -- huis op alarm, iedereen is weg
        switch.switchOff().checkFirst()   --.silent() is als je volgende events niet wil starten
        dz.log("Script: " .. info.scriptName .. " Er is een smokealarm, scenes worden geactiveerd....", dz.LOG_INFO)

	else
	    dz.log("Script: " .. info.scriptName .. " Smokealarm, onbekende alarmstatus....", dz.LOG_INFO)

	end
end
}

Re: dzvents cam screenshot

Posted: Saturday 19 January 2019 18:03
by waaren
pvklink wrote: Saturday 19 January 2019 16:24 In my old blockly script i had a rule "send camera_snapshot <camera> with subject <subject> after <x> seconds.
Can you show a screenshot of your blockly ?

Re: dzvents cam screenshot

Posted: Saturday 19 January 2019 18:45
by pvklink
I dont have an option to include a picture.
But it is quit easy, when you select add script/blockly
and then add devices/cameras within the blockly environment ..
that works perfect when you configure the email config in domoticz

Re: dzvents cam screenshot

Posted: Saturday 19 January 2019 20:29
by waaren
pvklink wrote:I dont have an option to include a picture.
But it is quit easy, when you select add script/blockly
and then add devices/cameras within the blockly environment ..
that works perfect when you configure the email config in domoticz
What are the values of camera, subject and x?

Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk


Re: dzvents cam screenshot

Posted: Sunday 20 January 2019 12:16
by pvklink
IPCAM
foto vanaf de tuin
0

Re: dzvents cam screenshot

Posted: Monday 21 January 2019 10:56
by waaren
pvklink wrote: Saturday 19 January 2019 16:24 In my old blockly script i had a rule "send camera_snapshot <camera> with subject <subject> after <x> seconds.
This part worked quit well! Is there a simular option in dzvents? i cant find it!
dzVents has no native command for this yet but you can use the function below.

Code: Select all

local function snapshot(idx,subject,delay)
    if not dz then dz = domoticz end
    if not idx then idx = 1 end
    if not subject then subject = "snapshot_" .. dz.time.rawDate .. "_" .. dz.time.rawTime  end
    if delay and delay > 0 then
        local url = dz.settings['Domoticz url'] .. "/json.htm?type=command&param=emailcamerasnapshot&camidx=".. idx .. "&subject=" .. dz.utils.urlEncode(subject)
        dz.openURL(url).afterSec(delay)
    else
        dz.sendCommand("SendCamera:" .. idx, subject)
    end
end
copy / paste this into your script directly after your
  • execute = function(domoticz, item)
part.

You can call this function with the camera number (default 1), subject (default snapshot_date_time), delay (default 0)
testcommands for this function:

Code: Select all

        snapshot(nil,"Test default camera index (1) and no delay")
        snapshot(1,"Test camera index 1 and no delay")
        snapshot(1,"Test camera index 1 and delay of 5 seconds",5)

Re: dzvents cam screenshot

Posted: Monday 21 January 2019 20:35
by pvklink
Great!
Thanks!
This should be a part of standard dzvents....
It works great!
The only thing i couldn't find was the idx attribute, or a number as ID.
So i used:
snapshot(nil,"Test default camera index (1) and no delay")

Is it possible to use Naam instead of idx? IDX isn't visible, only place to look is in the database ... i think...
Another great improvement for this function is that you can take x pictures after y seconds...:
snapshot(1,"Test camera index 1 and delay of 5 seconds",y,x)

Cam attributes are:
Actief:
Naam:
Protocol:
IP Adres:
Poort:
Gebruikersnaam:
Wachtwoord:
ImageURL:

Re: dzvents cam screenshot

Posted: Monday 21 January 2019 20:52
by waaren
pvklink wrote: Monday 21 January 2019 20:35 Great!
Thanks!
This should be a part of standard dzvents....
I will test it...
Thirst question: my cam has no idx attribute, or a number as ID. Cam attributes are:

Actief:
Naam:
Protocol:
IP Adres:
Poort:
Gebruikersnaam:
Wachtwoord:
ImageURL:

Do i use Naam instead of idX?
I am working this but have not found an easy way to use the name. Domoticz internally only accept an idx.
If you use
  • http://domoticz_ip:domoticz_port/json.htm?type=cameras
in your browser you will see your cameras including names and id's.
getting this as a native dzVents command is not as easy as l thought, so I would not wait for it :)

Re: dzvents cam screenshot

Posted: Monday 21 January 2019 20:55
by pvklink
No problem, it works great for me!

Another great improvement for this function is that you can take x pictures after y seconds...:
snapshot(1,"Test camera index 1 and delay of 5 seconds",y,x)

I tried it with: .repeatAfterMin(delay, 5) instead of .afterSec(delay)... this does not work...

Re: dzvents cam screenshot  [Solved]

Posted: Tuesday 22 January 2019 2:40
by waaren
pvklink wrote: Monday 21 January 2019 20:55 Another great improvement for this function is that you can take x pictures after y seconds...:
snapshot(1,"Test camera index 1 and delay of 5 seconds",y,x)
I tried it with: .repeatAfterMin(delay, 5) instead of .afterSec(delay)... this does not work...
That command will probably never gets implemented for the snapshot command.
What you could use now is:

Code: Select all

local function snapshot(idx,subject,delay)
    if not dz then dz = domoticz end
    if not idx then idx = 1 end
    if not subject then subject = "snapshot_" .. dz.time.rawDate .. "_" .. dz.time.rawTime  end
    if delay and delay > 0 then
        local url = dz.settings['Domoticz url'] .. "/json.htm?type=command&param=emailcamerasnapshot&camidx=".. idx .. "&subject=" .. dz.utils.urlEncode(subject)
        dz.openURL(url).afterSec(delay)
    else
        dz.sendCommand("SendCamera:" .. idx, subject)
    end
end

local cameraID  = 1
local repeats   = 5  --- number of repeats 
local interval  = 11  -- seconds between repeats  

for i = 0,(repeats - 1) do 
    snapshot(cameraID,"Test repeated snapshots (" .. i+1 .."/" ..  repeats .. ") of camera with index " .. cameraID .. 
                        ". Snap was shot ".. (i * interval) ..  " seconds after script finished.", ( i * interval ))
end

Re: dzvents cam screenshot

Posted: Tuesday 22 January 2019 23:02
by pvklink
Works perfect!
Thanks again @waaren!
Case closed, next project : a spirit zwaveplus radiator valve.
just installed it, and after 5 minitues it seems to work!

Re: dzvents cam screenshot

Posted: Wednesday 06 February 2019 17:05
by Gravityz
@Waaren.

i noticed your snapshot feature got implemented.
i also want to take multiple snapshots but i think with the new feature the script can be made a lot easier.
instead of looping just 3(or 5) snapshots after eachother with a delay.
also the local function is replaced by the build in function right!

is this correct or am i missing something.

Code: Select all

return {
    active = true,
    on = {
 -- de devices die dit script triggeren 
        devices = {
            'PIR sensor'
        }
    },
    execute = function(domoticz, device)
-- device bevat de info van het device wat de trigger veroorzaakt heeft
-- stuurt een foto als er beweging wordt gedetecteerd en  het alarm aan staat.
        if (domoticz.devices('PIR sensor').state == 'On' and domoticz.security == domoticz.SECURITY_ARMEDAWAY) then
            domoticz.snapshot(1,"beweging snapshot 1")
            os.execute("sleep 1")
            domoticz.snapshot(1,"beweging snapshot 2")
            os.execute("sleep 1")
            domoticz.snapshot(1,"beweging snapshot 3")
        end
     end
}

Re: dzvents cam screenshot

Posted: Wednesday 06 February 2019 17:26
by waaren
Gravityz wrote: Wednesday 06 February 2019 17:05 i noticed your snapshot feature got implemented.
I also want to take multiple snapshots but i think with the new feature the script can be made a lot easier.
If you use a recent Beta then the dzVents has indeed a native snapshot command. It can be used like

Code: Select all

return {
    active = true,
    on = {
 -- de devices die dit script triggeren 
        devices = {
            'PIR sensor'
        }
    },
    execute = function(domoticz, device)
-- device bevat de info van het device wat de trigger veroorzaakt heeft
-- stuurt een foto als er beweging wordt gedetecteerd en  het alarm aan staat.
        if (device.state == 'On' and domoticz.security == domoticz.SECURITY_ARMEDAWAY) then
            for i = 0,2 do
                domoticz.snapshot(1,"beweging snapshot " .. (i + 1)).afterSec(i)
             end
        end
     end
}

Re: dzvents cam screenshot

Posted: Wednesday 06 February 2019 17:30
by Gravityz
nice. tried something similar but could not get it to work. this looks very good.
i wil change my script into that of yours

Re: dzvents cam screenshot

Posted: Wednesday 06 February 2019 19:02
by hoeby
also take a look to this thread

www.domoticz.com/forum/viewtopic.php?f=59&t=26729

it takes a snapshot from a camera, and places it in a directory on the pi. after that it sends it by telegram.
maybe it helps you to get to the point you are looking for

Re: dzvents cam screenshot

Posted: Wednesday 06 February 2019 19:18
by Gravityz
thanks. good info