Does it save any type of video? Let me know; I’d be happy to see if I could expand the platform to cover your use case.
I can think of one option: Disable RTSP server so cloud app is functional. Now, enable record to SD in the cloud app. So, there should be recorded files available on the ftp server. I can try this out tomorrow.
EDIT: \record\20171107\07\ is the folder on the SD card. Files are indeed mp4 (audio is PCM ALAW and video is H264 AVC1). It seems to record multiple files, each around 1 minute long and around 1-1.5 MB in size. My folder had 33.mp4, 34.mp4 and so on.
So my guess is \record\YYYYMMDD\HH\MM.mp4.
Got it! In that case, I think this configuration should work:
camera:
- platform: yi
host: '192.168.1.100'
password: my_password_123
path: /record
Logged into FTP and found this is the correct folder: /media/mmcblk0p1/record/
EDIT: A bug in the hacked firmware is preventing SD card from being found in Mi Home. So, recording cannot be turned on with the latest official firmware. But downgrading works!
I’m getting this error:
[homeassistant.components.camera.yi] There don’t appear to be any uploaded videos
[haffmpeg.core] FFmpeg fails program arguments must be a bytes or text string, not bool
My config:
camera:
- platform: yi
name: DoorCam
password: 123
host: ‘192.168.1.36’
path: /media/mmcblk0p1/record/
I used a dummy password since the camera runs an anonymous ftpd.
EDIT2: Got something to happen! I see files in the ftp folder. They open in VLC just fine. Now, the HASS component is also loading fine and there are no ffmpeg errors in the log.
However, I’m getting a strange black image with ASCII characters
@bachya: seems the system time on the camera (in GMT) is wrong. Do you think this could be causing an issue?
You can’t use a “dummy” password – take a look at the docs.
I don’t see how a system time difference would cause videos to to not show. Here’s one thing you can try: save one of these videos to the machine that runs HASS and configure the Local File camera platform; does the video show up then?
I have the XiaoFang camera (small square thing) running Xiaofang f/w that uses an anonymous busybox ftpd (Dropbear?). I can login just fine without a user/password and with one too.
Maybe your component could support anonymous login, as well?
Well, I finally got the system time fixed to my local time. The files seem to be in China timezone, though. Maybe because the app used Mainland China as locale while setting up. I tried with my country in the mi home app but files still got stored in china timezone.
So, in effect, the file timestamps (modified on) are correct but the folder structure is for 2:30 hours ahead. example: /media/mmcblk0p1/record/20171108/02/40.mp4 (china time) has last modified timestamp as 201711080010 ← this is the correct time
Don’t know how your code works so can’t be sure if the future folder structure will break it.
Also, tried local file (which documentation says is for images eg uses jpg) and it didn’t work.
EDIT: Just realized that this thread is actually for Yi camera. I got misled by the title and the common problems of no RTSP support in HASS and laggy/unreliable custom RTSP servers on the cameras. Though it does seem possible to use a modified version of your platform for Xiaomi Fang camera. I can help with testing if you are interested.
I remembered running into an issue with empty passwords, but will reinvestigate soon.
If you want to test beforehand, Xiaofang seems to use the same Linux distro as Yi, so you can always change the root password via telnet (ftpd uses that same password).
Fascinating! First off, your folder structure is the same as mine (timestamped folders, each containing timestamped MP4s); so, I think we should be fine there. I also think the timezone thing shouldn’t present a problem: as long as all videos are timestamped in the same timezone, my platform should do the right thing.
– – –
Will get back to you soon with a beta v2 that you can test!
I’ve changed root password and added to configuration.yaml but still no go. I can still login via FTP anonymously. And no change in the feed in HASS (side note: the ASCII characters seem to multiply as time passes).
Tried enabling debug on the platform and got only one config loading message and nothing else.
Very promising if this is the logic used. Timestamps on the file are correct and consistent, so far.
Sounds great! I’m in.
I remember why you need to set a password: the ffmpeg
binary (which I use to transcode the video) doesn’t accept password-less FTP requests. So, you’ll definitely need to set a non-null password on your camera.
With that said, let’s try debugging your setup. Could you send me:
- The relevant section of your
configuration.yaml
- All log messages related to this platform.
We’ll go from there. Thanks!
Good news! FTP has been secured by adding -u root to the tcpsvd line in the script. Requires SFTP connection. See updated error message from HASS log.
camera:
- platform: yi
name: DoorCam
password: rootpassword
host: ‘192.168.1.36’
path: /media/mmcblk0p1/record/
ffmpeg:
ffmpeg_bin: /usr/bin/ffmpeg
logger:
default: warning
logs:
homeassistant.components.camera.yi: debug
DEBUG (MainThread) [homeassistant.components.camera.yi] Received configuration: OrderedDict([(‘platform’, ‘yi’), (‘name’, ‘DoorCam’), (‘password’, ‘rootpassword’), (‘host’, ‘192.168.1.36’), (‘path’, ‘/media/mmcblk0p1/record/’), (‘port’, 21), (‘username’, ‘root’)])
2017-11-08 13:47:42 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py”, line 422, in start
resp = yield from self._request_handler(request)
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web.py”, line 306, in _handle
resp = yield from handler(request)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 213, in coro
res = yield from res
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 213, in coro
res = yield from res
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/ban.py”, line 58, in ban_middleware_handler
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/init.py”, line 423, in handle
result = yield from result
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/init.py”, line 387, in get
response = yield from self.handle(request, camera)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/init.py”, line 407, in handle
image = yield from camera.async_camera_image()
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/yi.py”, line 115, in async_camera_image
url = yield from self.hass.async_add_job(self.get_latest_video_url)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/yi.py”, line 79, in get_latest_video_url
ftp = FTP(self.host)
File “/usr/lib/python3.5/ftplib.py”, line 118, in init
self.connect(host)
File “/usr/lib/python3.5/ftplib.py”, line 156, in connect
self.welcome = self.getresp()
File “/usr/lib/python3.5/ftplib.py”, line 235, in getresp
resp = self.getmultiline()
File “/usr/lib/python3.5/ftplib.py”, line 221, in getmultiline
line = self.getline()
File “/usr/lib/python3.5/ftplib.py”, line 209, in getline
raise EOFError
EOFError
2017-11-08 13:47:46 ERROR (MainThread) [haffmpeg.core] FFmpeg fails program arguments must be a bytes or text string, not NoneType
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/haffmpeg/core.py”, line 114, in open
stderr=stderr
File “/usr/lib/python3.5/asyncio/subprocess.py”, line 212, in create_subprocess_exec
stderr=stderr, **kwds)
File “/usr/lib/python3.5/asyncio/base_events.py”, line 1180, in subprocess_exec
% type(arg).name)
TypeError: program arguments must be a bytes or text string, not NoneType
2017-11-08 13:47:46 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py”, line 422, in start
resp = yield from self._request_handler(request)
File “/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web.py”, line 306, in _handle
resp = yield from handler(request)
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 213, in coro
res = yield from res
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 213, in coro
res = yield from res
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/ban.py”, line 58, in ban_middleware_handler
return (yield from handler(request))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/init.py”, line 423, in handle
result = yield from result
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/init.py”, line 387, in get
response = yield from self.handle(request, camera)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/init.py”, line 425, in handle
yield from camera.handle_async_mjpeg_stream(request)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/yi.py”, line 136, in handle_async_mjpeg_stream
‘multipart/x-mixed-replace;boundary=ffserver’)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/aiohttp_client.py”, line 121, in async_aiohttp_proxy_stream
data = yield from stream.read(buffer_size)
File “/srv/homeassistant/lib/python3.5/site-packages/haffmpeg/core.py”, line 156, in read
return self._proc.stdout.read(count)
AttributeError: ‘NoneType’ object has no attribute ‘stdout’
Full log 2017-11-08 13:47:42 ERROR (MainThread) [aiohttp.server] Error handling request - Pastebin.com
I took a look at the code. Maybe we need to use pysftp instead of ftplib.
When I try FTP login, I get this:
Opening FTP connection to 192.168.1.36
FTP login with username root
Opening FTP connection to 192.168.1.36
FTP login with username root
Error EElFTPSError: Control channel transfer errorCWD .
RECONNECTING FTP, PLEASE WAIT…
QUIT
→ FTP reconnected
PWD
Error EElFTPSError: Control channel transfer error
I’m hesitant to introduce a 3rd party FTP library – why do you need SFTP? The Yi Home cameras work fine with vanilla FTP.
Well, because the busybox build on the camera doesn’t support authenticated FTP. I tried using a FTP client and got the control channel transfer error when I added -u to the tcpsvd line. Without -u, FTP works fine without a user/password.
Maybe you can link me to the ftpd binary on your camera so I can check the ftpd from that one?
There isn’t a standard SFTP library in python, apparently.
Discussion on securing FTPd in Xiaofang hacks: Feature Request: Secure FTPd · Issue #255 · samtap/fang-hacks · GitHub
Hi guys, there is no ftp password in my camera, however, the component works with any word as a password in my case.
Looking through that link – if the hack exposes an RTSP server, why not just use this?
https://community.home-assistant.io/t/rtsp-support/2306/7?u=bachya
Great to know!
Well, I thought this would get around transcoding but looks like there’s conversion to MJPEG happening. Wonder why HASS can’t handle H264.
The main reason for this approach is to retain the cloud app functionality and have HASS integration too. Best of both worlds. So you can setup motion detection (cloud backup) and there will also be a video backup on the camera itself of the last few days (depending on SD size).
Way better than the existing option of either RSTP or cloud or JPG.
Got it.
I’m still not seeing a big enough use case to replace Python’s built-in FTP library with a 3rd-party one. Is it necessary for you to be using SFTP?
The only other option is to wait for XiaoFang to release a version with updated busybox (securing the ftpd). Maybe we’ll get a MJPEG streamer too. Or HASS will start supporting H264.
Notice a theme?