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.
  • Optional  Camera Mount – This mount can be used outside.
  • 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://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:

  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:
      ffmpeg:
      
      camera:
        - platform: ffmpeg
          name: Garage Cam
          input: rtsp://192.168.45.83:554/unicast
    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.

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

  1. Hi,

    ive made the through the instruktions.

    rtsp server cannot connect with vlc.

    fanghack works, but for example the network button writes: unsupported command network.

  2. Tried already 2 sdcards (FAT32) without success. Folks what brand/size was your sdcard for successful firmware downgrade?

     

  3. Hello, is this steps applied for fanghack 2.0 ?

    I just need to view from ivideon for free cloud service (10second notif), no pc server.

    After istall ivideon android app, I need to add camera, but no xiaomi xiaofang cam, any guidance ?

     

     

  4. Help needed …

    After I “Run the scripts” I get ….
    “404 Not Found
    The 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 Found
    The requested URL /cgi-bin/status was not found on this server.

    1. I’m not sure why that would happen. Try a different card. You may also want to try posting on the Fang Hacks GitHub.

  5. Thanks Simit.

    Tried new card 3 times. Same result.

    I did the Downgrade the Firmware  and 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.)

    All help appreciated.

  6. I have xiaofang and xiaomi Yi Home 720p.  Does it work on both? If not, is there any hack info to make the yi works the same as this xiaofang hack ?

  7. How do I setup my hacked xiaofang with Ivideon? There is a list of cameras , but xiaofang is not on the list. Thank you!!

  8. 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!

    1. No, I haven’t. I’ve been meaning to post on the HA forum to see if there is a way to detect when a camera image goes down.

      1. Thanks for the quick reply; aside from xiaofang — is there another  cheap IP camera you’ve come across in the past year that you like for night/day use?

        1. The only other cameras I own are an amcrest pan tilt and the doorbell camera(I wrote about it recently). They both work well with Ivideon and HA.

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

    1. You can take it out, but they will be gone if it reboots. It’s best to just get a cheap card dedicated to it.

  10. Hi

    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

    https://ipcamtalk.com/threads/panoramic-light-bulb-camera-view-from-pc-or-blue-iris.27602/#post-272614

     

    1. Is this camera farther away from your router than the others? Try moving it closer to see if that helps.

      1. No it is not. I have other cheaper camera’s far away. This camera is <5m with no walls in between

  11. As per above procedures, from inside of the house(router), camera work perfect(TinyCam).

    How can I see it from outside with same app. Set up is?

    Thanks.

     

    1. You would need to forward ports on your router. But that would be risky since that would mean other people might be able to access the feed.

      1. I wouldn’t recommend exposing this to the public internet. But forwarding ports would depend on the router you are using.

  12. Hi,

    Stuck at the step 1; need help.

    Followed instructions to flash provided firmware. Cam seems not getting the firmware from the SD card… no activity… LED blinking alternate yellow-blue and thats it!

  13. After use the downgrade firmware the sdcard dont work on Mihome?

    my camera does not recognize the sdcard.

  14. Download the Fang Hacks image. It’s the latest zip file from HERE. Unzip the file to anywhere on your hard drive.

    The file is corrupted

    Applying fang hacks scripts…Source file not found: ‘/media/mmcblk0p1/bootstrap/sdcard’Source file not found: ‘/media/mmcblk0p1/bootstrap/rc.local’Source file not found: ‘/media/mmcblk0p1/bootstrap/rcS’Source file not found: ‘/media/mmcblk0p1/bootstrap/fang_hacks.sh’Source file not found: ‘/media/mmcblk0p1/bootstrap/fang_hacks.cfg’

    Help ME !

  15. You should avoid using the mihome app it’s pretty shady.  Try my generator config app I made and it works in a browser no app required.

     

     

  16. Hi, it’s a bit off-topic, but I’m out of ideas. Have a Hualai Xiaofang 1080p that won’t pair with the mihome app. Anyone had a similar problem? where can I found alternative firmware? can anyone help, please…. @Simit?

Leave a Reply to prabirCancel reply