Templating "camera_image" in picture-elements!?

Hello everyone,
i don’t understand why this template doesn’t work?

type: picture-elements
image: /local/images/camoff_cell.png
camera_image: |
        [[[
          if (states['switch.cam_privacy'].state == 'off' )
            return "camera.cam_hd_stream";
          return "";
        ]]]

camera_view: live
aspect_ratio: "1.3"
elements:
.....

I also tried like this:

type: picture-elements
image: /local/images/camoff_cell.png
camera_image: |
  {% if is_state('switch.cam_privacy', 'off') %}
    camera.cam_hd_stream
  {% else %}
    ""
  {% endif %}
camera_view: live
aspect_ratio: "1.3"
elements:
.....

can someone help me?

You may keep trying with other unsupported staff - but better read Docs & see what is supported.
Templates are not supported by picture-elements card.
Your only possible way is to place picture-elements card inside a “wrapper” card which does support templates - like config-template-card, card-templater. Each card has docs & dedicated threads in Community, you may ask details there.

ok…maybe it can be useful to someone else: I solved it like this:

type: custom:config-template-card
variables:
  PRIVACY: states['switch.cam_privacy'].state
entities:
  - switch.cam_privacy
card:
  type: picture-elements
  image: /local/images/camoff_cell.png
  camera_image: "${PRIVACY === 'off' ? 'camera.cam_hd_stream' : ''}"
  camera_view: live
  aspect_ratio: "1.3"
  elements:
  .....

Thank you!

1 Like

Never tested camera entity inside config-template-card (CTC), does it work fine?

it works great!