Show the current image in Homeassistant
I have a Raspberry Pi Zero with camera that takes a photo every hour of a Minol heat usage meter. To monitor if the photo was taken, I want to take an occasional look at the current image. So I want to see the image in the Homeassistant dashboard. Of course we don't want to send the image because of size, a url to the image would be nice.
There are multiple options. For me it is not totally clear how often they reload the image. And because my image is only updated once an hour the difference is possibly high, but not very often.
But before we can add the image to the Homeassistant dashboard we need a webserver to give us the current image.
The obvious solution to get a webserver for me is using Python with python3 -m http.server
and then surf to http://IP-ADDRESS:8000/
.
This works of course, but needs some glue (i.e. systemd) to be run in the background and after a reboot.
So the more standard way is to use nginx here.
Install nginx on Raspberry Pi:
Then add to default server section in /etc/nginx/sites-available/default
:
This adds /images/
to the webserver.
After reloading nginx with sudo systemctl reload nginx
the contents of the images folder is surfable.
For me at this url: http://192.168.0.78/images/
.
Next we need a symlink to the current image. I don't want to interfere with the scripts that shoots the photo, so we do this purely with shell commands on the filesystem:
( cd /home/pi/images; ln -sf $(find 20* -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1) current.jpg )
An example of an image name is 2024/10/1730046301.jpg
-- so to be sure not to symlink current.jpg
to current.jpg
I search only for 20*
.
The printf
here prints first the creation time and then the filename.
After the sort
(using the creation time), the time is removed with cut
and the last line is used.
Now we have a current.jpg
symlinking to the current minol image.
Next we add the image to the Homeassistant dashbaord.
First option is to add an image url via /config/helpers
and Create Helper
.
This feels a bit intransparent.
I don't know how long this image is cached.
On the other hand when I looked after a few hours at the card the image was up to date.
So maybe this is enough here.
The second option shows the reloading live. Using the generic Camera integration with the link to the image as still image. The only other thing needed here is to disable SSL verification. The still image will update regularly (a bit too often for my 1h new photo but I actually don't care enough). Obviously the updates are often because it is meant to be an actual live camera.
The two options look like this for me:
As you see it is dark at the moment of the screenshot and I have no additional light for my minol cam. The top card is the Generic Camera and the bottom card is the picture card. But this is exactly what I want to have. I will keep the generic Camera option, because it shows the reload with a live progress loading circle.