Hacking the XiaomiFang Wifi camera

Out of interest, are you using the latest released fanghacks SD card image? Or did you create card image from scratch based on the latest github files?

I used the 0.2.0 image release, but seems that this is quite out of date.
Someone raised a issue in GH regarding the camera getting overheated and it causing the RTSP server to crash:

the recommendation is to upgrade to latest source.
(The 0.2.0 image is 9+ months old :frowning: )

Good point so I guess I’ll have to gwait be t a try by building it my own

Guys you should follow this threat here… It is verys good and works like a charm!

4 Likes

thanks for sharing this, will give it a try later to check if the performance on Home Assistant improves.

I got my cam running now for 8 hours without problems… will add another one these days. But it really seems to be stable for the moment. Easy explanation: the rtsp server is checked every x minutes and if stopped it will be restarted automatically. This could be the solution for Xiaomi Cam :slight_smile:

I’ve been using the snx_snapshot/mjpeg technique for a while and found it stable but laggy.

There’s a new camera platform for Yi cameras that uses the continuous recording feature (also available in Mi Home for Xiaofang) and FTP (available in Xiaofang hacks). The author seems to be interested in helping Xiaofang users too. Maybe a new camera platform for Xiaofang could come out of this!

Platform Yi Camera - https://home-assistant.io/components/camera.yi/

Thread for discussion on how to use/modify Yi Home Camera for Xiaofang: Connecting Xiaomi smart camera

1 Like

Great work! With this hack, can you turn on/off the camera from HA? Thanks!

Are you running HA on a raspberrypi 3?

Yes sir! I used this tutorial to get the can running. As the ffmpeg server on the xiaomi hack sometimes breaks down.

Follow this giude:

Ok. Thanks. One last question, can you turn on/off night vision within home Assistant or is it automatic?

1 Like

There must be a script… Dunno remember exatly where which activates the ir

Thundergreen can you put here your config code yaml for the cam?

1 Like

I have a xiaomi Camera but is a diferent model! Is it possible to integrate with HA?

I’m very interested about this camera too :slight_smile:

image

I have 2 of these Xiaomi DaFang cameras and I’ve integrated them with HA.
Note that you will need ffmpeg to get this working.
I personally use motion in the middle to perform motion detection / recording and streaming (I use that streamed feed in HA). Plus for some reason the quality is better than HA directly pulling the RTSP feed.

  1. Get the modified firmware from https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks
  2. Once installed and setup as per the instructions, start the RTSP sever (use the MJPEG RTSP)
  3. If connecting from HA directly, use this config:
camera:
  - platform: ffmpeg
    name: Cam
    input: -rtsp_transport tcp -i rtsp://192.168.x.x:8554/unicast

if using motion in the middle, your config should look like this:

- platform: mjpeg
  mjpeg_url: http://192.168.x.x:808x
  name: Cam

in addition you can control some functions of the camera directly from HA like the blue/yellow LED, IR Filter and IR LED, X and y motor movements etc. The way I achieved this is with a combination of scrape sensors and template switches.
For the scrape sensors I had to create a few web pages to return statuses. I can’t attach them here so I’m posting one example for the blue LED:

#!/bin/sh

echo "Content-type: text/html"
echo ""

getgpio(){
GPIOPIN=$1
cat /sys/class/gpio/gpio$GPIOPIN/value
}

cat << EOF
<!DOCTYPE html>
<html>
<head>
<title>Fang Hacks Blue LED Status</title>
</style>
</head>
<body>
EOF
# status of 0 means on, status of 1 means off
getgpio 39
cat << EOF
</body>
</html>
EOF

Save the file as blue.cgi on the SD card under www/cgi-bin
For other functions, simply replace the GPIO number (39 here) with the one matching the function that you need:

Blue LED: 39
Yellow LED: 38
IR Cut: 26
IR LED: 49

Then you can create scrape sensors, here is the example for the blue LED:

- platform: scrape
  resource: http://192.168.x.x/cgi-bin/blue.cgi
  name: dafang_blue_led_status_scrape
  select: "body"

Create 2 simple shell commands to turn the LED on or off:

dafang_blue_led_on: wget http://192.168.x.x/cgi-bin/action.cgi?cmd=blue_led_on
dafang_blue_led_off: wget http://192.168.x.x/cgi-bin/action.cgi?cmd=blue_led_off

Then create a template switch:

- platform: template
  switches:
    dafang_blue_led:
      friendly_name: Dafang Blue LED
      value_template: "{{ is_state('sensor.dafang_blue_led_status_scrape', '\n0\n') }}"
      turn_on:
        service: shell_command.dafang_blue_led_on
      turn_off:
        service: shell_command.dafang_blue_led_off

Here is the result:
image

Hope this helps

13 Likes

Thanks for sharing!

1 Like

Does tracking work?

No not yet, at least not natively, but there are web commands that you can use to control the motor, depending on what app you use.

Thanks for sharing! How do you start the server? I can’t find how to do that on Github.

Go on the IP address of your camera, it’ll show a webpage that looks like this:

Click on the on of the RTSP Server options as per your needs.