roleoroleo / yi-hack_ha_integration

Home Assistant custom integration for Yi cameras: yi-hack-MStar, yi-hack-Allwinner, yi-hack-Allwinner-v2, yi-hack-v5 and sonoff-hack
GNU General Public License v3.0
205 stars 32 forks source link

Cant take snapshot from ha #129

Closed bedson87 closed 4 months ago

bedson87 commented 1 year ago

I've been having trouble with integration for some time (new home assistant version?). Lots of errors as below when trying to take a snapshot. Sometimes it works but usually writes an empty file. Everything else seems to work normally - recording to sd, preview, mqtt.

Model Suffix y211ga Firmware Version 0.2.6 Yihack integr 0.4.5 Hass 2023.5.4

This error originated from a custom integration.

Logger: custom_components.yi_hack.camera
Source: custom_components/yi_hack/camera.py:249
Integration: Yi Cam with yi-hack (documentation, issues)
First occurred: 9:30:38 AM (2 occurrences)
Last logged: 9:29:16 PM

Fetch snapshot image failed from yi_hack_a2_c013c2_cam, falling back to FFmpeg; HTTPConnectionPool(host='192.168.10.28', port=8080): Read timed out.
roleoroleo commented 1 year ago

Does the snapshot work inside the web gui?

bedson87 commented 1 year ago

Yes, both highres and lowres are displayed without any problems.

roleoroleo commented 1 year ago

HA shows a timeout problem. Weird behavior... Network problems?

bedson87 commented 1 year ago

Nothing has changed with the network and there were no problems before. Camera close to unifi ap. Very good signal 🫢 After restarting the camera, the snapshot works but after some time it stops. Could it be related to something else? SD card? Web ui takes a long time to load snapshot. Screenshot_20230604-224735

roleoroleo commented 1 year ago

Probably the problem is the cam. Could you check the processes when the cam stops working properly? Login to the cam with ssh and run top command. And try to disable "Snapshot for recorded video".

bedson87 commented 1 year ago

Thx for your help! I turned off the recording function and still snapshots from ha don't work. This is what "top" looks like. Screenshot_20230605_210438

roleoroleo commented 1 year ago

top is ok. Now, try to run the snapshot manually: imggrabber -m y211ga -r high -w

bedson87 commented 1 year ago

umm Screenshot_20230606_212229

roleoroleo commented 1 year ago

It should be ok. Try to redirect the command to a file and check if it's a jpeg image: imggrabber -m y211ga -r high -w > /tmp/sd/test.jpg

bedson87 commented 1 year ago

Thanks, it works. Strange thing - with HA once it works and 10 times it fails. I'll try to re-integrate or something.

roleoroleo commented 1 year ago

Check how long it takes. Maybe I could increase the timeout.

EDIT

Another problem. The cam is not able to capture 2 or more snapshot at the same time. If a snapshot is running, the 2nd exits with error.

bedson87 commented 1 year ago

I tried calling single snapshot from dev tools with HA and crash. Is there any good way to measure the time it takes to take a snapshot? Or is it possible to edit the config file for the test somewhere and change the integration timeout?

roleoroleo commented 1 year ago

HTTP_TIMEOUT is a const defined in const.py Now it's set to 10 seconds.

Try to change it and restart ha to reload the integration.

bedson87 commented 1 year ago

Now everything works. I didn't change the timeout. I'm following and thanks for your help and tips!