Monitoring changes in OS folder possible?

I’m fairly new to OpenHAB, but got my first site working!! :smiley:
Now I was wondering if I can somehow include pictures/movies from my IP Cam. Camera is an older Linksys and doesn’t do anything other than recording when motion triggered. The newly recorded movie is then stored on the hard drive with a filename like ‘recording time date’ (thus, the filename is different every time).
Since there is no way I can make the camera notify OpenHAB of a new file, I was wondering if I can make OpenHAB look for a new file periodically?
I’ve been scanning the various communities but couldn’t find anything along those lines.
Now I could possibly get an external program to scan the folder every few minutes, but still would have to notify OpenHAB if there were any changes (eg new file).


There are lots of ways to do this. You can write a rule with a Time trigger to poll the directory. However you will need to write the code yourself to identify when a new file appears (e.g. keep a timestamp of the last check and if there are any files more recent it is a new one). As you guess you can write a script that polls the directory and tells OH about it using MQTT or by updating an Item through OH’s REST API. You can create a script that OH calls using the Exec binding periodically that prints out if there is a new file.

Hi Rick
Thanks for the quick response. I have no experience with this so please
excuse my question if they appear obvious.
How do I poll the directory? Can I somehow read the file names (into a
variable) of the file(s) present? I could then process the string to
extract the time.


There is nothing available that I know of that you will be able to use out of the box. Polling the directory for new files is going to take some coding on your part.

In a rule you can use var String files = executeCommandLine("ls -l /my/camera/folder", 5000) and then parse files.

You can apply this tutorial and write it up in Java but be aware that while Java is available in rules, the Rules Language is not Java so a lot will be different.

Here are some ways to do it in Python.

I think we need a file binding! Items would be updated when the bound files are changed. You could read/write file metadata and contents

DateTime SnapshotDateTime "snapshot [%1$tm/%1$td %1$tH:%1$t]" { file="/var/www/html/image.jpg; value=lastmodified" }
Number MeterReading "meter reading [%.3f kWh]" { file="/var/run/meter.json; value=JSONPATH($.meter.kwh)" }
String LastLogLine "firewall log [%s]" { file="/var/log/firewall.log; data=JS(lastline.js)" }
String WriteToLog { file="/var/log/event.log"; mode=write,append" }

Note: It can be tricky to make the above work, since files may be changing while they are being inspected. A useful comparison is Apache Camel’s file component, which is very complex and flexible because of those issues. It might be better to just install the Apache Camel feature in the same Karaf container as OH2 (since it also runs on Karaf), and I could write an integration between Camel and openHAB. :wink:


Thank you. I’m happy to see that there are possible solutions. A binding
might be the way to go. I can see a whole bunch of applications for this,
like monitoring inbox files, or error logs or even something like a
personal cloud storage watcher.
Anyway I will see if I can make one of the suggestions work. Thanks for
your input.

@watou @Martli
Do we actually have some kind of file binding that can monitor new files in specific folder? I’m trying to achieve same functionality which is to monitor FTP folder and see if there are new files from my camera is there in order to get notification of motion detection.

I might try to code that binding, but no promises since it will be my first experience in writing bindings for OpenHAB.

There is no such binding to my knowledge.

@rlkoshak @watou @Martli
So I went ahead and created a binding that allows you to monitor FTP(S) and Local drive and sends events with new file name. I’d appreciate if somebody could use it and provide feedback.

1 Like

Hi Alexandr
I am very interested to try this out. I’m currently away from home but hope to try and see how it works in the next few weeks.


Sure, let me know about your experience please.