Folder sensor

Does anyone have a config for a sensor that displays the name of the last file written to a HA directory?

I am saving images with timestamps and and want the sensor to display the name of the last saved image.
Cheers

you could write a command line sensor using a shell command similar to

ls -Art | tail -n 1

Thanks! I actually want to filter the return as I have 2 files produced on each capture (lastsnap and latest), and the file I care about is timestamped. I think I need grep?

OK think I have it:

ls -Art | tail -n -3 | grep "capture.jpg"
1 Like

Hmm on Hassio the following is raising an error from a command line sensor, although the command works when I ssh in:

sensor:
  - platform: command_line
    name: new_image
    command: ls share/motion -Art | tail -n -3 | grep "capture.jpg"

Does this variation help?

command: "ls share/motion -Art | tail -n -3 | grep 'capture.jpg'"

OK the following works, just a typo in the path:

sensor:
  - platform: command_line
    name: new_image
    command: "ls /share/motion -Art | tail -n -3 | grep 'capture.jpg'"

Cheers!