Custom Component for Home Assistant that reads a list of files from a directory into a sensor.
This was developed for use alongside the Gallery Card but may have other uses.
Files must be in the WWW folder, ideally in a subfolder. This component will periodically scan the folder for changes to the files, and is based on the built-in Folder component.
The component can be installed from HACS (use the Custom Repository option), but follow the below instructions to install manually.
- Create a folder in your
config
directory (normally where your configuration.yaml file lives) namedcustom_components
- Create a folder in your
custom_components
namedfiles
- Copy the 3 files (init.py, manifest.json, and sensor.py) into the
files
folder - Restart Home Assistant
- Create a folder in your
WWW
folder namedimages
(or any other name, but be sure to use the proper name below) - Add your images/videos to this folder
- Add the files sensor to your configuration.yaml file
- sensor - platform: files folder: /config/www/images filter: '**/*.jpg' name: gallery_images sort: date recursive: True
- Restart Home Assistant
- Check the sensor.gallery_images entity to see if the
fileList
attribute lists your files
Name | Type | Default | Description |
---|---|---|---|
platform | string | Required | files |
folder | string | Required | Folder to scan, must be /config/www/*** |
name | string | Required | The entity ID for the sensor |
sort | string | Optional | One of 'name', 'date', or 'size'; Determines how files are sorted in the Gallery, Default: date |
recursive | boolean | Optional | True or False; If True, the pattern filter ** will match any files and zero or more directories, subdirectories and symbolic links to directories. Note: Using the ** pattern in large directory trees may consume an inordinate amount of time , Default: False |
The entity will automatically update on a schedule, however, if you need to refresh more often or at some event, you can use the update_entity service call.
action:
- service: homeassistant.update_entity
target:
entity_id:
- sensor.gallery_images
This component largely created from work done by @zsarnett in the slideshow card, from which other inspiration was also taken.