Template on lovelace card

Hi everybody,

I’m trying to do some templating inside a card to load the images from my camera depending of the device.
If I login with an smartphone it should render the low quality stream, if a login on a PC it should load the HQ stream.
But it is not working, there is no errors but the card doesn’t load the stream:

type: custom:webrtc-camera
url: >-
{% set my_test_json = states(‘binary_sensor.luz_acesa_escritorio’) %} {% if
my_test_json == ‘on’ -%}
rtsp://homeassistant:8554/casalHQ?video=all&audio=all
{%- else -%}
rtsp://homeassistant:8554/casal?video=all&audio=all
{%- endif %}
ui: true
muted: true

Can you help me please?

I do not use this card, but are you sure it supports templating? Many cards accept statis parameters. From card documentation I can see that it hase (somehow limited?) support for JavaScript templates:
New in v3.6.0.

  • Card options shortcuts, style and ptz supports JavaScript templates
  • In shortcuts and style you can use states related templates
  • In ptz you can use streamName/streamID related templates (useful for card with multiple templates)

Perhaps you could use custom:config-template-card to force templating of proper strems?

1 Like