Help: Templating URL for Generic IP Camera

Generic IP Camera supports templating of the URL.

I have used this with a ping detect sensor to change the URL to a locally hosted .jpg file (by adding it to the ./www/ folder) so when the device is offline it shows a placeholder image in its place, which helps to maintain the grouping and layout in home assistant.

The blank image works fine when the device is offline, but it does not switch over to live URL when the ping sensor changes from off to on.
Anyone have any ideas?

Code:
- platform: generic
framerate: 1
name: !secret image_url_name_1
still_image_url: >
{% if is_state(“binary_sensor.image_1_source_online”, “on”) %}
!secret image_url_1
{% else %}
https://localhost/local/blank_te_display.jpg
{% endif %}

My guess would be that the template is only evaluated when the component is being setup - i.e., when the configuration is read during initialization.

Actually, after browsing the code some more, it may actually evaluate the template every time it tries to grab a still image. So then the question becomes, when does it try to grab a new still image?

Or, could it be that using !secret image_url_1 in a template doesn’t work? Maybe you could try creating an input_text that is initialized to that secret and use it instead, something like:

input_text:
  image_url_1:
    initial: !secret image_url_1

camera:
  - platform: generic
    framerate: 1
    name: !secret image_url_name_1
    still_image_url: >
      {% if is_state('binary_sensor.image_1_source_online', 'on') %}
        {{ states('input_text.image_url_1') }}
      {% else %}
        https://localhost/local/blank_te_display.jpg
      {% endif %}

Yes the issue is down to !secret variable not being added to the code at compile time.
I found a way to make it work here, but it’s a hack and not ideal: Make secrets available in templating engine