Taking multiple snapshots after the doorbell is activated

Moderator: leecollings

Post Reply
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Taking multiple snapshots after the doorbell is activated

Post by Chakkie »

Hi all,

I've been looking into this forum for a while and seems no one has posted this topic before. So I guess I just made a new one.

I was wondering if there is a possiblity to tell domoticz to make multiple snapshot in a certain interval after the doorbell is activated (pushed).

Like doorbell pushed -> take 10 snapshots with 0.5 - 1 second interval. -> send these images to an email or telegram bot.

Thanks all
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Taking multiple snapshots after the doorbell is activate

Post by Egregius »

Depends on the camera, not?
I just started playing with a RPi camera, looks very promising :)
User avatar
proohu01
Posts: 95
Joined: Friday 17 October 2014 12:20
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Taking multiple snapshots after the doorbell is activate

Post by proohu01 »

Sure you can. Just start off with a lua script like this and change it to your linking. That is what I did. The origional link to the source forum is in the LUA script. This script protects you from peolple that like to press the doorbell more than once in a couple of seconds.

Code: Select all

--[[
Test-Deurbel-Foto
Lua Device script
--]]


-- Script needs a Domoticz uservariable called 'Dummybel_previous' of type 'String'
-- See http://domoticz.com/forum/viewtopic.php?f=23&t=7512 for more information

telegram_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
telegram_chatid_1 = 'xxxxxxx'
telegram_chatid_2 = 'xxxxxxx'
TimeBetweenPresses = 10 --time that needs to be between presses (in seconds), before os.execute line is ran again

commandArray = {}

function datetimedifferencenow(s)
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t1 = os.time()
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    difference = os.difftime (t1, t2)
    return difference
end

if (devicechanged['dummybel'] == 'On') then
    if (datetimedifferencenow(uservariables_lastupdate['Dummybel_previous']) > TimeBetweenPresses ) then
        commandArray['Variable:Dummybel_previous']=tostring(os.time())
        print('<b style="color:Blue">Doorbell pressed, previous time was <b style="color:Green">MORE</b> than '..TimeBetweenPresses..' sec ago, send pushnotification</b>')
        os.execute('wget http://127.0.0.1:8080/camsnapshot.jpg?idx=1 && sudo mv camsnapshot.jpg?idx=1 /var/tmp/snapshot.jpg ')
        os.execute('curl -s -X POST "https://api.telegram.org/bot'..telegram_token..'/sendPhoto" -F chat_id='..telegram_chatid_1..' -F photo="@/var/tmp/snapshot.jpg" ')
        os.execute('curl -s -X POST "https://api.telegram.org/bot'..telegram_token..'/sendPhoto" -F chat_id='..telegram_chatid_2..' -F photo="@/var/tmp/snapshot.jpg" ')
        commandArray['Variable:Dummybel_previous']=tostring(os.time())
    else
        print('<b style="color:Blue">Doorbell pressed, previous time was <b style="color:Red">LESS</b> than '..TimeBetweenPresses..' sec ago, ignore press of button</b>')
    end
end

return commandArray
Pi 2 B | Pi Camera | PiFace 2 | RFXtrx433E (KaKu + Oregon Scientific) | Plugwise (9 Circles) | Aeon Z-Wave stick (Fibaro - dimmers, sockets, RGB, screens/blinds) | RFXMeter (Kwh/water/gaz) | WOL | Onkyo Receiver | RTC | Hikvision | Netatmo | Satel Integra
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Taking multiple snapshots after the doorbell is activate

Post by Chakkie »

Thanks you so much for sharing your script.

This is actually a very nice script to prevent someone who wants to mess with your doorbell by like pressing so many times.

But what I was looking for is when someone at the door press the doorbell once then mutiple snapshots will be taken in a specified interval.

The reason is that one snapshot may not always get a clear shot of the person's face. If you take a multiple shot in a half second interval or less you'll have a bigger chance of getting a better image of that person.

Looking at the lua script and could'nt find the trace of how to define the number of snapshot to be taken and the interval between the shots.

May be just adding simple lines will do the tricks??
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Taking multiple snapshots after the doorbell is activate

Post by Chakkie »

Hi for anyone who also interested. I have figured out how to take a multiple short when doorbell is activated.


lua script:

Code: Select all

commandArray = {}
  if (devicechanged['Deurbel voordeur']=='On') then
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
    os.execute('/home/pi/domoticz/scripts/SentSnapshot.sh')
      print('Script Deurbel is ingedrukt')
  end
return commandArray
Just add the os.execute multiple times in the lua script

Use the following bash script and add sleep x (x is in second) to determine the interval between each snapshot is taken.

The following script is from another user who mentioned this script in the other topic. Please change the parameter to your own.

Code: Select all

#!/bin/sh
today=`/bin/date '+%d-%m-%Y__%H-%M-%S'`;    #Used to generate filename
IP="172.19.3.7"                       # IP address Camera

#Ping IP-address of camera to see if it's online, otherwise we don't have to grab a snapshot
if ping -c 1 $IP > /dev/null ; then  #Grab snapshot

#Get Snapshot from camera
wget "http://172.19.3.7:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=user&pwd=password" -O /volume1/Data/Deurbel_Snapshots/deurbel-$today.jpeg

#Send pushnotification with snapshot
/usr/bin/curl -s -X POST "https://api.telegram.org/bot123456789:yourcode/sendPhoto" -F chat_id=123456789 -F photo="@/volume1/Data/Deurbel_Snapshots/deurbel-$today.jpeg"

#Delete previous taken snapshots older than 7 days
find /volume1/Data/Deurbel_Snapshots/ -name '*.jpeg' -mtime +7 -delete
else
 /usr/bin/curl --data chat_id=138165201 --data-urlencode "text=Camera is offline, so no image can be sent"  "https://api.telegram.org/bot123456789:yourcode/sendMessage"
fi
JanKarel
Posts: 5
Joined: Thursday 18 February 2016 18:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Taking multiple snapshots after the doorbell is activated

Post by JanKarel »

Hello Chakkie would you have a suggestion for attachments to e-mails as well. I have the same object in mind as you, i.e. in response to a motion sensor, but únfortunately I'm not familiar at all with telegram bots.

JanKarel
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests