dzvents cam screenshot  [Solved]

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

dzvents cam screenshot

Post 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
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents cam screenshot

Post 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
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents cam screenshot

Post by pvklink »

IPCAM
foto vanaf de tuin
0
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents cam screenshot

Post 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:
Last edited by pvklink on Monday 21 January 2019 20:53, edited 1 time in total.
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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 :)
Last edited by waaren on Tuesday 22 January 2019 2:02, edited 2 times in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents cam screenshot

Post 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...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot  [Solved]

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents cam screenshot

Post 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!
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post 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
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dzvents cam screenshot

Post 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
Last edited by hoeby on Wednesday 06 February 2019 20:07, edited 1 time in total.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: dzvents cam screenshot

Post by Gravityz »

thanks. good info
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest