Cache Image of last activity from camera

So I’ve made a lovelace page that shows the my camera feed and a still image of the last detected event.
My issue is that the still image gets cached and I want it to update… So I figured to fix this I would add ?timestamp to the url to force it to reload (since it would believe it to be a new picture)
here is what I’ve got for the still image…

  - type: picture
    image: >-
      https://###.duckdns.org/local/cam_capture/FROffice.latest.jpg?{{
      states('sensor.date_time_iso') }}
    tap_action:
      action: url
      url_path: >-
        https://###.duckdns.org/local/cam_capture/FROffice.latest.jpg?{{
        states('sensor.date_time_iso') }}
    hold_action:
      action: none

But unfortunately it will not take the template data. From what I have read, the URL is a string and does not accept template data.
Any tips for getting around this??

Thanks
Chris

Have you tried it as a test just using any number such as {{ 1234 }}? It might help you to narrow down if the issue is with the date stamp in the url (that may need to be URL encoded) or if it’s the query in general.

The path displayed in the url bar is
http://xxxx/xxx/xx/FROffice.latest.jpg?{{ states(‘sensor.date_time_iso’) }}
and when I put that information into the template section of dev tools it outputs the time
http://xxx/xxx/xx/FROffice.latest.jpg?2021-01-22T15:57:00

URL’s don’t generally native colons, they get encoded when entered into a URL. I would try it, just as a test, with a static value or instead of using an ISO date use a numeric timestamp instead or use a YYYYMMDDHHMMSS format without any extraneous text.

I just came across this related thread which might help you.

I’ll check that thread now – {{ as_timestamp(states(“sensor.date_time_iso”)) }}
and the url came up with FROffice.latest.jpg?{{%20as_timestamp(states(“sensor.date_time_iso”))%20}}
dev tools show - FROffice.latest.jpg?1611349680.0

thanks for your help btw

I think the timestamp is a better way to go, past that if the URL still doesn’t cache it might be related to that other thread that had similar problems using dynamic URL’s in camera images.

Well, it’s been problematic… I didn’t have much success with that route so I abandoned ship.
I ended up adding a command to node red to force it to do what I wanted…
Basically when an image is generated, node red will overwrite the associated lovelace file and put a timestamp on the image for me.

I already had node red sending me android alerts anyways so I just plugged in a function node to handle updating the data.

This has a much lower overhead than the jinja template card linked in that topic above by CO_4X4:

It uses javascript for the templates.