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
221 stars 32 forks source link

Turn off motion event recording #107

Closed gewinh closed 6 months ago

gewinh commented 1 year ago

Thank you for the great work on the Sonoff cameras. I have a number of these cameras using the 0.1.4 hack, these are integrated into Home Assistant using your the custom integration. Cameras are. Model GK-200MP2C Base Version V0525.1.412build20220712 I use the pricacy mode binary sensor to turn the internal cameras off when the house is occupied. I understand that this switch only turns off the stream. What I would like to do is to turn off/on the Motion detection switch when the privacy mode is selected/unselected, so that recording of motion events to the sdcard is stopped. Is there a way of doing this from home assistant (even an ssh command to the camera would be OK). Thanks

roleoroleo commented 1 year ago

You can send a web command through camera_settings.sh http://MY_CAM/cgi-bin/camera_settings.sh?motion_detection=no http://MY_CAM/cgi-bin/camera_settings.sh?motion_detection=yes

gewinh commented 1 year ago

Brilliant, thanks. I setup a command_line switch in HA using curl and the above commands to turn off/on motion detection. Just what I needed.

gewinh commented 1 year ago

I have celebrated and closed this issue prematurely. Upon further testing I have found that turning off the Motion detection switch under Camera Settings, General (either directly from the web front end and doing a save, or via a web call) doesn't stop video recording, although the web page states all changes will take effect immediately. The camera still records and saves video on motion regardless if the switch is off or one. If I reboot the camera after switching motion detection off, then recording does stop. I am running the camera with cloud disabled, mqtt enabled and pointing to the HA mqtt instance. The username for the web interface is not root. Am I missing something here?

gewinh commented 1 year ago

So now, after a lot of testing the most reliable solution that meets my security needs is to create switches for each inside camera using the following yaml. Cameras off when home, on when away. I use the privacy switch in combination with this. Messy but works until a more elegant solution is available.

roleoroleo commented 1 year ago

The next release should fix this problem. https://github.com/roleoroleo/sonoff-hack/commit/740c4bb97a464513cca30900b700e4f497f7ac9f

gewinh commented 1 year ago

Thanks for the excellent software and support. I look forward to the new version.

gewinh commented 1 year ago

Thanks for the 0.15 firmware update, it did resolve my issues. Turning the privacy switch on in HA now turns the video off, on the camera so recording is stopped. I haven't upgraded the integration as yet but everything seems OK. I did have a few random camera restarts after the 0.15 web update, so I turned off snapshot for recorded video and turned on swapfile on sd, the camera is now stable. After a complete restart power off/on camera and HA restart everything is working for me. I will try the updated integration after a little running in the current state.

gewinh commented 1 year ago

Another head scratcher. In between minding grandchildren, I have been trying to sort out another issue with the privacy switch. I have been testing 3 cameras all running 0.1.5. The first (Base Version | V0525.1.276build20201103, Model | GK-200MP2C)works well, you turn privacy on and that sets the mqtt switch_on to no, it kills the rtspd process and the AVRecorder processes, this stops the display of the streams and the recording of the streams. I have quite a few other cameras on different sites that have the same setup and they work as expected with the privacy switch (after the great updates from Roleo re previous issues with the privacy switch) The next 2 cameras(Base Version | V5520.2053.0505build20230320, Model | GK-200MP2-B) do everything right except for the privacy switch, when you turn the switch on the mqtt switch_on goes to no, it kills the rtspd process, but there is no AVRecorder process on these cameras, the camera is still recording, it must be using a different process for the recording. Running "top" or "ps" on this camera with the privacy switch off shows no AVRecorder process. So when the privacy switch is on although the rtsp stream is not visible, the camera is still recording, you can see the videos in the web interface or on the sdcard at /mnt/mmc/alarm_record. I am at a loss to try and figure this out. I will do some more testing next week on 0.1.6 but I don't think the changes in this new version relate to this issue.

roleoroleo commented 1 year ago

Are you able to detect which process is responsible for the recording?

gewinh commented 1 year ago

OK played around some more and think I have found a more generic solution that works for both versions of the firmware and is a little more subtle that killing the recording process (which I cannot find for the new firmware). I found that if you pause the AlarmServer process the motion recording stops and then after you resume the process motion recording starts again. So can I suggest that you include this in privacy.sh and potentially remove the kill AVRecorder part, The stop/start rtsp streams is still needed. I used the following commands to pause and continue the AlarmServer process. ps | grep 'AlarmServer' | grep -v 'grep' | awk '{ printf $1 }' |xargs kill -SIGSTOP ps | grep 'AlarmServer' | grep -v 'grep' | awk '{ printf $1 }' |xargs kill -CONT The first command puts the status of the AlarmServer process to T and no recording goes to the SD The second command resumes the recording.

gewinh commented 1 year ago

Tested this further by editing the Live privacy.sh in /mnt/mmc/sonoff-hack/www/cgi-bin/privacy.sh

additional Lines

start_alarmserver() {
ps | grep 'AlarmServer' | grep -v 'grep' | awk '{ printf $1 }' |xargs kill -CONT }

stop_alarmserver() { ps | grep 'AlarmServer' | grep -v 'grep' | awk '{ printf $1 }' |xargs kill -SIGSTOP }

changed this area

if [ "$VALUE" == "on" ] ; then touch /tmp/privacy touch /tmp/snapshot.disabled stop_rtsp stop_alarmserver RES="on" elif [ "$VALUE" == "off" ] ; then rm -f /tmp/snapshot.disabled start_alarmserver start_rtsp rm -f /tmp/privacy RES="off"

These changes seem to fix the problem at least until reboot. ie no recording when privacy is turn on in HA. It would be nice to make these changes permanent in the distribution. I haven't investigated how to make the privacy status be retained on reboot of the camera.

roleoroleo commented 1 year ago

I will add to the next release. Thank you.

github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.