go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

Allow to import more camera entities from Home Assistant

Open felipecrs opened this issue 2 years ago • 3 comments

I have a Tuya camera which does NOT have ONVIF, but can be accessed from within HA through the Tuya official integration.

If I could import this camera from Home Assistant to Go2RTC, I could thereafter add it to Frigate and record/detect and so on.

The current implementation for importing HA cameras is a bit hacky, I think. It reads HA internal core.config_entries file and tries to extract the rtsp URL from there.

I tried every single way to get the RTSP by using HA's APIs but it turns out that such API isn't exposed. I created a PoC for exposing a new API under HA core:

image image

Just to prove that it works. If contributed back to HA core, go2rtc could use this API to fetch this data and it would work across more integrations (confirmed to work with Tuya, for example).

Later we could improve it, so that even cameras which does not support a stream_source can be translated by using HA's still image API (by using FFMPEG to create a video out of it).

What do you think, should I go ahead and try to send it to Home Assistant? If you say you don't like it or don't want it, then I will not do it.

felipecrs avatar Oct 19 '22 04:10 felipecrs

Some cameras may have dynamic stream, like Nest. I think it makes sense to add an API to get the RTSP link to the Hass core or to the WebRTC Camera component.

AlexxIT avatar Oct 20 '22 11:10 AlexxIT

I support, I have a similar situation in the tuya doorbell, opening the rtsp stream is not possible due to the closed tuya software. Did you manage to redirect video stream from TUYA integration to WebRTS/go2rtc/Frigate ?

sacredx72 avatar Oct 21 '22 08:10 sacredx72

Did you manage to redirect video stream from TUYA integration to WebRTS/go2rtc/Frigate?

Yes, but I suspect that the URL changes over time so what works now may not work so soon -- we would need an automated way instead. Anyway, setup the RTSPToWebRTC integration in Home Assistant with go2rtc, then start a stream with the doorbell from within Home Assistant. While the stream is happening, go to go2rtc web interface, find the doorbell in the list and right-click the RTSP link, copy it and do whatever you want.

felipecrs avatar Oct 21 '22 12:10 felipecrs

Could you briefly describe how you did it, which RTSP link you provided in RTSPToWebRTC / go2rtc ? judging by the screenshots for redirecting the RTSP stream, you specified IP 192.168.1.33:554 - is this the address of your server? I'm not much of a pro at reviewing code in built-in HA modules =) I still hope that support for closed TUYA cameras without built-in support for open RTSP will appear in AlexxIT integration =)

sacredx72 avatar Oct 27 '22 16:10 sacredx72

The easiest way without tinkering with HA source code is to:

  1. Setup RTSPToWebRTC integration in Home Assistant to connect with go2rtc
  2. Start a stream from HA using for e.g. the picture glance card
  3. Keep the stream running in a tab
  4. Go to go2rtc web interface, locate the camera in the list (it will be automatically added there), click in info
  5. You can get the original RTSP URL from there:

image

felipecrs avatar Oct 27 '22 16:10 felipecrs

@AlexxIT here's the Home Assistant PR:

  • https://github.com/home-assistant/core/pull/81755

It works nicely when the camera is added through the ONVIF integration, and also works nice for Tuya cameras from the official Tuya integration. The Tuya-based urls seems to follow this pattern:

rtsps://echo:<varies>@wework-1-us.stream.iot-11.com:443/v1/eb830d5699d76538167li8/<varies>?signInfo=<varies>

But there's a catch, it seems that:

  1. These URLs expires quickly if no client connects on them (I'd say 5 seconds), then a new URL has to be fetched

go2rtc needs to take this into account, i.e. auto-renew URLs.

Of course go2rtc also needs to authenticate, which is easy if running as add-on since the SUPERVISOR_TOKEN is injected automatically as an environment variable and can be used to communicate with http://supervisor/core/api/camera_stream_source/.

felipecrs avatar Nov 08 '22 00:11 felipecrs

Ok. We need to wait when changed will be accepted. Anyway it can be used with echo source.

AlexxIT avatar Nov 08 '22 04:11 AlexxIT

Hi, since I don't think this will get integrated in HA core, I published a custom integration for it:

https://github.com/felipecrs/hasss-expose-camera-stream-source

It also comes with a guide on how to use it to import Tuya or other cameras from HA to go2rtc and even Frigate:

https://github.com/felipecrs/hass-expose-camera-stream-source#importing-home-assistant-cameras-to-go2rtc-andor-frigate

  • Note that it requires: https://github.com/AlexxIT/hassio-addons/pull/21

felipecrs avatar Nov 08 '22 15:11 felipecrs

If someone has a Nest camera, it would be interesting to test if it also works for it. I tested for Tuya and ONVIF.

felipecrs avatar Nov 08 '22 15:11 felipecrs