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.
  • Win32 Win Disk Imager – Go ahead and install this.
  • Home Assistant – Optional
  • 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://<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.

Here are the steps:

  1. 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.

    1. Download the firmware from HERE
    2. Copy that file to your empty microSD card. It should be the only file on the SD Card:
    3. Unplug the camera and put the SD Card in there.
    4. 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.
    5. After a few minutes, the camera will make a noise, so you will know it is on the new firmware.
  2. Setup the device on Wifi
    1. Open the MiHome app, and follow the steps there to setup the WiFi on the camera.
    2. 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.
    3. 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.
    4. 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.
  3. Load the scripts onto the SD Card.
    1. Put the SD Card back into your computer and delete the firmware file from the SD Card.
    2. Download the Fang Hacks image. It’s the latest zip file from HERE. Unzip the file to anywhere on your hard drive.
    3. Open Win32 Disk Imager.
    4. Click the Browse button, and point it to the file that you unzipped earlier.
    5. Select the Drive Letter for the SD Card.
    6. Click the Write button. This should take about a minute. The SD Card should look like below:
  4. Run the scripts.
    1. Power on the camera ( Don’t put the SD Card in yet ).
    2. Wait for the camera to connect to WiFi and initialize. If you wait about a minute, you should be fine.
    3. Put the SD Card in the camera. After around 10 seconds, you should hear a ‘ding’ sound. That means the scripts are loaded.
    4. Go to the following address in your browser, replacing camIP with the IP of the camera: http://camIP/cgi-bin/status
    5. If you get the Fang Hacks page, that’s a good sign.
    6. Click the Apply button to activate the hacks.
    7. DO NOT CHECK THE ‘DISABLE CLOUD APPLICATION’. If you want to disable the cloud applications, make sure you go to ‘Network’ and setup your WiFi settings appropriately.
    8. As long as the SD card is in the camera, the hacks will now be applied across reboots.
  5. Test your camera.
    1. You can test your camera using apps such as TinyCam or VLC or iVideon. Just use rtsp://camIP:554/unicast as the address. 
  6. Optional – View your camera in Home Assistant
    1. Use the following code in your Home Assistant .yaml file to see the camera in Home Assistant:
    2. 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.

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

    1. FAT32 I believe. I know that when I started, I was using a 2gb as card and it basically couldn’t read it. I’m not really sure why. You may want to try a different card if you can.

    1. I’m not too sure about the motion sending to a NAS. I don’t think that will work.

      And for the APK, if it worked before the hack, it will work afterwards. If it didn’t work before, it still won’t work.

Leave a Reply

Your email address will not be published. Required fields are marked *