Hacking the XiaomiFang Wifi camera

it is easier as expected to integrate xiaomi cam into hass This can be archieved by Motioneyeos . just add the cam, after installing the hack on it, as network camera and use the streraming link in motioneyeos to stream the video.

@hijinx it might be issue with ffmpeg and raspberry cause when i add this cam with rtsp my whole system freezes. Would u mind telling us how u made it?
This Method seems to be only jpeg and i want a stream not a dia show.

I did the following:

When I go the the group I can see the camera’s feed as a still.
When I click on the still image it opens an overlay card with a live (transcoded) image.

I’m just using the ffmpeg that comes pre-deployed in the hass.io home assistant container.

I can see that ffmpeg is using CPU (using top command from in the homeassistant container, and also on the esxi performance monitor) constantly whilst streaming as it’s transcoding the video.
My guess is that my x86 server has the power to do a transcode, but that RPi does not.
Nonetheless I found that the snx_rtsp_server (RTSP server) process running on the camera seems to die often :frowning:

I’m not at home right now, but I can post the exact yaml later if you like?

thanks for your response… thats exactly the way i did it too. some users say it would work but more I read it doesnt work… so i made my descission to take motioneyeos to transcode the video :slight_smile: thanks anyway… thought i’d find a snipped i missed… but we have done exactly the same thing

First of all - thanks for your dedication on this project :wink:

I’m writing to share you guys the problems I had, you might face the same, and also to make a question.
So I started by hacking the camera as described (https://github.com/samtap/fang-hacks), was really simple, and when opening in VLC the URL rtsp://192.X.X.X/unicast it’s streams(VIDEO/AUDIO) really great.

The problem came with the HASS:
In the configuration.YAML I had the folloiwng:

- platform: ffmpeg
name: HomeCamera
input: -rtsp_transport tcp -i rtsp://192.X.X.X/unicast

From the log’s I have the following error:
2017-09-25 12:08:33 ERROR (MainThread) [homeassistant.loader] Unable to find component input
2017-09-25 12:08:33 ERROR (MainThread) [homeassistant.setup] Setup failed for input: Component not found.
2017-09-25 12:08:33 ERROR (MainThread) [homeassistant.loader] Unable to find component name
2017-09-25 12:08:33 ERROR (MainThread) [homeassistant.setup] Setup failed for name: Component not found.
2017-09-25 12:08:33 ERROR (MainThread) [homeassistant.config] Invalid config for [camera.ffmpeg]: required key not provided @ data[‘input’]. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/camera.ffmpeg/

Turns that, I found that there was just a parsing issue, discovered by this tool: http://yaml-online-parser.appspot.com/
So I changed the config file to the below and start working fine:

  - platform: ffmpeg
    name: HomeCamera
    input: -rtsp_transport tcp -i rtsp://192.X.X.X/unicast

-> My question it’s the following: Is it possible to increase the frames per second that we can see in HASS?

Don’t wanna be rude but the documented yaml config is right. Kits more a problem of hassio that it crashes I guess

I’m running hassio and the built in ffmpeg works fine.
I get a thumbnail of the RTSP feed about every 2-3 seconds, and if I click on the thumbnail it opens a full screen frame with full motion transcode from the camera - its pretty smooth.

My config is the same:

  - platform: ffmpeg
    input: -rtsp_transport tcp -i rtsp://
    name: Xiaofang 1

My guess is that a RPi 3 does not have sufficient CPU to transcode the video in real time, and that the hassio ffmpeg is not able to offload transcode to the GPU (either not compiled correctly or simply not supported - I dont know either way :slight_smile: )
I am using a xeon server, and even that is definitely working harder than normal to do the transcode.
(Its not maxed, but I can see the hassio VMs CPU usage shoot up in ESXi vSphere client.

My bigger problem is that the rtsp server in the camera crashes.

Lets try the MJPEG version of the video server :slight_smile:

this happens to me constantly… and the restart option doesn’t work

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!


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?