bexem / Fetch-Latest-File

A custom component for home assistant to fetch the latest file in a given directory.
GNU General Public License v3.0
2 stars 1 forks source link
hacs-custom home-assistant homeassistant homeassistant-custom-component python

Home Assistant "Fetch latest file" Custom Component

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.

Installation

  1. Use HACS custom repository: Open your Home Assistant instance and show the add repository dialog of the Home Assistant Community Store.
    Manual Instructions
    1. Go to any of the sections (integrations, frontend, automation).
    2. Click on the 3 dots in the top right corner.
    3. Select "Custom repositories"
    4. Add this repository URL to the repository text field.
    5. Select the integration category.
    6. Click the "ADD" button.
  • Go to Configuration > Integrations > Add Integration > Fetch Latest File
  • OR

    1. Copy the fetch_latest_file folder into your custom_components folder within your Home Assistant configuration directory.
    2. Add the following to your configuration.yaml:
    fetch_latest_file:

    Usage

    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:

    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

    Use Case

    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.

    See My example

    Further Uses

    This component can also be used in many other scenarios, such as:

    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:

    Support

    Feel free to open an issue for any problems or feature requests.