what is the best way to publish a camera snapshot for download? It doesn’t have to be open web - local network is ok.
I’m doing camera snapshot every day at noon and want to use that photo on other machine. /local folder is not ok for this because of aggressive caching. The other machine can download image with static url. Can I turn off the cache for specific folder? What are my other options? nginx url rewrite?
i dunno about “best”, but here’s a grab from one of my scripts:
- target:
entity_id: camera.am_garage
data:
filename: /config/www/tmp/garage.jpg
action: camera.snapshot
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- target:
entity_id: camera.am_garage
data:
filename: /config/www/tmp/garage_a.jpg
action: camera.snapshot
- data_template:
message: |
garage door {{ door }}
http://homeassistant.local:8123/local/tmp/garage.jpg
http://homeassistant.local:8123/local/tmp/garage_a.jpg
title: garage snapshot {{ now().strftime('%H:%M:%S')}}
data:
images:
- /config/www/tmp/garage.jpg
- /config/www/tmp/garage_a.jpg
action: notify.homeassistant_gmail
this is invoked when a garage door opens. then it takes 2 snapshots (let’s me see if someone’s coming vs going) and sends them to me both as an attachment as well as the url for download.
Yes ok. But when you open this url the image is cached for 31 days. So next time you open it it will show you old image. That is unless hass was restarted. So this is not good for publishing an image. For push it works ok.
again “best” is subjective but there are numerous Blueprints on the Forum that can do (some of) this…
Have a look at this one for example and you could tweak to suit your needs
‘best’ would be the one that actually work. I have a script that makes a snapshot every day and saves the image. Then it can also be downloaded externally from /local path. Problem is that this method also makes the image cached so next day I cannot see any newer picture. You can even delete the original image and web server will still serve you with cached version. So camera snapshot is ok but then what?
you can change the name from a fixed name to one that encodes the date/time so that it’s not the old image
Sure but then the download side needs to know or calculate proper download filename which is not always possible. So my question is still valid. What is the best way to publish camera snapshot for automated download?
What I’ve tried and failed as not working:
- adding ?v=something to the download url: it just doesn’t work. Image is cached, parameter has no influence on that
- using /api/camera_proxy/camera.mycamera?token= long-lived tokens don’t work here
- using image url from Media Sources browser: url has parameter authSig but the token used there is somehow one-time only and image is still cached with it. Long-lived tokens don’t work there
- nginx rewrite might help with rewriting image url but I can’t figure it out
My blueprint linked above has an option to archive snapshots.
How is this relevant?
Host the image on a webserver you control and can configure however you want (as in, turn caching off). Especially if it’s just for local access.
Set up ftp or a SCP script to send the image to the webserver, hit that webserver with your request for the image.
Ok, this looks like a viable solution. And there is even a tutorial for that Tutorial: Making your first add-on | Home Assistant Developer Docs custom addon with http server. I think this is the way