Using a template to set a url variable?

Hello,
I am trying to set a url variable via template based on a helper binary sensor. I put the template into the template viewer and I get the correct results but when I try using it in my lovelace dashboard it does not work.

           {% if is_state('input_boolean.enable_front_camera_stream', 'on') %}
              'rtsp://ffffffff-ring-mqtt:8554/ffffffff_live'
            {% else %}
              ''
           {% endif %}

Pasting that into the template viewer I get the expected result.

Below is my lovelace code to view the rtsp stream:

        - type: custom:webrtc-camera
          url: >
           {% if is_state('input_boolean.enable_front_camera_stream', 'on') %}
              'rtsp://ffffffff-ring-mqtt:8554/ffffffff_live'
            {% else %}
              ''
           {% endif %}

Now I have tested the url directly and things work so I know the url and compoent all work as I expect. Any help would really be appreciated!

Templating is not available on many cards. Since none of the examples on the git for Webrtc Camera card show the use of templates, it is likely than they cannot be used. You may be able to use Lovelace Card Templater to enable templating on the Webrtc card.

Not sure what you trying to achieve…guessing … what you could do is use the conditional card that shows you this one only if the sensor is ‘on’

Yeah, apologies for being cryptic. Right now my ring camera works great in the webrtc card, however ring isn’t really intended to stream continuously. So, what i’m trying to get is when motion is detected it will show the stream of the camera on my display. What i’m getting though is that the webrtc stream will always stay connected (which I don’t want, I only want to open a stream when detecting motion).

I set this all up with a conditional card in the hopes that would do it but it seems conditional cards don’t actually de-activate when hidden so the stream never closes even if hidden. So I’ve been trying to find some conditional way I can enable/disable the rtsp stream based off my motion event.

Interesting find. The card/stream visibly (re)builds when switching to a dash/page but indeed seems to stay alive when ‘hidden’. Not what you want but… I am using a tablet to show the camera in a fullscreen (page) dashboard (separate view) when motion is detected, then it indeed builds but the build is not very fast (with me)

Check this maybe ? It allows switching to cams based upon motion
custom-cards/surveillance-card: A custom component for displaying camera feeds in the style of a surveillance system. (github.com)

Thanks for the suggestion. Tried that but still suffers from the stream always staying open.

And did you try what @didgeridrew suggested above?

Not yet, that will be the next try. Hopefully get a chance to try it out tomorrow. Will report back!

Thanks again!

I got it working on my camera (camera.nas_thuis_tp_voordeur) with motion sensor (binary_sensor.tapo_camera_545d_motion)

type: custom:card-templater
card:
  camera_view: live
  type: picture-glance
  camera_image_template: >
    {% if states.binary_sensor.tapo_camera_545d_motion.state == "on" %}
    camera.nas_thuis_tp_voordeur 
   {% else %} 
  nothing 
  {% endif %}
  title_template: '{{ states.binary_sensor.tapo_camera_545d_motion.state }}'
  entities: []
entities:
  - binary_sensor.tapo_camera_545d_motion

Nice one! that did the trick!

Thanks for all the help, have a great day!

Thanks goes to @Didgeridrew

Totally, thanks to both @Didgeridrew and @vingerha !