evilmarty / mjpeg-timelapse

Mjpeg Timelapse integration for Home Assistant
MIT License
24 stars 4 forks source link

Pause/resume capture? #6

Closed bjeanes closed 2 years ago

bjeanes commented 2 years ago

I'm wondering if it would be possible to pause and resume the capture of frames for this integration? Perhaps with a service to start and stop? The use-case here is to stop capturing at a low light level and just show frames from when the image (from a camera) is light. Before finding this integration, I was planning to use the camera.* services to take a photo conditionally and have a ffmpeg process stitch together the frames into a video to play, but something like this integration would work much nicer if it were possible to suppress capture (e.g. from an automation).

evilmarty commented 2 years ago

@bjeanes you can achieve that by turning the camera off and on via services.

bjeanes commented 2 years ago

Ah fantastic. I didn't realise that would have that effect already :). Thanks for the prompt reply!

bjeanes commented 2 years ago

@evilmarty ah the caveat here is that stopping the camera also stops me from viewing the accumulated timelapse (the /api/camera_proxy/camera.xxxx/ route returns a 503`. More so I'm hoping to have it continue to show/loop the frames that do exist but stop capturing new frames. This is for a timelapse of a garden situation, so being able to see if the plant was starting to droop before the lights went out to identify watering issues is the goal here.

Any ideas?

evilmarty commented 2 years ago

@bjeanes if that is so then it'll have to be controlled by service calls, which need to be implemented.

evilmarty commented 2 years ago

@bjeanes I've added the ability to use service calls to pause and resume recording. Hopefully that should suffice your needs.

bjeanes commented 2 years ago

Thank you! I'll try it out tonight.

bjeanes commented 2 years ago

I was unable to get this working. I updated to the 3e4fa7a via HACS, restarted HA, but the new services do not show up in service dev tools.

If I create an automation to use what I assume is the service names (based on looking at the code), I get:

Screen Shot 2022-03-17 at 11 39 55 am

The services don't show up under mjpeg_timelapse nor camera:

Screen Shot 2022-03-17 at 11 44 21 am

evilmarty commented 2 years ago

There's a newer version with some fixes. Can you try update and try again?

bjeanes commented 2 years ago

I'm on 3e4fa7a already and AFAICT that is the tip of main

evilmarty commented 2 years ago

It's odd that the services don't appear. Are there any errors in the logs?

bjeanes commented 2 years ago

Nothing that I can see, no. I will try uninstalling and re-installing the integration via HACS, restarting in between. Perhaps those service registrations only happen once and not each boot...

bjeanes commented 2 years ago

Uninstalled HACS. Restarted. Re-installed. Restarted. Still only the Clear images service shows up. As a sanity check, I SSHd into HASS to check that it is using the right version of the code:

[core-ssh mjpeg_timelapse]$ pwd
/root/config/custom_components/mjpeg_timelapse

[core-ssh mjpeg_timelapse]$ cat services.yaml
clear_images:
  name: Clear images
  description: Deletes all recorded images.
  target:
    entity:
      integration: mjpeg_timelapse
      domain: camera
pause_recording:
  name: Pause recording
  description: Pauses fetching and saving images.
  target:
    entity:
      integration: mjpeg_timelapse
      domain: camera
resume_recording:
  name: Resume recording
  description: Resumes saving images.
  target:
    entity:
      integration: mjpeg_timelapse
      domain: camera

If I grep for clear_images vs the new services, the only notable difference is that only clear_images is registered in async_setup_platform: https://github.com/evilmarty/mjpeg-timelapse/blob/3e4fa7a02c2ecdfb3e582cd3b99b76bdad4a98aa/custom_components/mjpeg_timelapse/camera.py#L100-L111

Is that perhaps the issue?

evilmarty commented 2 years ago

That bit of code doesn't do anything. The part that does is above it in async_setup_entry:

https://github.com/evilmarty/mjpeg-timelapse/blob/3e4fa7a02c2ecdfb3e582cd3b99b76bdad4a98aa/custom_components/mjpeg_timelapse/camera.py#L77-L97

It's weird that one is working whilst the other is not. What version of HA are you using?

evilmarty commented 2 years ago

@bjeanes I figured it out. You are right, if you defined your entries in customization.yml then they would not be available. If you had used the HA they would have been available.

bjeanes commented 2 years ago

Hah! ~I see. Can you make it work with customizations.yml?~ I am using that because you have not enabled re-configuration via HA and so I'm still tweaking a few things. Working now!