Camera.record Stream/record not ending/saving

Hi All,

I used to have an automation what send an photo via Telegram whenever the door opens.
This work great, only issue is that it is way to quick so i did not see who walked in as the photo was already taken.

So now i read some blogs and the advice was to use camera.record instead of camera.snapshot. Only i can’t get it to work. First issue was i did not install Stream and additional packages. But those are fixed. Now when i run my automation it doesn’t do anything (for what i can see). When i run the automation again it tells me it is already recording.

I already changed the duration time to “2” to make sure i was not to quick. But no joy.

Error log shows me:

Log Details (ERROR)
Sun Nov 10 2019 14:55:24 GMT+0100 (Central European Standard Time)
Error while executing automation automation.voordeur_notificatie. Unknown error for call_service at pos 2:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 437, in action
await script_obj.async_run(variables, context)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/script.py”, line 190, in async_run
await self._handle_action(action, variables, context)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/script.py”, line 274, in _handle_action
await self._actions[_determine_action(action)](action, variables, context)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/script.py”, line 357, in _async_call_service
context=context,
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 97, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py”, line 1236, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py”, line 1261, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py”, line 213, in handle_service
self._platforms.values(), func, call, service_name, required_features
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 348, in entity_service_call
future.result() # pop exception if have
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 372, in _handle_service_platform_call
await func(entity, data)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/camera/init.py”, line 712, in async_handle_record_service
DOMAIN_STREAM, SERVICE_RECORD, data, blocking=True, context=call.context
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py”, line 1236, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py”, line 1261, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/stream/init.py”, line 132, in async_record
await async_handle_record_service(hass, call)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/stream/init.py”, line 237, in async_handle_record_service
raise HomeAssistantError(f"Stream already recording to {recorder.video_path}!")
homeassistant.exceptions.HomeAssistantError: Stream already recording to /home/homeassistant/.homeassistant/secure/voordeur.mp4!

My automation is not so exciting but here is the config.

- id: test123
  alias: Voordeur Notificatie
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d0002e8b414
    from: 'off'
    platform: state
    to: 'on'
  action:
  - data:
      message: '{{now().strftime("%H:%M %Y-%m-%d")}}: Voor deur is open geweest.'
      title: '*Voordeur sensor is getriggerd*'
    service: notify.telegramdaniel
  - data:
      duration: 2
      entity_id: camera.gang
      filename: /home/homeassistant/.homeassistant/secure/voordeur.mp4
    service: camera.record

The path where it saves is my secure path:

homeassistant:
  # Name of the location where Home Assistant is running
  # name: Home
  # Location required to calculate the time the sun rises and sets
  # latitude: 52.028213
  # longitude: 5.046502
  # Impacts weather/sunrise data (altitude above sea level in meters)
  # elevation: 0
  # metric for Metric, imperial for Imperial
  # unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  # time_zone: Europe/Amsterdam
  # Customization file
  customize: !include customize.yaml
  whitelist_external_dirs:
    - /home/homeassistant/.homeassistant/secure
# lovelace:
#   mode: yaml

Hope anyone can see where i am going wrong.
Thanks!

Hi,

So I have somehow very similar problem - my camera does record a stream but after a random number of times the recording is triggered - eventually it throws up the same error and then fails to record anymore until I restart hassio. Then everything is fine for few recordings and it does the same again.

Looks a bit to me like a weird race condition…Not sure if that’s helpful, but maybe we can dig into it deeper or maybe someone has an idea what’s going on here?

The error I get can be seen below:

Tue Dec 10 2019 19:13:32 GMT+0100 (Central European Standard Time)
Error while executing automation automation.nagrywaj_osoby_z_kamery_podjazd_przod. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 437, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 190, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 274, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 357, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1236, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1261, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 348, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 372, in _handle_service_platform_call
    await func(entity, data)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 712, in async_handle_record_service
    DOMAIN_STREAM, SERVICE_RECORD, data, blocking=True, context=call.context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1236, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1261, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 132, in async_record
    await async_handle_record_service(hass, call)
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 237, in async_handle_record_service
    raise HomeAssistantError(f"Stream already recording to {recorder.video_path}!")
homeassistant.exceptions.HomeAssistantError: Stream already recording to /config/recording/20191209-083038_czlowiek_podjazd_przod.mp4!

As can be seen, the log from 7pm on Dec 10th reports a problem recording a file from Dec 9th apparently started at 8:30 AM!
The weird thing is, it recorded another video 2h later (as it should, because a person was detected) but it failed recording anything since then. I’ve tested that the trigger works and it indeed does - it’s just that the recording fails.

I thought that maybe because on the same binary sensor I’m using two different automations - one to send me a snapshot via telegram and the other to record. But they have different conditions, because I want to get snapshot only when my alarm is armed away, but I want to record all the time a human being is detected, regardless of the alarm status…

The relevant bits from my automation.xml below:

- id: '1569783718678'
  alias: "osoba podjazd przod"
  trigger:
  - entity_id: binary_sensor.osoba_podjazd_przod
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: alarm_control_panel.drewutnia
    state: armed_away
  action:
  - data:
      message: czlowiek na podjezdzie
      data:
        photo:
          - url: http://192.168.0.24:5000/podjazd_przod/best_person.jpg
            caption: "wykryto czlowieka na podjezdzie"
    service: notify.automatyczny

- id: '1569783718683'
  alias: "nagrywaj osoby z kamery podjazd przod"
  trigger:
  - entity_id: binary_sensor.osoba_podjazd_przod
    from: 'off'
    platform: state
    to: 'on'
  action:
  - service: camera.record
    data:
      entity_id: camera.podjazd_przod
      filename: "/config/recording/{{ now().strftime('%Y%m%d-%H%M%S') }}_czlowiek_podjazd_przod.mp4"
      duration: 30
      lookback: 5

…and the binary sensor is configured as such (I’m using frigate for human detection and it does work without any problems: https://github.com/blakeblackshear/frigate)
Also, the notification via telegram always works too, so it does seem to be a problem with the camera.record function…
I have a pretty standard IP camera for which I’m using a RTSP over TCP connection.

camera:
  - platform: generic
    name: podjazd_przod
    still_image_url: http://127.0.0.1:8123/local/mylocal.png
    stream_source: rtsp://192.168.1.11/H264

If anyone has any idea what’s happening here, please share :slight_smile:
Thanks in advance!

Hi internetix,

Sorry for the late response. I didn’t saw your response until i just opened a new one. Sound like your struggling with the same issue. It has been very quiet on this post for some time that i almost forgot.

At the moment a bit tight in time but like to pick this up maybe in a couple of weeks when it is a bit more quiet here. And who know maybe someone out there has the solution or know the cause.

Will let you know when i am picking up on this. Thanks for replying!

No worries. In the meantime I had to rebuild my HA due to a disk failure. I’m still getting the same errors but now they seem to be occurring even more often resulting in no video recordings at all. I’m using frigate ( https://github.com/blakeblackshear/frigate ) to trigger the recording.
I have no idea how to debug this further :frowning:

Today did some more troubleshooting but can’t find a solution.
Also found out if i enable the stream integration my camera’s also do not work anymore in the frontend.

Tried:

sudo apt-get install -y python-dev pkg-config libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev libavfilter-dev

Camera setup: (coming from iSPY)

camera:
  - platform: badnest
  - platform: buienradar
  - platform: ffmpeg
    input: http://192.168.13.10:8080/mjpegfeed?oid=1&full
    name: Balkon
  - platform: ffmpeg
    input: http://192.168.13.10:8080/mjpegfeed?oid=5&full
    name: Gang  

Automation:

- id: test123
  alias: Voordeur Notificatie
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d0002e8b414
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: device_tracker.life360_daniel_jansen
    state: away
  action:
  - data:
      duration: 2
      entity_id: camera.gang
      filename: /home/homeassistant/.homeassistant/secure/voordeur.mp4
    service: camera.record
  - data:
      data:
        video:
        - caption: Video Title xy
          file: home/homeassistant/.homeassistant/secure/voordeur.mp4
      message: '{{now().strftime("%H:%M %Y-%m-%d")}}: Voor deur is open geweest.'
      title: '*Voordeur sensor is getriggerd*'
    service: notify.telegramdaniel

Secure folder config:

  customize: !include customize.yaml
  packages: !include_dir_named packages
  whitelist_external_dirs:
    - /home/homeassistant/.homeassistant/secure

Folder permissions:

root@homeassistant:~/.homeassistant# ls -ls | grep secure
      4 drwxrwxrwx 3 homeassistant homeassistant       4096 Jan 30 19:56 secure
root@homeassistant:~/.homeassistant# pwd
/home/homeassistant/.homeassistant

---------

root@homeassistant:~/.homeassistant# cd secure/
root@homeassistant:~/.homeassistant/secure# pwd
/home/homeassistant/.homeassistant/secure
root@homeassistant:~/.homeassistant/secure# ls -ls
total 3912
   4 drwxrwxrwx 2 homeassistant homeassistant    4096 Jan 17 20:35 motion
 904 -rwxrw-rw- 1 homeassistant homeassistant  923427 Jul  4  2019 plant2.jpg
2732 -rwxrw-rw- 1 homeassistant homeassistant 2797074 Jul  4  2019 plant.gif
 272 -rwxrw-rw- 1 homeassistant homeassistant  278222 Jul  4  2019 plant.mp4


Error logs:

Blockquote
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 INFO (MainThread) [homeassistant.components.automation] Executing Voordeur Notificatie
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 INFO (MainThread) [homeassistant.helpers.script] Script Voordeur Notificatie: Running script
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 INFO (MainThread) [homeassistant.helpers.script] Script Voordeur Notificatie: Executing step call service
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 INFO (MainThread) [homeassistant.components.stream] Started stream: http://192.168.13.10:8080/mjpegfeed?oid=5&full
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 INFO (MainThread) [homeassistant.helpers.script] Script Voordeur Notificatie: Executing step call service
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 WARNING (SyncWorker_19) [homeassistant.components.telegram_bot] ‘home/homeassistant/.homeassistant/secure/voordeur.mp4’ are not secure to load data from!
Jan 30 20:17:04 homeassistant hass[18165]: 2020-01-30 20:17:04 ERROR (SyncWorker_19) [homeassistant.components.telegram_bot] Can’t send file with kwargs: {‘title’: ‘Voordeur sensor is getriggerd’, ‘message’: ‘21:17 2020-01-30: Voor deur is open geweest.’, ‘caption’: ‘Video Title xy’, ‘file’: ‘home/homeassistant/.homeassistant/secure/voordeur.mp4’}
Jan 30 20:33:55 homeassistant hass[18165]: 2020-01-30 20:33:55 INFO (MainThread) [homeassistant.components.automation] Executing Voordeur Notificatie
Jan 30 20:33:55 homeassistant hass[18165]: 2020-01-30 20:33:55 INFO (MainThread) [homeassistant.helpers.script] Script Voordeur Notificatie: Running script
Jan 30 20:33:55 homeassistant hass[18165]: 2020-01-30 20:33:55 INFO (MainThread) [homeassistant.helpers.script] Script Voordeur Notificatie: Executing step call service
Jan 30 20:33:55 homeassistant hass[18165]: 2020-01-30 20:33:55 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.voordeur_notificatie. Unknown error for call_service at pos 1:
Jan 30 20:33:55 homeassistant hass[18165]: Traceback (most recent call last):
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/automation/init.py”, line 449, in action
Jan 30 20:33:55 homeassistant hass[18165]: await script_obj.async_run(variables, context)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 189, in async_run
Jan 30 20:33:55 homeassistant hass[18165]: await self._handle_action(action, variables, context)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 272, in _handle_action
Jan 30 20:33:55 homeassistant hass[18165]: await self._actions[_determine_action(action)](action, variables, context)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 354, in _async_call_service
Jan 30 20:33:55 homeassistant hass[18165]: context=context,
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 96, in async_call_from_config
Jan 30 20:33:55 homeassistant hass[18165]: domain, service_name, service_data, blocking=blocking, context=context
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1226, in async_call
Jan 30 20:33:55 homeassistant hass[18165]: await asyncio.shield(self._execute_service(handler, service_call))
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1251, in _execute_service
Jan 30 20:33:55 homeassistant hass[18165]: await handler.func(service_call)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py”, line 201, in handle_service
Jan 30 20:33:55 homeassistant hass[18165]: self._platforms.values(), func, call, service_name, required_features
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 335, in entity_service_call
Jan 30 20:33:55 homeassistant hass[18165]: future.result() # pop exception if have
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 359, in _handle_service_platform_call
Jan 30 20:33:55 homeassistant hass[18165]: await func(entity, data)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/camera/init.py”, line 711, in async_handle_record_service
Jan 30 20:33:55 homeassistant hass[18165]: DOMAIN_STREAM, SERVICE_RECORD, data, blocking=True, context=call.context
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1226, in async_call
Jan 30 20:33:55 homeassistant hass[18165]: await asyncio.shield(self._execute_service(handler, service_call))
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py”, line 1251, in _execute_service
Jan 30 20:33:55 homeassistant hass[18165]: await handler.func(service_call)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/stream/init.py”, line 111, in async_record
Jan 30 20:33:55 homeassistant hass[18165]: await async_handle_record_service(hass, call)
Jan 30 20:33:55 homeassistant hass[18165]: File “/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/stream/init.py”, line 217, in async_handle_record_service
Jan 30 20:33:55 homeassistant hass[18165]: raise HomeAssistantError(f"Stream already recording to {recorder.video_path}!")
Jan 30 20:33:55 homeassistant hass[18165]: homeassistant.exceptions.HomeAssistantError: Stream already recording to /home/homeassistant/.homeassistant/secure/voordeur.mp4!

Big Big Big thanks to who knows the solution!

1 Like

hello @djansen1987 @internetix ,

have you find a solution please?

same for me, no record at all, the stream work in HA and in motioneye but no records…

Thanks

Hi, I switched to MotionEye via HassOS add-on store. From there i manage the recordings.
Only bit where i am now stuck on is how to display the camera feeds from MotionEye to HA

thanks for your reply, i do the same but i cant manage to use automation with the cam…like recording only if i m not home…

here is my config if you want the feed in ha :

camera : 
  - platform: mjpeg 
    name : CamPiZero 
    still_image.url: http://192.168.1.xx:8765/picture......>  GO TO Useful URLs [SnapshotURL] in MotionEye serverof the Pi
    mjpeg_url: http://192.168.1.xx:8081 /mjpeg 
    username: user name in motioneye addon
    password : password in motioneye addon

after that you will have an entity camera (for me camera.campizero ) and you can use it in a glance card.

the still image url comes from motion eye server url on the pi Go to “Video Streaming” then Useful URLs [SnapshotURL] copy the URL and paste it in configuration.yaml after “still_image.url”.

And if you find a solution to only record when “somebodyhome” is false…i am interested by your solution, because at every detection motion, the cam record the video and i just want that if i m “not home”.

Enjoy!

Hi Olivier,

Finally had the time to test with it. It worked except for the still image, it was not allowed in the config and gave me an config error. Without it it worked as i liked. Thanks!

Nice ! Happy for you

but for still_image , are you sure you use the right platform? :

- platform: mjpeg 

?

because it works perfect for me, i just copy the link provided for still_image in motion_eye server of the Pi-Zero…
Strange…

1 Like

Also having the same issue on 2 different h.a instances. Mine and my friends one that i set up for him. My automations all work correctly but the record function seems to throw the exact same error intermittently. Quite annoying because it happened around the exact same time somebody stole about 1500bux worth of stuff off him and there are no recordings to show him wtf happened which sucks! It really does seem to be a issue with the camera.record function. Is there any way to let the devs of h.a know so they can implement a fix?

Still no Solution to this ?
i have the same problem and only restarts fix this