Stream Component: Confirmed Cameras and Configurations

Great work on this @hunterjm. Just had the chance to set it up with my three cameras in HA - an Amcrest and two generic Chinese IP cameras. The camera.record service works great too! For the wishlist - it’d be great to have some sort of camera.stop_record service where I could fire off an automation to start recording a stream and then stop recording at an indefinite later time (when motion has stopped, for example).

2 Likes

As an update, confirmed that if I add the user/pass it still fails. (And isn’t needed via VLC).

Does anyone have an example lovelace card they’re using for a camera? I suspect my card is just wrong…

In the browser, there is a seek bar you can use to skip closer to real-time, but you run the risk of buffering.

All in due time :wink:

3 Likes

I have Xiaomi dafang, and when I try to stream I got this:

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/websocket_api/commands.py”, line 122, in handle_call_service
connection.context(msg))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1138, in async_call
self._execute_service(handler, service_call))
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1160, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 188, in handle_service
self._platforms.values(), func, call, service_name
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 314, in entity_service_call
future.result() # pop exception if have
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 330, in _handle_service_platform_call
await func(entity, data)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/init.py”, line 653, in async_handle_play_stream_service
blocking=True, context=service_call.context)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1138, in async_call
self._execute_service(handler, service_call))
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1160, in _execute_service
await handler.func(service_call)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 188, in handle_service
self._platforms.values(), func, call, service_name
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 314, in entity_service_call
future.result() # pop exception if have
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/asyncio/tasks.py”, line 241, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 330, in _handle_service_platform_call
await func(entity, data)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/init.py”, line 581, in play_media
raise NotImplementedError()
NotImplementedError

The media player you are trying to stream to does not support the play_media service, which is used by play_stream.

Only confirmed to work on Chromecast and Apple TV.

I followed the guide in the first post, and this is the configuration that works for me. still_image_url points to the camera’s IP address, and stream_source to Unifi Protect’s IP address.

  - platform: generic
    name: Driveway
    still_image_url: https://192.168.5.x/snap.jpeg
    stream_source: rtsp://192.168.1.y:7447/abcdefgh
    verify_ssl: false

The corresponding Lovelace configuration looks like this. The still image updates every 20 seconds, and in full screen mode shows a moving image, but at just about 2 frames/second or so.

- entity: camera.driveway
  type: picture-entity

You may have already noticed that you are not actually watching the RTSP stream in your browser, but HA is proxying the video stream via HTTP. You could check if the proxy URL works in principle - it looks something like this: http://localhost:8123/api/camera_proxy_stream/camera.driveway?token=dce5b.... The full path and token is an attribute of the camera entity.

Hello,
I am using the mijia 1080p camera from this hack https://github.com/Filipowicz251/mijia-1080P-hacks.
If I enable the stream component and try to stream, no video is displayed and HA becomes unresponsive after 10-20 minutes. Without the stream component everything is fine.

Same for me, unresponsive after 10-20min but Whit other cam, so I don’t think it’s The camera

I’ve got a wyze v2 flashed with dafang hacks and it works well, but often it will show old video when I click on it to stream (with preload enabled). if I restart HA it will work again, but after 1 or 2 times trying to access the stream it like stays stuck on the last buffered preload.

It could be a bit off-topic but still related to camera.record which some people might find useful. This is still work in progress as I’m only able to test it remotely at the moment. The following automation is being triggered by hikvision binary sensors (line-crossing) which are set to only trigger once every 15 seconds and shall send a 15 seconds mp4 video clip (with 5 seconds lookback) via telegram bot:

- alias: Captune outdoor movement video
  initial_state: 'on'
  hide_entity: true
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.saturn_nvr_line_crossing_1
        - binary_sensor.saturn_nvr_line_crossing_2
        - binary_sensor.saturn_nvr_line_crossing_3
        - binary_sensor.saturn_nvr_line_crossing_4
        - binary_sensor.saturn_nvr_line_crossing_5
      from: 'off'
      to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.outdoor_motion_notify_video
    state: 'on'
  action:
    - service: camera.record
      data_template:
        entity_id: "camera.{{ {
          '1' : 'side_passage',
          '2' : 'kitchen_side',
          '3' : 'porch_roof',
          '4' : 'kitchen_roof',
          '5' : 'back_garden'
        }[trigger.entity_id[-1]] }}"
        filename: "/tmp/capture_{{ as_timestamp(trigger.to_state.attributes.last_tripped_time) | int }}_{{ trigger.entity_id[-1] }}.mp4"
        lookback: 5
        duration: 15
    - delay:
        seconds: 20
    - service: telegram_bot.send_video
      data_template:
        target:
          - !secret telegram_chat_id_alexey
          - !secret telegram_chat_id_marina
        file: "/tmp/capture_{{ as_timestamp(trigger.to_state.attributes.last_tripped_time) | int }}_{{ trigger.entity_id[-1] }}.mp4"
        caption: "Movement in {{ trigger.to_state.attributes.friendly_name }}"

I’ve added a 20 seconds delay as a test to allow sufficient time for camera.record to finish writing data to the disk. I’m using last_tripped_time of the binary_sensor to generate unique filename since using now() in two different calls could result in different filenames.

I wish there was a way of knowing if recording has finished.

EDIT: With this approach there are a lot of errors, so so I should probably allow longer delay before attempting to send the video. Unfortunately this would also cause collisions with future automations.

Can't send file with kwargs: {'file': '/tmp/capture_1554820858_5.mp4', 'caption': 'Movement in Back Garden'}

Can't load data into ByteIO: [Errno 2] No such file or directory: '/tmp/capture_1554820858_5.mp4'

EDIT 2: As a dirty workaround one could use a Folder Watcher component to watch for newly created mp4 files and send them via telegram in a separate automation. Perhaps there are better ways of doing it.

4 Likes

I tried this with the last optoin, but when I paste my generic camera entity, it still just shows a still picture and updates after 10 or 15 seconds?

It’s a Sony Android TV with Chromecast built in .

remember the TV has 2 media players, one for the TV itself and the other for the cast device, the sony android tv itself will not play it, you need to use the cast device.

Didn’t know that, I Will try it .
Thank you.

Does lookback recording works for you?

I have a strange behavior on Xiaomi dafang.
I’ve noticed that when I watch the live feed and then I close it, after about 5 minutes HA frontend crash.
Had a look in the log with journalctl and I notice that home assistant crash when it try to stop the rtsp service.
Anyone with the same problem?
Also noticed that if I turn off the rtsp server via the dafang web interface HA return to work normally.

I haven’t tried yet.

Yes, I have been experiencing some crashes, and just figured out it was instigated after atempting to watch live stream of my wyze with dafang installed.

some of us had seen some freezing and documented it here, you guys shoudl do the same: https://github.com/home-assistant/home-assistant/issues/22840