Xiaomi Dafang with domoticz

Post Reply
DennisD
Posts: 69
Joined: Friday 18 September 2015 21:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Xiaomi Dafang with domoticz

Post by DennisD » Sunday 13 May 2018 18:52

I finally found a way to make the Xiaomi Dafang (the one with motion tracking) semi work with domoticz, and in case of a motion detection i get a telegram notice.

I did the following:

Hack the dafang camera:
https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks (read the faq and install notes)

Install inotify on rpi:
sudo apt-get install inotify-tools

Install NFS server on rpi:
sudo apt-get install nfs-common nfs-server -y

Make a folder in which you want to share, in my case i made a Dafang folder:
sudo mkdir /mnt/Dafang
sudo chmod -R 777 /mnt/Dafang

Open /etc/exports and add the nfs share:
sudo nano /etc/exports
add the following line(change IPCAM to the ip of the dafang camera:
/mnt/Dafang IPCAM(rw,sync,no_subtree_check,all_squash,anonuid=1000,anongid=1000)

On the dafang camera make a file (i called it nfs) and put it in /system/sdcard/config/autostart
In that file add the following line(change IPDOMOTICZ to the ip of your domoticz):
mount -o nolock -t nfs IPDOMOTICZ:/mnt/Dafang /system/sdcard/motion/stills

Edit /sdcard/config/motion.conf and set save_snapshot=false to save_snapshot=false

Then save the following code to a bash file ie dafang.sh

Code: Select all

#!/bin/bash
#
IMAGEDIRECTORY="/mnt/Dafang"       #NFS Location of files saved from DAFANG
CHATID=""                           #CHATID telegram
BOTID=""  #Bot token telegram
MONITORDIR="/mnt/Dafang"         #Directory which DAFANG save snapshots to

#no need to edit after this point ...
inotifywait -m -r -e create --format '%w%f' "${MONITORDIR}" | while read NEWFILE
do
cd $IMAGEDIRECTORY || exit
fn=$(ls -t | head -n1)

#-- send message to telegram
curl --data chat_id=$CHATID --data-urlencode "text=Beweging gedetecteerd, is er iemand thuis slaapkamer?"  "https://api.telegram.org/$BOTID/sendMessage"

#-- send snapshot with Telegram
curl -s -X POST "https://api.telegram.org/$BOTID/sendPhoto" -F chat_id=$CHATID -F photo=@$fn
done
Everytime a snapshot is added too the dafang folder you will get notified by telegram with a picture (can be allot of pictures :))
Edit /etc/rc.local and add(change it to the directory where the dafang.sh file is located:
bash /home/pi/domoticz/scripts/bash/dafang.sh &

And edit accordingly.

I also made a button in domoticz which activates motion detection on and to turn it off with the following urls:
On: http://root:ismart12@IPDAFANG/cgi-bin/a ... tection_on
OFF: http://root:ismart12@IPDAFANG/cgi-bin/a ... ection_off
(note, change the default username/password, and edit IPDAFANG to your Dafang camera ip).

Then a simple blocky which turns the motion detect on (on detection its makes a snapshot) when nobody is home.

Hope this helps anyone with a dafang camera, and sorry for the long post

niki_lauda
Posts: 139
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Xiaomi Dafang with domoticz

Post by niki_lauda » Monday 17 September 2018 20:35

DennisD wrote:
Sunday 13 May 2018 18:52
I finally found a way to make the Xiaomi Dafang (the one with motion tracking) semi work with domoticz, and in case of a motion detection i get a telegram notice.
...................................
Edit /sdcard/config/motion.conf and set save_snapshot=false to save_snapshot=false

T
Nice but the line
Edit /sdcard/config/motion.conf and set save_snapshot=false to save_snapshot=false

Is this correct? Shouldn't it be /system/sdcard/config/motion.conf and
to save_snapshot=true? or the first false to true?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest