Integrations

File

Spook adds actions that list the files in a folder Home Assistant is allowed to use, and delete them from an automation, to clean up the exports, synced backups and logs that pile up outside your media.

The file integration is how Home Assistant reads and writes files of its own: a notification written to a file, a sensor that reads the last line of one, the Read file action.

Plenty piles up in a folder outside your media. The clips a camera recorder exports, a backup folder another machine syncs into, the logs of a tool. Home Assistant cannot see what is in there, let alone clean it up.

Spook adds two actions for that: list the files in a folder, and delete them. The same as List media and Delete media do for your media, for the folders outside of it.

Both work in the folders Home Assistant is allowed to use, and nowhere else. Home Assistant only lets its integrations into the folders in allowlist_external_dirs, a list in your configuration. Out of the box, that is your media folder and the www folder in your configuration folder. Add your own under homeassistant: in your configuration.yaml, and restart. The folder has to be there already:

homeassistant:
  allowlist_external_dirs:
    - /share/nvr-exports
file:

The file: line sets up the file integration, which brings these actions: they show up once it is set up. Leave it out when you set it up under Settings > Devices & services already.

Actions

Spook adds two actions to the file integration. You find them wherever you add an action, marked with a 👻.

List files

Lists the files in a folder, the oldest first: their full path and name, their size, and when they last changed.

With Recursive on, the files in the folders inside it are listed too, all the way down. With Name pattern, only the files whose name fits it, like *.mp4 for the videos. Upper and lower case are the same: *.mp4 also finds CLIP.MP4.

With Older than, only the files that last changed longer ago than that are listed. Ready to hand to Delete files.

Folders, links and anything hidden (its name starts with a dot) are left out. In a synced folder, the hidden files are the sync tool's own: a cleanup should leave them be.

Listing files is for administrators only, as reading a file with the file integration of Home Assistant is.

How to use it

  1. Open the automation or script that needs the list, and select Add action.
  2. Search for list files, and select File: List files 👻.
  3. Under Folder, enter the full path of the folder, like /share/nvr-exports.
  4. Under Response variable, give the list a name, like result. The steps after this one can use it.
  5. Select Save.

Delete files

Deletes one or more files from the folders Home Assistant is allowed to use, by their full path.

A file that is not there is skipped, not an error. Ask for the response to see which files were deleted, and which were not found.

Every path is checked before the first file goes. One path outside the allowed folders, one folder, or one link, and the action deletes nothing at all. Folders are never deleted, nor what is in them: give the files, List files gives them.

When a file cannot be deleted, for example because Home Assistant is not allowed to, the action still deletes everything else. Then it fails with an error that names each file it could not delete, and why. That error is all you get back: no response, so no list of the files that did go.

Deleting files is for administrators only.

How to use it

  1. Open the automation or script that should delete the files, and select Add action.
  2. Search for delete files, and select File: Delete files 👻.
  3. Under File, enter the full paths of the files to delete. File: List files 👻 gives them.
  4. Select Save.

Missing something here?

An action, an entity or a repair this integration should have? Say so. Stuck, or found a bug? There is help.