Modify the Xiaomi Xiaofang Camera to Work With Home Assistant and Other Video Recording Software

I was looking for a simple and cheap Wifi camera that would work with Home Assistant and doesn’t rely solely on cloud recording since that can get expensive very quickly. In my search, I came across the Xiaomi Xiaofang camera. Although this camera is ‘cloud only’ by default, @samtap on GitHub has created FangHacks, which is a set of scripts that can be installed on the Xiaofang to enable RTSP, along with a bunch of other features. It will also show you how to add this into Home Assistant. This post will go through the steps involved in installing these modifications.

Here’s what you will need:

Xiaomi Xiaofang camera – NOTE: This camera is likely the China version. The cloud recording function probably won’t work anywhere outside of China. If you are only planning on recording the video locally like I am, then that shouldn’t really matter.

MicroSD Card | Amazon – NOTE: I initially had a 2GB SD card, and I couldn’t not get anything to work. I switch to a 16GB card and it worked. The 2GB card worked everywhere else, but not here. I’m wondering if the Xiaofang only reads SDHC cards(usually cards that are 4gb or more). If you run into issues where it seems like the camera isn’t reading the card, try another card.

Windows computer – This can probably be done with other OS’es, but these steps are all what I did on a Windows computer.

Ivideon – Optional – This is the software that I use to record from my cameras. You can store locally forever, and they will also store on the cloud for a day for free ( The paid plans will store it longer ).

NOTE: While I was putting together this writeup, the RTSP feed on the camera appears to be hanging every few days. The web interface stays up, and I can just go to http://CamIP/cgi-bin/action?cmd=reboot to reboot it. I haven’t automated this yet, but I think I might use Home Assistant to do that. I’m not sure if this is a problem that will happen on all cameras or just this one that I have.

Here are the steps:

Downgrade the Firmware
By default, this camera uses the latest Chinese version of their firmware. However, this version prevents the Fang Hacks scripts from working. So this step is for downgrading to a lower version that is also in English.

Copy that file to your empty microSD card. It should be the only file on the SD Card:

Unplug the camera and put the SD Card in there.

While using the pin that came with the camera to push the SETUP button on the bottom of the camera, plug the camera in. Continue holding the reset button for 10 seconds. This causes the camera to go into its ‘firmware update mode’ and will copy that bin file to its internal memory.

After a few minutes, the camera will make a noise, so you will know it is on the new firmware.

Setup the device on Wifi

Open the MiHome app, and follow the steps there to setup the WiFi on the camera.

In the last step, it probably won’t find the camera since the camera will not work with the Chinese servers outside of China. That’s OK. It should have an IP address on it and it should be connected to the network now.

Login to your router to find the IP address of the unit. If your router shows you the MAC addresses of the connected devices, you can use that to find it in the list on your router. The MAC is on a sticker on the camera’s back.

If you don’t know how to find it on your router, you can download and run AngryIP Scanner. Run it and have it scan your network and find the IP address associated with that MAC address.

Load the scripts onto the SD Card.

Put the SD Card back into your computer and delete the firmware file from the SD Card.

HASS will then grab an image from the camera every 10 seconds and show it on the home page.

I hope this is able to help someone out. I had a lot of trouble getting a lot of this information with the firmware and downgrading, so I was thinking there might be others that would like this info in one place. If you have any questions or comments, feel free to post them below. I usually reply fairly quickly.

I also have mine setup with my Garage Door Controller so that the Telegram notifications for it will send a picture of the garage when the garage is left open for a while. I will probably post how to do that soon.

After I “Run the scripts” I get ….
“404 Not FoundThe requested URL /cgi-bin/status was not found on this server. ”

All good – eaxctly as instructed/predicted to here…

Run the scripts.

Power on the camera ( Don’t put the SD Card in yet ).
Wait for the camera to connect to WiFi and initialize. If you wait about a minute, you should be fine.
Put the SD Card in the camera. After around 10 seconds, you should hear a ‘ding’ sound. That means the scripts are loaded.
Go to the following address in your browser, replacing camIP with the IP of the camera: http://camIP/cgi-bin/status ….

Then I get ….
404 Not FoundThe requested URL /cgi-bin/status was not found on this server.

I did the Downgrade the Firmwareand all seemed to work OK. I got the “camera will make a noise, so you will know it is on the new firmware.” Anyway of checking? I dont know what current firmware is on the camera…. Any way of checking (I cant check via the app because I can only get to the stage where the camera registers on my WiFi as 192.168.0.10 and this matches the MAC on the back of the camera.)

Thanks for the tip on Ivideon… Been using these Xiaomi w/ Fang cam’s for 10 month with TinyCamPro and Ivideon seems like a much better option to manage cameras and using my NAS storage and servers to store footage.

In regard to NOTE: While I was putting together this writeup, the RTSP feed on the camera appears to be hanging every few days. The web interface stays up, and I can just go to http://<em>CamIP</em>/cgi-bin/action?cmd=reboot to reboot it. I haven’t automated this yet, but I think I might use Home Assistant to do that. I’m not sure if this is a problem that will happen on all cameras or just this one that I have.

^^
I experience the same thing, have you automated the restarts in some fashion? Did you end up using HA to do such or another method? Thanks!

Thanks Simit for your work. I have questions about after hacking. Should I leave the SD card containing fang.hack files in the camera at all time? Will the camera lose the hacked functions after reboot? Thanks for answering.

I have Defang and have the hack installed. RTSP feed and even http feed is very very slow. It is just like photo slide show. I reduced the resolution to minimum but no difference. Is this the case for Xiofang too? Asking the question as I am wondering to buy one. I use Ivideon and Blue Iris (demo)

I have 6 – 360 panoramic cheap bulb cameras and they woork great and response time way way better. I did not need any hacks for those (they are not IP cameras but you could find RTSP feed see