Trying to display an image from local folder in HS

hey guys, quite new to home assistant , i would appreciate if someone can point me in the right direction … i have an IP cam setup to display a permanent stream in HA, but it also take 4 pictures and saving them to my nas, i’m looking for a way to display the latest image saved in HA … anything in HA that could support that ?

Give Local file camera a go.

Thanks I’ll give it a shot tonight

I had seen it previously but having a different image name for every pictures prevented me from using it

What I will try ,

Running an incron folder monitor to move and rename the newest picture in the watched folder and move it to another folder overwriting the image I’m watching with the local file component

That should work :slight_smile:

I was yo focus on using only HA to do it but that combination should work :slight_smile:

I’ll post the results later tonight if it is of interest !!

Thanks for the suggestion , it provided me the basic idea to come up with that one

I’m interested; even if for nothing else than more knowledge. Thanks!

Sorry i’ve been to busy last night , we’ll do it this weekend and get back to you then :slight_smile:

1 Like

No rush; you’re not on a clock here! Thanks!

Ok just a quick update :slight_smile:

I reconfigured the HASS for my camera,
Configured a NAS drive to accept all the photos taken
Mounted a drive from Raspbian to that NAS
Added a symlink to that mount that is residing in the .homeassistant folder

then configured my incron job to monitor move and rename the files to be able to fetch it with the camera local component.
It worked well for the first hour , i was able to get the new file created / moved and renamed to the destination drive but then …

Stopped working as my camera is creating a structure per hour to store the file .
Which means that my photos are stored into a structure like this : Photos/date/hour/photoname.jpg

This is more complicated than i thougth . as not being that good in bash , i will need some reading to try to monitor each daily/hourly created folders and move / rename the file to the folder i’m monitoring with the local camera component.

Any help for a general bash script that i could use to do the job which i would run as action from my file watcher.

i will anyway work on it , but it might be faster with a small hand :slight_smile:

thanks

1 Like

Hi,
I have a similar problem. My Webcam stores images when motion was detected. I did a python script which makes an animated gif with timestamp of only the images where a significant change was detected (remove small changes due to illumination changes).
I store this file (res.gif) at ~/.homeassistant/www/
in the configuration I use:

camera:

  • platform: local_file
    file_path: /local/res.gif
    name: AniGiflocalGIF

but this is not working (identation is correct - I just did not get the spaces into the post)
I can’t find the reason for this in the documentation
Any ideas?
BR,
Daniel

Hi all,
I got it working now using:

file_path: /home/pi/.homeassistant/www/res.gif

ist not as descirbed the relative path of the www directory of hass - its the absolute path…

I am setting up my camera pictures from FTP and would like to use your python script for moving files and creating animated gifs. Any chance in sharing?

Hi,
The source for image2gif can be found at

I wanted to attach my script, but this in unfortunately not allowed.
Feel free to copy and adapt the following lines:

[details=Source Code][code]

-- coding: utf-8 --

“”"
Created on Tue Nov 15 22:35:50 2016
Test script to get images (FPT ipcam images) and generate animated gif

Tasks:
* needs mout of ftp / load images from ipcam
* check the newest x images
* only select interesting images - reduce by similariy to previous image
* store similarity data (not done yet)
* generate gif image (or animated png)

Requirements
pip install apng

Links:
- https://github.com/isaacgerg/images2gif
- http://docs.python-guide.org/en/latest/scenarios/imaging/
- http://stackoverflow.com/questions/753190/programmatically-generate-video-or-animated-gif-in-python
- https://www.sitepoint.com/manipulating-images-with-the-python-imaging-library/
- http://code.activestate.com/recipes/577630-comparing-two-images/

@author: Daniel
use with MIT License (MIT)

“”"

import os
from apng import APNG

def calsimI1I2(I1, I2):
‘’’ calculate similarity of two images by histogram RMS ‘’’
h1=I1.histogram()
h2=I2.histogram()
rms = math.sqrt(sum(map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
return rms

#%%
import math
from functools import reduce
import glob
import math, operator
import datetime as dt
from PIL import ImageDraw
from PIL import ImageFont
from PIL import Image, ImageSequence
import time
from images2gif import writeGif

#%%
print(“Start”)
files=sorted(glob.glob(“I:\ipcam*.jpg”), key=os.path.getmtime)

db=[]# list with file informations
counter=0
for f in files: # go through files
path,fnext=os.path.split(f)
fn,ext=os.path.splitext(fnext)
db.append({‘FileName’:fn,‘Time’:os.stat(f).st_mtime,‘AnalyzedFlag’:0,‘Use’:0})
counter += 1

print(“Filelist generated”)
#%% do image comparison
counter = 0
frames=[]
framecounter=0
path,fnext=os.path.split(files[0])
framenew=Image.open(path+’\’+db[-1][‘FileName’]+’.jpg’)
im = APNG()
N=600
for i in range(1,N):
print(i)
print(db[-i][‘FileName’])
file=path+’\’+db[-i][‘FileName’]+’.jpg’
frameold=Image.open(file)
res=calsimI1I2(frameold,framenew)
db[-i][‘S’]=res
framenew=frameold
draw = ImageDraw.Draw(framenew)
font = ImageFont.truetype(“arial.ttf”, 36)
mydt=db[-i][‘Time’]
draw.text((0, 0),time.ctime(mydt), font=font, fill=(255,0,0,255))
del draw
#db[k][‘AnalyzedFlag’]=1 # TODO later
print(‘Similarity’ + str(db[-i][‘S’]))
if res>N:# check max 600
frames.insert(0,framenew.copy())
im.append(file, delay=500)
framecounter +=1
if framecounter>30:# 30 frames are enough
break

export

writeGif(path+"\res.gif", frames, duration=.65, dither=0)
im.save(path+"\res.png")
path=‘R:\home\pi\.homeassistant\www’
writeGif(path+"\res.gif", frames, duration=.65, dither=0)
im.save(path+"\res.png")
print(“ready”)
[/code][/details]
It was just a quick and dirty try to filter the recorded ipcam images, but works nice.

3 Likes

Thanks, ill take a look