Hi all,
I’m trying to record a rtsp stream from my camera, the idea is to start the recording when the door is opened, and stopped + send to telegram when the door is closed.
I’ve created 3 shell commands:
shell_command:
clear_recording: rm /config/www/door.mp4
start_recording: bash /config/www/door.sh
stop_recording: bash /config/www/stop.sh
door.sh
#!/bin/bash
echo "start recording"
ffmpeg -y -nostdin -i "STREAM_URI" /config/www/door.mp4
stop.sh
#!/bin/bash
killall --user root --ignore-case --signal INT ffmpeg
I’ve added both scrips to 2 automations, so when the door is opened, I start the recording, but also when the door is closed, just kill the ffmpeg, wait 2 seconds and then, send the video through telegram
when_door_open:
alias: Sensor de puerta abierto
description: ""
trigger:
- type: opened
platform: device
device_id: device_id
entity_id: binary_sensor.sensor_puerta
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- service: shell_command.start_recording
data: {}
- service: notify.telegram
data:
message: Door is open
mode: single
when_door_close:
alias: Sensor de puerta cerrado
description: ""
trigger:
- type: not_opened
platform: device
device_id: device_id
entity_id: binary_sensor.sensor_puerta
domain: binary_sensor
condition: []
action:
- service: notify.telegram
data:
message: Door close
- service: shell_command.stop_recording
data: {}
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: telegram_bot.send_video
data:
url: http://HOME_ASSISTANT_INSTANCE/local/door.mp4
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- service: shell_command.clear_recording
data: {}
mode: single
Ok, after the explanation. If I execute the bash scripts directy from the terminal, it works like a charm, but if I execute them from Home Assistant automation, it only works the first time I execute the flow, any help??
I see other posts related to that but I didn’t find any solution