sibbl / hass-lovelace-kindle-screensaver

This tool generates a png from a Home Assistant Lovelace view, which can be displayed on a Kindle device which has the Online Screensaver plugin installed.
MIT License
311 stars 71 forks source link

add timstamp to image name #79

Closed cryptooth closed 4 months ago

cryptooth commented 11 months ago

Is it possible to add timestamp to output image name? Like output_2023_08_11.png? I'm using on my HA setup. But sometimes HA sending same (cached) image to my Phone. If output image name has timestamp, we can solve the caching problem.

thank you.

sibbl commented 11 months ago

Hey,

what exactly do you mean with "sending same (cached) image to my Phone"? The server is meant to never sent an image somewhere. It's always pulled by some browser or other http client. May I ask which specific http client you're having issues with?

What the server already does is telling the requesting client when the image was last modified. We send this as part of the Last-Modified HTTP header already. Browser and http clients should be able to tell by only fetching the HTTP headers whether they need to fetch the image from the rest of the response or skip it, which means they can use the cached image.

I'm also not sure where exactly you want to put the "output image name". The image is always available under the same URL by design. Which HTTP header are you specifically referring to in your suggestion? I know that you could pass a filename in the Content-Disposition header but I found no hints that this would help with caching issues.

I'd be happy to improve caching and would appreciate some input regarding the specific problem you have.

cryptooth commented 11 months ago

Sorry for my poor explanation.

With this docker image, I take screenshots of some views in Homeassistant, putting a shared folder with HomeAssistant, and send them to my mobile phones via WhatsApp (RapidAPI) or by push notification using the notify feature in HomeAssistant periodically during the day.

But sometimes outdated photos come to my phone. So I thought maybe I could solve this cache problem by adding a timestamp to the end of the screenshot's name.

I'm also open to another suggestion.

Thank you

sibbl commented 11 months ago

Thanks for the explanation, that sounds like an interesting use case!

Maybe a quick fix could be that you manually add any ?t=123 parameter to the URL you send to your phone, where 123 is either a random or at least a unique id like the current timestamp for your case (e.g. ?t={{ now() }} with HA templating).

This should also enforce the push notification to not cache the request.