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

the shell_command :

shell_command:
  cuisine_camera_shell_script: bash -x /config/shell_scripts/cuisine_camera_shell_script.sh **{{cam_token}} >>** /config/shell_scripts/cuisine_camera_shell_script.log 2>&1

doesnt work together {{ }} and >>, i read that in a post https://community.home-assistant.io/t/pass-arguments-to-shell-command-on-event/37029/4?u=olivier974

so i just keep :

shell_command:
  cuisine_camera_shell_script: bash -x /config/shell_scripts/cuisine_camera_shell_script.sh {{cam_token}}

and since that i have nothing in the log…and i dont know how make a second line to have the log…

And i have this error still the beginning :

Error running command: `/bin/bash /config/shell_scripts/cuisine_camera_shell_script.sh {{cam_token}}`, return code: 1

i google it but dont find anything…

i have execute the script by double click it in samba share and the echo is appeared but no token provided

Then replace:

#!/bin/bash
date
echo "token is: $1"

with

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

date
echo "token is: $1"

Execute the script by hand - do not forget to add a token after the file name.
Does it work, is there anything in /config/shell_scripts/cuisine_camera_shell_script.log ? If it isn’t working then you need to fix the script.

If it works try from Home Assistant.

thanks

if i execute the script by hand with power shell windows, it works, i can see the token…fast because the windows open and close very fast…

But no .log create…

if i triggered manualy the automation in hassio, the log is create with no token…

an idea?

I am just guessing - put the command in a double quotation marks:

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

thanks again for your help!

it doesnt change anything…

this is my .sh :

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

date
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://192.168.1.50:8123/api/camera_proxy_stream/camera.cuisine?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 {} ;

i really dont understand why i cant passed a variable from HA, a lot of people do that…

i have replace the " {{cam_token}}" with text and it passed to the script when i triggered manualy…

like this :

shell_command:
  cuisine_camera_shell_script: bash -x /config/shell_scripts/cuisine_camera_shell_script.sh test_to_see

and i have “test_to_see” in the .log for the echo function…

So its a problem with the argument…between ha and the sript…

OK!!! i get it!!!

i have just remove the template “cam_token” in the automation and put directly :

shell_command:
  cuisine_cam_shell: '/config/shell_scripts/cuisine_cam.sh {{ state_attr("camera.cuisine","access_token") }}'

and it works!!! lol

thanks a lot for your help @neohidra

i have now little .mp4 but the format is not regognized…lol

i will search wich format is it now :frowning:

here is the log :frowning:

Sat Dec  7 23:45:55 +04 2019
token is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4fdf663e463bb1e09d167b784b063a470776
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://xxxxxxxxx:8123/api/camera_proxy_stream/camera.cuisine?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe463bb1e09d167b784b063a470776':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 25 tbr, 25 tbn, 25 tbc
Output #0, mp4, to '/config/www/cam_record/19-12-07_23-45-55cuisine_camera.mp4':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: mjpeg (mp4v / 0x7634706D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, q=2-31, 25 tbr, 12800 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=    6 fps=0.0 q=-1.0 size=       0kB time=00:00:00.20 bitrate=   1.8kbits/s speed=0.372x    
frame=   10 fps=9.2 q=-1.0 size=       0kB time=00:00:00.36 bitrate=   1.0kbits/s speed=0.331x    
frame=   14 fps=8.0 q=-1.0 size=       0kB time=00:00:00.52 bitrate=   0.7kbits/s speed=0.299x    
frame=   18 fps=7.6 q=-1.0 size=       0kB time=00:00:00.68 bitrate=   0.5kbits/s speed=0.285x    
frame=   22 fps=7.3 q=-1.0 size=       0kB time=00:00:00.84 bitrate=   0.4kbits/s speed=0.279x    
frame=   25 fps=7.0 q=-1.0 size=       0kB time=00:00:00.96 bitrate=   0.4kbits/s speed=0.268x    
frame=   25 fps=6.4 q=-1.0 Lsize=     256kB time=00:00:00.96 bitrate=2182.7kbits/s speed=0.246x    
video:255kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.340544%
ls: /config/www/cam_record/cuisine_camera.mp4: No such file or directory
-rw-r--r--    1 root     root      255.8K Dec  7 23:45 /config/www/cam_record/19-12-07_23-45-55cuisine_camera.mp4
-rw-r--r--    1 root     root      255.8K Dec  7 23:45 /config/www/cam_record/19-12-07_23-45-55cuisine_camera.mp4
-rw-r--r--    1 root     root      255.8K Dec  7 23:45 /config/www/cam_record/cuisine_camera.mp4
find: -exec requires an argument

reading the vidéo is perfect with VLC Media Player!!! yeahhhhhhhhhhhhhhh!!! :slight_smile:

Thanks anyway for your time, patience and help! your are a nice person!

2 Likes

oohhh friend I would love to work with this but I have problems with the directories and I don’t know where to start

I have the same scritp as you, and changed only the name of cam

1st question: the cuisine_camera_shell_script.sh file where it is hosted
I have it here /config/shell_scripts/cuisine_camera_shell_script.sh

my error: bash: /config/shell_scripts/camera_shell_script.log: No such file or directory

2nd shell_command: does it have to be hosted in configuration.yaml?

3rd is necessary

  homeassistant:
   whitelist_external_dirs:
     - "/ config / shell_scripts /"
     - "/ config / www / cam_record /"

thank you very much friend

Hello @Domy5,

its a pleasure that someone is interested in :wink:

-1st question: i have create a folder named “shell_scripts” under config : like that : /config/shell_scripts/cuisine_camera_shell_script.sh
and lol i understand because i create a .log file to see if it works, so this is the content of the “cuisine_camera_shell_script.sh” for example :slight_smile:

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

date
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://192.168.xxx.xxx:8123/api/camera_proxy_stream/camera.cuisine?token=$1

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

So you can see after triggered manualy your automation, the log will be create and inside its normally looks like mine in my previous message.

-2nd shell_command: does it have to be hosted in configuration.yaml? : you can but i create a file “shell_command.yaml” to put all my shell commands…like :

cuisine_cam_shell: '/config/shell_scripts/cuisine_cam.sh {{ state_attr("camera.cuisine","access_token") }}'

if you do, dont forget to put in configuration.yaml : “shell_command: !include shell_command.yaml” :wink:

You can do whithout and just put in configuration.yaml :

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

-3rd is necessary : no, i havent that in my config…

Last thing : its the automation : you have to triggered with something, like a motion sensor. I have one attached on the camera (you can see here my thingverse : [https://www.thingiverse.com/thing:3816458] (https://www.thingiverse.com/thing:3816458) ).

My automation is :

- id: 'xxxxxxxxxxxxxxxx'
  alias: Record cam detecteur cuisine
  trigger:
  - entity_id: binary_sensor.cuisine_pir_sensor
    for: 00:00:02
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: binary_sensor.somebody_home
    state: 'off'
  action:
  - data:
      entity_id: camera.cuisine
      filename: /config/www/cam_captures/cuisine_{{ 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://XXXXXX.duckdns.org/local/cam_captures/cuisine_{{ now ().year
          }}_{{ now ().month }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute
          }}.jpg
      message: Détection de mouvement cuisine
      title: Alerte cuisine
    service: notify.mobile_app_galaxy_note10
  - data_template:
      data:
        images:
        - /config/www/cam_captures/cuisine_{{ now ().year }}_{{ now ().month }}_{{
          now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg
      message: Capteur de mouvements Cuisine déclenché
      title: '!!! Hassio Detection Cuisine !!!'
    service: notify.email_notify
  - service: shell_command.cuisine_cam_shell

Now you have all what you need :wink:

Enjoy! give me some feedback if its ok for you please :wink:

1 Like

Thank you very much, how quickly you answer, it is appreciated
this does not works:

after configuration.yaml:“ shell_command:! include shell_command.yaml ”
and
shell_command.yaml

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

This worked for me:

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

but it makes a file with a different name than “camera_shell_script.log”
name like this “CY4X7X ~ 8”

and inside the log

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
[https @ 0x753beea0] HTTP error 400 Bad Request
https: //*****.duckdns.org/api/camera_proxy_stream/camera.puerta_esp32cam? token = 7 ************************** ************ 33c4013f1df67e184f1d
: Server returned 400 Bad Request
ls: / config / www / cam_record
/ 20-01-31_16-12-49cuisine_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_16-12-49cuisine_camera
.mp4 ': No such file or directory
ls: / config / www / cam_record
/ 20-01-31_16-12-49cuisine_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 15: $ '\ r': command not found

automation is not a problem I have an automation with a switch-button that sounds a buzz like a doorbell and in turn sends a photo and this would be to send a small video (for now to keep it in a folder) all with the same esp32-cam

any ideas again thank you very much

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