Record Vidéo from ESP32_Cam (config with EspHome) in hassio works great!

new step achieved by including a space " ", at the end of the line.

in this line:
http_url =" https://*****.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=$1 "

my .sh file now:

#!/bin/bash
exec &>> "/config/shell_scripts/camera_shell_script.log"
echo "token is: $1"
cam_token=$1
folder="/config/www/cam_record"
id=$(date +"%y-%m-%d_%H-%M-%S")cuisine_camera
http_url="https://****.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=$1 "
mkdir $folder

ffmpeg -i $http_url -t 1 -vcodec copy $folder/$id.mp4

ls -lh $folder/$id.mp4 $folder/cuisine_camera.mp4
cp $folder/$id.mp4 $folder/cuisine_camera.mp4
ls -lh $folder/$id.mp4 $folder/cuisine_camera.mp4
find $folder -type f -name ‘*.mp4’ -mtime +30 -exec rm {} ;

Now the odd log file (CY4X7X ~ 8) shows this:

token is: 8b*******************************************89f47176ed0
mkdir: can't create directory '/config/www/cam_record

': File exists
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (Alpine 8.3.0)
  configuration: --prefix=/usr --enable-avresample --enable-avfilter --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-libx265 --enable-libtheora --enable-libv4l2 --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-libxcb --disable-stripping --disable-static --disable-librtmp --enable-vaapi --enable-vdpau --enable-libopus --disable-asm --disable-debug
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mpjpeg, from 'https://**.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=8b*********************************76ed0':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 800x600, 25 tbr, 25 tbn, 25 tbc
[NULL @ 0x1268af0] Unable to find a suitable output format for '
'

: Invalid argument
ls: /config/www/cam_record
/20-01-31_17-12-32cuisine_camera
.mp4: No such file or directory
ls: /config/www/cam_record
/cuisine_camera.mp4
: No such file or directory
cp: can't stat '/config/www/cam_record
/20-01-31_17-12-32cuisine_camera
.mp4': No such file or directory
ls: /config/www/cam_record
/20-01-31_17-12-32cuisine_camera
.mp4: No such file or directory
ls: /config/www/cam_record
/cuisine_camera.mp4
: No such file or directory
find: -exec requires an argument
/config/shell_scripts/camara.sh: line 16: $'\r': command not found

You make a mix between my file and yours lol : there is

20-01-31_16-12-49cuisine_camera

you dont have such a name, you have :

camera.puerta_esp32cam

so first, adapt my file, dont paste only.

Second one, can you give the exact name of your script? :
i see “camara.sh” is it right? give me what you put inside and paste with special quote (x3) : AltGr + “7 è `” touch on your keyboard please.

your file must be :

#!/bin/bash
exec &>> "/config/shell_scripts/camera_shell_script.log"
echo "token is: $1"
cam_token=$1
folder="/config/www/cam_record"
id=$(date +"%y-%m-%d_%H-%M-%S")puerta_esp32cam
http_url="https://****.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=$1 "
mkdir $folder

ffmpeg -i $http_url -t 1 -vcodec copy $folder/$id.mp4

ls -lh $folder/$id.mp4 $folder/puerta_esp32cam.mp4
cp $folder/$id.mp4 $folder/puerta_esp32cam.mp4
ls -lh $folder/$id.mp4 $folder/puerta_esp32cam.mp4
find $folder -type f -name ‘*.mp4’ -mtime +30 -exec rm {} ;

and i think you have to put this in your configuration.yaml :

shell_command:
  puerta_esp32cam_shell_script: "bash /config/shell_scripts/camara.sh {{cam_token}}"

if “camara.sh” is your name’s script of course, who need to be in the

/config/shell_scripts/

folder

the other problem is the time stamp i use for snapshot (take a picture) and the time stamp for stream video, so if you dont use my automation like, sure it can’t work as expected…

I see 2 problems, first you have a

Server returned 400 Bad Request

so make sure yur hassio in reachable from outside with the duckdns you provide AND WITH HTTPS not http only, and verify that there is not a space or special caracter like " that is at a wrong place…

If you adapt my script with your camera’s name and use my automation, it should work…

Just use your button to trigger the automation and if you dont use presence sensor “somebody_home”, delete the condition in the automation.

What is the firmware you are using in your ESP32CAM device? I’ve wanted to deploy these small devices but never identified a reliable firmware that streams decent quality video. Thank you!!

i just use EspHome 1.14.3 to flash them :wink:

here is my config :

esphome:
  name: garage
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "xxxxxxxxxxxxxxxxxxxxxx"
  password: "xxxxxxxxxxxxxxxxxxxxxx"
  manual_ip:
    static_ip: 192.168.xxx.xxx
    gateway: 192.168.xxx.xxx
    subnet: 255.255.255.0
  
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "xxxxxxxxx"
  
# ESP32-CAM
esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  vertical_flip: false
  horizontal_mirror: false
  resolution: 640x480 

  name: garage

sensor:
  - platform: wifi_signal
    name: "WiFi Signal garage"
    update_interval: 60s
    id: signalWg

switch:
  - platform: restart
    name: "Restart Cam garage"
  

binary_sensor:
  - platform: gpio
    pin: GPIO13
    name: "Garage PIR Sensor"
    device_class: motion

# Flashlight
output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4
light:
  - platform: binary
    output: gpio_4
    name: $hostname lightg

I have put a motion sensor with a case for external antenna : https://www.thingiverse.com/thing:3816458
The point is to stay at the lowest resolution, 640x480, and average fps is 4-8, i know its not a good quality but enought for me, and for 7$ camera…

I have nine of them, running 24h/7d and no crash, work like a charm.

If you want better quality and cheap price, there is the xiaomi cams, for 40$, HD stream, 360° moving, speaker include, …i have 2 of them…you can integrate in HA with another firmware from stock… i have 2, but not integrate in HA, work with Mi-Home from everywhere…xiaomi cloud :thinking:

1 Like

hello script mate, I haven’t been able to do anything so far the work overwhelms me,

  • I have already changed the script content for which you provide me (I think the name should not matter for its operation, but even so I change it to remove problems, it is already updated)

  • the yaml configuration too

 shell_command:
    gateway_sp32cam_shell_script: "bash /config/shell_scripts/camara.sh {{cam_token}}"

i had this

shell_command:
   cam_shell: 'bash /config/shell_scripts/camara.sh {{state_attr ("camera.puerta_esp32cam", "access_token")}}'

will you take the token well with this? {{cam_token}}

  • in automations I have changed to a simple one to do tests
- alias: AAA Doorbell House
   trigger:
   - entity_id: binary_sensor.timbre_pulsador_esp32cam
     from: 'off'
     platform: state
     to: 'on'
   action:
   - service: shell_command.puerta_esp32cam_shell_script

After all this I think the fault has to be in the script line

ffmpeg -i $ http_url -t 1 -vcodec copy $ folder / $ id.mp4

which for me fails

log file after all changes

token is: d17.cf68843ff1
mkdir: can't create directory '/config/www/cam_record

': File exists
/config/shell_scripts/camara.sh: line 9: $'\r': command not found
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.3.0 (Alpine 8.3.0)
  configuration: --prefix=/usr --enable-avresample --enable-avfilter --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-libx265 --enable-libtheora --enable-libv4l2 --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-libxcb --disable-stripping --disable-static --disable-librtmp --enable-vaapi --enable-vdpau --enable-libopus --disable-asm --disable-debug
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
[mjpeg @ 0x1aeeda0] EOI missing, emulating
Input #0, mpjpeg, from 'https://d......duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=d176.....8843ff1':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 800x600, 25 tbr, 25 tbn, 25 tbc
[NULL @ 0x1af1af0] Unable to find a suitable output format for '
'

: Invalid argument
ls: /config/www/cam_record
/20-02-03_18-57-05puerta_esp32cam
.mp4: No such file or directory
ls: /config/www/cam_record
/puerta_esp32cam.mp4
: No such file or directory
cp: can't stat '/config/www/cam_record
/20-02-03_18-57-05puerta_esp32cam
.mp4': No such file or directory
ls: /config/www/cam_record
/20-02-03_18-57-05puerta_esp32cam
.mp4: No such file or directory
ls: /config/www/cam_record
/puerta_esp32cam.mp4
: No such file or directory
find: -exec requires an argument

got¡¡¡ was a fault of hidden characters
CR LF not supported by .sh files

https://unix.stackexchange.com/questions/27054/bin-bash-no-such-file-or-directory

thank you very much thank you for everything

1 Like

my authorization:

- alias: Timbre Casa
  trigger:
  - entity_id: binary_sensor.timbre_pulsador_esp32cam
    from: 'off'
    platform: state
    to: 'on'
  action:

#  - service: camera.play_stream
#    data:
#      entity_id: camera.puerta_esp32cam
#      media_player: media_player.tv

  - service: switch.turn_on
    data:
      entity_id: switch.timbre_zumbador_esp32cam
  - delay: 00:00:01
  - service: switch.turn_off
    data:
      entity_id: switch.timbre_zumbador_esp32cam

  - data:
      caption: LLAMAN A LA PUERTA
      url: https://****.duckdns.org/api/camera_proxy/camera.puerta_esp32cam?token={{state_attr('camera.puerta_esp32cam','access_token')}}
    service: telegram_bot.send_photo

  - service: shell_command.puerta_esp32cam_shell_script

  - delay: 00:01:00
  - data: 
      caption: LLAMAN A LA PUERTA Video
#     target: *****
      file: "/config/www/cam_record/puerta_esp32cam.mp4"
    service: telegram_bot.send_video
    
  - data_template:
      data:
        inline_keyboard:
        - Encender led:/command1, Apagar led:/command2
        - Sonarr:/command3, No sonar:/command4
        - Ding Dong:/command5
      message: Hola timbre
      title: ATENCION TIMBRE
    service: notify.telegram
   


my configuration of ESPHOME:

substitutions:
  hostname: puerta
esphome:
  name: $hostname
  platform: ESP32
  board: esp32dev
wifi:
  ssid: "*******"
  password: "*********"
api:
  reboot_timeout: 0s
ota:
logger:

# ESP32-CAM
esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  resolution: 800x600
  jpeg_quality: 45
  max_framerate: 2.5 fps

  name: "Puerta ESP32Cam"

#web_server:
#  port: 80

# Luz
output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4
    
light:
  - platform: binary
    output: gpio_4
    name: "Luz ESP32Cam"

sensor:
  - platform: wifi_signal
    name: "Señal WiFi ESP32Cam"
    update_interval: 60s

binary_sensor:
  - platform: status
    name: "Estado ESP32Cam"
  - platform: gpio
    pin:
      number: GPIO12
      mode: INPUT_PULLUP
      inverted: True
    name: "Timbre pulsador ESP32Cam"
    filters:
      - delayed_off: 100ms
#  - platform: gpio
#    pin:
#      number: GPIO13
#      mode: INPUT
#    name: "Movimiento"
    
switch:
  - platform: restart
    name: "Restart ESP32Cam"
  - platform: gpio
    pin:
      number: GPIO13
      mode: OUTPUT
    name: "Timbre Zumbador ESP32Cam"

text_sensor:
  - platform: wifi_info
    ip_address:
      icon: "mdi:ip"
      name: "IP ESP32Cam"
    ssid:
      name: "SSID ESP32Cam"
      icon: "mdi:access-point-network"
    bssid:
      name: "BSSID ESP32Cam"
      icon: "mdi:access-point-network"

my card in lovelace:

  - badges: []
    cards:
      - entities:
          - entity: camera.puerta_esp32cam
          - entity: light.luz_esp32cam
          - entity: switch.timbre_zumbador_esp32cam
          - entity: switch.restart_esp32cam
          - entity: binary_sensor.timbre_pulsador_esp32cam
          - entity: binary_sensor.estado_esp32cam
          - entity: sensor.senal_wifi_esp32cam
          - entity: sensor.ip_esp32cam_2
          - entity: sensor.ssid_esp32cam_2
          - entity: sensor.bssid_esp32cam_2
          - entity: sensor.cam_token
        type: entities
      - aspect_ratio: 70%
        camera_image: camera.puerta_esp32cam
        camera_view: live
        entity: camera.puerta_esp32cam
        name: ESP32Cam
        show_name: true
        show_state: false
        tap_action:
          action: call-service
          service: light.toggle
          service_data:
            entity_id: light.luz_esp32cam
        type: picture-entity
    path: camara
    title: camara

my sensor:

  - platform: template
    sensors:
      cam_token:
        value_template: "{{ state_attr('camera.puerta_esp32cam', 'access_token') }}" 

my script:

!/bin/bash
camera_shell_script="/config/shell_scripts/camera_shell_script.log"
rm "${camera_shell_script}" # esto borra cada vez el archivo si quieres que sea incremental puedes borrar
exec &>> "${camera_shell_script}"
echo "token is: $1"
cam_token=$1
folder="/config/www/cam_record"
echo "${folder}"
id=$(date +"%y-%m-%d_%H-%M-%S")puerta_esp32cam
http_url="https://***.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam?token=$1 "
mkdir $folder
#ffmpeg -i $http_url -t 15 -c:v libx264 -preset superfast -vcodec copy $folder/$id.mp4  #modo rapido y otro codec
ffmpeg -i $http_url -t 10 -c:v libx264 -preset slow -crf 22 -c:a copy $folder/$id.mp4 #modo lento y otro codec
ls -lh $folder/$id.mp4 $folder/puerta_esp32cam.mp4
cp $folder/$id.mp4 $folder/puerta_esp32cam.mp4
ls -lh $folder/$id.mp4 $folder/puerta_esp32cam.mp4
#find $folder -type f -name "*.mp4" -mtime +1 -delete
find $folder -type f -name "*.mp4" -mtime +1 -exec rm -f {} \;
#read -p "Pausa "  #pausa si ejecutas el script directamente
1 Like

happy for you it works!

Because we are not experts…we have to search again and again…each time we learn something…sometimes it doesnt work right now but motivation make it!

1 Like

thank you thank you thank you
now only the last instruction of the scritp fails me

with this fault find: -exec requires an argument inside the log

This is the bad instruction:
find $ folder -type f -name ‘* .mp4’ -mtime +30 -exec rm {};

This is the good one for me:

find $ folder -type f -name ‘* .mp4’ -mtime +30 -exec rm -f {} \;

or this one

find $ folder -type f -name ‘* .mp4’ -mtime +30 -delete

Hello, Olivier

Thank you for your script above. And it would be very helpful for me to record by ESP32 cam. But it doesn’t work at this moment and I need you help. Can you please review it below and let us have any comment about it?

As i tested the script below, I got the message about “permission denied”. But I put the all authority for the related folder such as config or WWW folder all. and I put the all file in the appropriate folders.

Is there any supported comment to clarify this issue?

Configuration.yaml file

shell_command: !include shell_commands.yaml

<Shell_command.ymal>

camscript: ' /config/www/camshell.sh {{ state_attr("camera.cam_1", "access_token") }}'

<camshell.sh>

#!/bin/bash
exec &>> "/config/www/script.log"

echo "token is: $1"
cam_token=$1

folder="/config/www/recording"
id=$(date +"%y-%m-%d_%H-%M-%S")cam_1
http_url="https://xxx.xxx.xxx/api/camera_proxy_stream/camera.cam_1?token=$1 "
mkdir $folder

ffmpeg -i $http_url -t 1 -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/esp_cam_1.mp4
cp $folder/$id.mp4 $folder/esp_cam_1.mp4
ls -lh $folder/$id.mp4 $folder/esp_cam_1.mp4
find $folder -type f -name '*.mp4' -mtime +30 -exec rm {} ;

<automation.ymal>

- alias: test
  initial_state: true
  trigger:
    - platform: state  
      entity_id: binary_sensor.motion_sensor_xxxxxx 
      from: 'off'
      to: 'on'  

  action:       
    - service: shell_command.camscript

Hello,

first thing i see …dont know if its the solution but : the “permission denied” is about the wrong token or any token received :slight_smile:

should be :

http_url=https://xxx.xxx.xxx.xxx/api/camera_proxy_stream/camera.cam_1?token=$1

delete the quotes " "
What do you have in your script.log?
you should have line 2 : “your token is : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
If you dont have the token , it cant work.

Second thing : why do you change the name of cam? first you call it “cam_1” and after you call it “esp_cam1”
It should be :

#!/bin/bash
exec &>> "/config/www/script.log"

echo "token is: $1"
cam_token=$1

folder="/config/www/recording"
id=$(date +"%y-%m-%d_%H-%M-%S")cam_1
http_url=https://xxx.xxx.xxx.xxx/api/camera_proxy_stream/camera.cam_1?token=$1
mkdir $folder

ffmpeg -i $http_url -t 1 -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/cam_1.mp4
cp $folder/$id.mp4 $folder/cam_1.mp4;

Third thing is the 2 last lines doesnt need anymore :

ls -lh $folder/$id.mp4 $folder/esp_cam_1.mp4
find $folder -type f -name '*.mp4' -mtime +30 -exec rm {} ;

delete them but dont forget to put back the ; after the last line (i paste the good one at the second remarq)

Lets try!

It works great for me and for @Domy5 ! :wink:

Last thing : i dont put the script direct in the www folder, i create a “shell_script” folder after www folder.

It should work if your delete the quotes in the https adresse of your homeassistant (first thing i notice here) :slight_smile:

Thanks for this. Works well. For smaller video files and to get this to work with telegram on my android device I use the following ffmpeg comand:

ffmpeg -y -r 10 -i $http_url -t 5 -an -c:v libx264 -crf 26 -vf scale=640:-1 -pix_fmt yuv420p $folder/$id.mp4

1 Like

nice!

i use SMTP and email, works great too

Hi Olivier974, I’ve seen that you’re able to record the stream video from the ESP32-CAM and HA.

I would like to do it, however I don’t understand very good how to do the shell and where to put it in the Home Assistant.

So, could you please send me all the configuration to make this possible?

I have a question, where can I get the token?

Thank you very much!

Hello,

all you need is already explained above, if you read the post…solution is in post #17

You can use any text editor and paste the config and adapt all the path for YOUR personnal configuration and finaly saved .sh instead .txt
Then put the script file in the script directory of HA.

I am under Hassio, not HA.

Then you can call the script with an automation, i have motion detector attached to my cam so when there is a detection, the automation call the script.

Read all the post slowly like @Domy5 do and you will succeed !

last thing, you doesnt need to find the token, because he change every time you connect to your cam !
that the job of the script, not yours lol

Thank you for your reply.

I´ve tried but I don´t know where to watch my videos.
I´m gonna share my configuration because maybe something went wrong:

configuration.yaml:

shell_command:

camara1_camera_shell_script: ‘/config/shell_scripts/garage_camera_shell_script.sh {{ state_attr(“camera.camara1”,“access_token”) }}’

/config/shell_scripts/garage_camera_shell_script.sh

!/bin/bash
camera_shell_script="/config/shell_scripts/garage_camera_shell_script.sh"
rm “${garage_camera_shell_script}” # esto borra cada vez el archivo si quieres que sea incremental puedes borrar
exec &>> “${garage_camera_shell_script}”
echo “token is: $1”
cam_token=$1
folder="/config/www/cam_record"
echo “${folder}”
id=$(date +"%y-%m-%d_%H-%M-%S")camara1
http_url="https://xxxxxxxxx.duckdns.org/api/camera_proxy_stream/camera.camara1?token=$1 "
mkdir $folder
#ffmpeg -i $http_url -t 15 -c:v libx264 -preset superfast -vcodec copy $folder/$id.mp4 #modo rapido y otro codec
ffmpeg -i $http_url -t 10 -c:v libx264 -preset slow -crf 22 -c:a copy $folder/$id.mp4 #modo lento y otro codec
ls -lh $folder/$id.mp4 $folder/camara1.mp4
cp $folder/$id.mp4 $folder/camara1.mp4

automations.yaml

  • alias: esp32_cam
    trigger:
    • entity_id: media_player.samsung_ue43mu4657
      from: ‘off’
      platform: state
      to: ‘on’
      action:
    • data:
      entity_id: camera.camara1
      filename: /config/www/cam_captures/garage_{{ now ().year }}{{ now ().month
      }}
      {{ now ().day }}{{ now ().hour }}{{ now ().minute }}.jpg
      service: camera.snapshot
    • delay: 00:00:01
    • data_template:
      data:
      force_image: true
      image: https://xxxxxxxxx.duckdns.org/local/cam_captures/garage_{{ now ().year }}{{ now ().month }}{{ now ().day }}{{ now ().hour }}{{ now ().minute }}.jpg
      message: TV Encendida
      title: Mensaje TV
      service: notify.notify
    • data_template:
      data:
      images:
      - /config/www/cam_captures/garage_{{ now ().year }}{{ now ().month }}{{ now ().day }}{{ now ().hour }}{{ now ().minute }}.jpg
      message: TV Encendida
      service: shell_command.garage_camera_shell_script

That´s all!

Do you see something wrong?

By the way, Where can you see the log?

Thank you!

Hello,

the vidéos are there : /config/www/cam_captures/

so you need to have a folder call “www” in the config folder of hassio and inside, another called “cam_record” and “cam_capture”. Record is for video and capture is for pictures. Is there something inside?

I dont understand why your trigger in your automation is a media_player entity, but, anyway, to test it you can first do a manual trigger of the automation and go to the folders.

You need to create a folder “shell_scripts” under “config” folder of hassio too and put your “garage_camera_shell_script.sh” inside.

here is the config of my .sh :

#!/bin/bash
exec &>>/config/shell_scripts/garage_cam.log

date
echo "token is: $1"
cam_token=$1

folder=/config/www/cam_record
id=$(date +"%y-%m-%d_%H-%M-%S")garage_camera
http_url=http://192.168.x.x:8123/api/camera_proxy_stream/camera.garage?token=$1

mkdir $folder
ffmpeg -i $http_url -t 10 -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/garage_camera.mp4
cp $folder/$id.mp4 $folder/garage_camera.mp4 ;

yours should be :

#!/bin/bash
exec &>>/config/shell_scripts/camara1.log

date
echo "token is: $1"
cam_token=$1

folder=/config/www/cam_record
id=$(date +"%y-%m-%d_%H-%M-%S")camara1
http_url=http://192.168.x.x:8123/api/camera_proxy_stream/camera.camara1?token=$1

mkdir $folder
ffmpeg -i $http_url -t 10 -vcodec copy $folder/$id.mp4
ls -lh $folder/$id.mp4 $folder/camara1.mp4
cp $folder/$id.mp4 $folder/camara1.mp4 ;

its not the “duckDns” adress that you have to use but the local one, in my case 192.168.x.x !!!

First try without modifying a thing…like change the codec mode or others options…

When it will work, you can play with everything you want…that the basic for making something to work…no try a lot of thing different when it doesnt work lol

Good luck

PS : when you post your code, use “Alt Gr” + the key seven " 7 è ` " of you keyboard : 3 times before the code and 3 times after your code like this :

" ```"

" YOUR CODE HERE"

" ```"

and the code will be easy readable, not like the code in your post lol

1 Like