shell script: stopped after few seconds in automation

Hello,

(I am new to HA, (running it on HAOS in proxmox)

TLDR;
a shell command (running a shell script) seems stopped after few seconds (i assume 3) when in an automation, but not when run in a terminal (in the homeassistant docker) or when executed via “dev tools → action”

My intent is to capture an video from usb webcam when a sensor is activated, and stop it when the sensor is deactivated.
I read that scripts (not sure if this is also for shell scripts) are limited to 60 seconds, i am fine with it, it is ok to have a capture "from sensor “on” till 50 seconds or sensor has been switch to “off”

To do that, i created a shell script (in /config/scripts) with ON or OFF parameter. Basically:
if ON:

'nohup ffmpeg -i /dev/video0 -codec:v vp9 -qp 0 -preset ultrafast -t 50 /media/capture.mp4 &

if Off

S_PID=`pgrep "ffmpeg"`
kill -s SIGTERM $S_PID

in configuration.yaml, i added :

shell_command:
  usb_camera_record_on: /config/scripts/script_door_HA.sh ON
  usb_camera_record_off: /config/scripts/script_door_HA.sh OFF

I also “wrap them” into scripts (in scripts.yaml)

usb_camera_start_record:
  alias: USB Camera start recording
  mode: parallel
  sequence:
  - action: shell_command.usb_camera_record_on
usb_camera_stop_record:
  alias: USB Camera stop recording
  mode: parallel
  sequence:
  - action: shell_command.usb_camera_record_off

Now, when i use either the shell commands or the scripts in “dev tools”->action, this work nicely:
when i start a capture and do nothing, i have a 50 seconds movie
when i start a capture, and start another action to stop it (shell command or script), i have a shorter movie.
This is also the same when i lunch those scripts from ssh (in the homeassistant docker)

That’s fine… but when i start the capture from an automation, (e.g. trigger when sensor is “on”) i only have a movie of 2 to 3 seconds (max).

I am stuck here and i would appreciate any hints :frowning:
I seen post and docs regarding the execution time of scripts, i don’t intent to stress the paradigm of “less than a minute”, but i would like to be able to record more or less 50 seconds…
I try to remove the “nohup” and “&” but… no success…

Sorry if this is a “dumb” question, but i fail to find something related to this…
Thanks for reading and for any possible hints…

regards,
D

Hi all,

problem resolved, here in case someone would have a similar issue…

  1. i tried to “just let the script run” (basically keeping the sensor “on”, and at the end, i had the full movie (50s)
  2. so i investigate on the ffmpeg and it “ended to work” (yes, sorry but i don’t have a technical explanation) . I tried other “kill signals” but it seems this was more an ffmpeg issue :slight_smile:
    it works with :slight_smile:
    for acquisition:
ffmpeg -input_format yuyv422 -flush_packets 1 -i /dev/video0 -codec:v libx264 -qp 0 -preset ultrafast -t 50 something/mp4

for kill :

kill -s INT $S_PID

as this is close to black magic to me, well i won’t touch it any more …

Thanks i hope this will help…

D.