BUT, my phone is caching the image, and I receive the same image every time.
I’ve found out that if the phone receives “https://mysite.duckdns.org/local/tmp/snapshot.jpg?(random number)” it will pull the correct file, not the cached version.
but, it fails to run at all. Home assistant recognizes it as a valid configuration, and I see no errors in the log, but, I don’t get any notifications.
Is someone able to help me understand what I’m doing wrong, and/or provide another option to do what I’d like. I am not a programmer. I run Hass.io in a docker on a virtual machine.
I suspect the problem is you’re saving the snapshot using one filename, but then calling the notify service with a different filename. I’d try adding a first action step that saves the random filename to an input_text, then use that in both of the other action steps. Something like:
Actually, though, using a random number (either way) I think can still potentially cause two consecutive invocations to use the same filename, resulting in the original problem. Rather than a random number, I’d suggest using a Counter, and increment it each time in the first step, then use that (instead of the input_text.) That way each time the filename would be different. And I think you could reset the counter when it gets to 2, so the filenames would just have suffixes of 0 and 1. That would probably be enough to get the browser to re-read the file.
So for anyone else stumbling across this, to prevent your phone’s browser from using a cached image in the HTML5 push notifications you can put ?{{now().second}} or a random number or similar at the end of your image URL and it will appear as a new image to your browser for subsequent notifications. But you must ensure you change data to data_template in the correct spot. See my working script example below:
Hey man, where exactly do I use this code, under automation? Or under scripts? Still new to the push notifications and would love to receive a picture of my camera on motion detected.
I’d say @jdbrookes code is intended to be used as a script as it starts with sequence.
I should be fairly straight forward to use in an automation though by removing the sequence key and adding all the code below the action key in your automation.
I suppose it could happen, but I never experienced it. Possibly chrome itself was refreshing the cache on a regular basis anyway, and with most of these notifications I might only get one or two a day.
Since then I’ve also moved over to Telegram notifications which don’t have caching issues. Html5 notifications started out great but then Google made some changes and they became slow and unreliable.
i know you are not using chrome/html5 anymore, but i want to give it one more chance, seems they have added also priority now, but i am stll struggling with my cache issue
below is my code, i am sending my nabucasa url, the snapshot_buiten.jpg is always a new image, no issue there, but indeed , when you dont add like example ?50 aftet the http:// string, it loads always the same image
so indeed adding this to the end of the string, when testing in browser, i works {{ now().second }}
but when i do the automation, i doesnt send a unique seconds number, i see that when i also add the “url” parameter, so you can actually click on the link, and it points me to :
I’m on mobile so I can’t post an example, but you need to have data_template (as per my original example, right under the service) rather than just data. That should hopefully do it