This custom component for Home Assistant allows you to fetch the latest files (such as camera screenshots and video events) of a certain minimum size from a specified directory. It was specifically designed for use with Reolink cameras and their integrations but can be easily adapted for a variety of other use cases.
OR
fetch_latest_file
folder into your custom_components
folder within your Home Assistant configuration directory.configuration.yaml
:fetch_latest_file:
Once you've set up the custom component in your Home Assistant instance, you can call it using the service latest.fetch
with the following parameters:
directory
: The directory to search for files. (Required)filename
: The start of the file name to search for. (Required)extension
: The file extension(s) to search for. (Optional)min_size
: The minimum size of the files to fetch. Specify the size as a string with a unit: B for bytes, K for kilobytes, M for megabytes, G for gigabytes. For example, "1M" for 1 megabyte. (Optional)Here's an example of how to call this service:
service: fetch_latest_file.fetch
data:
directory: "/path/to/your/directory"
filename: "cam1"
extension: ["jpg", "mp4"]
min_size: "1M"
This will search for the latest .jpg
and .mp4
files that start with "cam1" in the specified directory and are at least 1 megabyte in size. The result is then stored in a entity state attribute which you can access in your automations, scripts, or templates.
Entity: fetch_latest_file.file 's attributes:
video: /path/to/your/directory/cam1_20230613102757.mp4
image: /path/to/your/directory/cam1_20230613102757.jpg
The main use case for this component is in a home security setup with Reolink cameras. Whenever an event is triggered, Home Assistant fetches the relevant files that meet the minimum size requirement and can post them to a specific Discord channel. This provides a streamlined way to access important security footage as soon as it is needed.
This component can also be used in many other scenarios, such as:
Fetching the latest screenshot from a home automation event that is of
a certain size
This component is highly flexible and can be adapted to suit a variety of needs within your Home Assistant setup. List of supported file extensions categories:
Feel free to open an issue for any problems or feature requests.