Seafile

The Seafile integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] connects Home Assistant to your Seafile server.

Seafile is a self-hosted file sync and share server. Files are stored in libraries. This integration shows the size, number of files, and last modification time of the libraries you choose, and can store Home Assistant backups in them.

Use cases

  • Keep an eye on how much storage your libraries use and get notified when one grows too large.
  • Check that a library you back up to is still being updated.
  • Store your Home Assistant backups on your own Seafile server.

Prerequisites

  • A Seafile server that Home Assistant can reach.
  • A Seafile account with access to the libraries you want to add.

Configuration

To add the Seafile service to your Home Assistant instance, use this My button:

Manual configuration steps

If the above My button doesn’t work, you can also perform the following steps manually:

URL

The address you use to open Seafile in your browser, for example, https://seafile.example.com.

Username

The email address or login ID of your Seafile account.

Password

The password of your Seafile account. It is only used to create an access token and is not stored.

Verify SSL certificate

Turn this off if your server uses a self-signed certificate.

If your account uses two-factor authentication, you are asked for the code from your authenticator app.

Home Assistant exchanges your password for an access token. In Seafile, this token is listed under the linked devices of your account as Home Assistant, followed by the name of your home in parentheses. Revoking it there disconnects Home Assistant.

After logging in, you can select the libraries to add. You can also skip this step and add libraries later.

Adding a library

  1. Go to Settings > Devices & services and select the Seafile integration.
  2. Select Add library.
  3. Select the library you want to add.
  4. Optionally, turn on Store backups and choose a Backup folder. See Backups.

To change the backup settings of a library later, select the Reconfigure library button next to the library.

Library

The library to add. Encrypted libraries are not supported.

Store backups

Make this library available as a backup location in Home Assistant.

Backup folder

The folder in the library to store backups in. Defaults to /Home Assistant backups. It is created when the first backup is uploaded.

Reconfiguration

If your Seafile server moves to a new address, its certificate changes, or you want to log in with a different username or password, you can update the integration without removing and adding it again.

  1. Go to Settings > Devices & services and select the Seafile integration.
  2. Next to the account, select the three dots menu, then select Reconfigure.
  3. Enter the URL, Username and Password, and change Verify SSL certificate if needed, then select Submit.

Home Assistant logs in again and creates a new access token. It then tries to revoke the old token, using the previous URL and SSL setting. If that fails, for example because the old address no longer works, the old Home Assistant entry stays under the linked devices of your account, and you can remove it there yourself. You must log in to the same Seafile account that was set up before.

Supported functionality

Each library is added as a separate device in Home Assistant, with the following entities.

Sensors

  • Size
    • Description: Total size of the files in the library.
  • Files
    • Description: Number of files in the library.
  • Last modified
    • Description: Time the library was last changed.

Buttons

  • Empty trash
    • Description: Permanently deletes the files and folders in the trash of the library. This can’t be undone. Only the owner or an admin of the library can empty its trash.

Selects

  • History
    • Description: How much file history Seafile keeps for the library, so you can restore older versions of files.
    • Options:
      • Keep full history: Keep all older versions. This is the default in Seafile.
      • Don’t keep history: Keep no older versions. Seafile removes the existing history.
      • Keep a period of history: Keep the older versions for a set number of days. Switching to it from another option sets a period of 30 days. A period that is already set stays as it is. Change the number of days with History days.
    • Remarks: Only available for libraries you own or administer.

Numbers

  • History days
    • Description: For how many days Seafile keeps the older versions of files in the library, from 1 to 3650.
    • Remarks: Only available when History is set to Keep a period of history.

Backups

Each library with Store backups turned on is available as a backup location in Home Assistant, named after the account and the library, for example, admin@example.com (seafile.example.com) - Documents. Libraries you select while setting up the integration have backups turned off; turn them on by reconfiguring the library.

Each backup is stored in the backup folder as a .tar file, with a _meta.json file next to it that describes the backup. Don’t rename or delete only one of the two files: backups without both files are not listed.

Backups are uploaded in parts of 50 MiB, so they also work when Seafile is behind a proxy that limits the request size, such as Cloudflare.

For more information on backups, see backups.

Data updates

The Seafile integration pollsData polling is the process of querying a device or service at regular intervals to check for updates or retrieve data. By defining a custom polling interval, you can control how frequently your system checks for new data, which can help optimize performance and reduce unnecessary network traffic. [Learn more] your Seafile server every 5 minutes.

The list of backups is cached for 5 minutes. Backups that you add or delete in Seafile directly can take up to 5 minutes to show up in Home Assistant.

Seafile automation examples

The following examples use a library named Documents and a library named Laptop backup. Replace the entities with those of your own libraries. Here are a few ideas to get you started.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the visual automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.

Automation: Notify when a library grows too large

This automation sends a notification when the Documents library grows past 50 GiB. The threshold uses the unit the Size sensor is shown in, which is GiB by default.

  • Trigger: Numeric state crossed threshold
    • Entity: Documents Size
    • Above: 50
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
    • Message: The Documents library in Seafile is now {{ states('sensor.documents_size') }} GiB.
YAML example for a notification when a library grows too large
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Seafile library grows too large"
triggers:
  - trigger: numeric_state
    entity_id: sensor.documents_size
    above: 50
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The Documents library in Seafile is now {{ states('sensor.documents_size') }} GiB."

Automation: Empty the trash of a library every week

This automation empties the trash of the Documents library every Sunday at 03:00. Files in the trash are deleted permanently, so only use this for libraries where you don’t need to restore deleted files. Only the owner or an admin of the library can empty its trash.

  • Trigger: Time
    • At time: 03:00:00
    • Weekdays: Sunday
  • Action: Press button
    • Target: Documents Empty trash
YAML example for emptying the trash every week
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Empty Seafile trash weekly"
triggers:
  - trigger: time
    at: "03:00:00"
    weekday: sun
actions:
  - action: button.press
    target:
      entity_id: button.documents_empty_trash

Automation: Notify when a backup library stops changing

This automation sends a notification when the Laptop backup library has not changed for 7 days, which can mean that your backups stopped running.

  • Trigger: Template, the Last modified sensor of the library is more than 7 days ago
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
    • Message: The Laptop backup library in Seafile has not changed for 7 days.
YAML example for a notification when a backup library stops changing
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Seafile backup library not updated"
triggers:
  - trigger: template
    value_template: >
      {% set modified = states('sensor.laptop_backup_last_modified') | as_datetime(None) %}
      {{ modified is not none and now() - modified > timedelta(days=7) }}
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The Laptop backup library in Seafile has not changed for 7 days."

Supported versions

The integration has been tested with Seafile 13 and 14 (Community Edition).

Known limitations

  • Encrypted libraries are not supported and are not shown in the list of libraries.
  • An account on a server can only be added once.
  • When a library is deleted on the Seafile server, or your account loses access to it, Home Assistant doesn’t remove it automatically because the library might only be unavailable for a while. Instead, a repair issue lets you remove it.
  • Changing History or History days fails with a permission error if the Seafile server administrator has turned off the library history setting.

Troubleshooting

Symptom: The sensors of a library are unavailable

The entities of one or more libraries show as unavailable. You might also see a repair issue named Seafile library “name” not found, where name is the name of your library.

Description

Home Assistant can’t reach the Seafile server, or the library is no longer available to your account: it was deleted on the server, or your account lost access to it. When the server can’t be reached, the sensors of the account are unavailable as well. When the server is reachable but the library is gone, Home Assistant creates a repair issue, and the library can no longer be used as a backup location.

Resolution

  1. Check that Home Assistant can reach the Seafile server, and look for connection errors in Settings > System > Logs.
  2. Sign in to the Seafile web interface with the same account and check that the library is still listed. If the library comes back, for example because it was shared with you again, the repair issue disappears by itself within a few minutes.
  3. If the library is gone for good, open the repair issue in Settings > System > Repairs and select Submit. This removes the library, its device and entities, and its backup location from Home Assistant. You can also delete the library entry from the Seafile integration page.

Symptom: A library is not listed as a backup location

The library is not shown as a location when you create a backup.

Description

Store backups is turned off for the library, or the Seafile account is not loaded.

Resolution

  1. On the Seafile integration page, select the Reconfigure library button next to the library.
  2. Turn on Store backups and select Submit.
  3. If the library still isn’t listed, check that the integration is loaded and its sensors are available.

Symptom: Home Assistant asks you to log in to Seafile again

The Seafile integration needs attention and its entities are unavailable.

Description

The access token of the integration was revoked or is no longer valid, for example, because the Home Assistant entry was removed from the linked devices of your account.

Resolution

  1. Go to Settings > Devices & services and select Reconfigure on the Seafile integration.
  2. Log in with the username and password of the same Seafile account. If the account uses two-factor authentication, also enter the code.

Home Assistant creates a new access token and loads the integration again. Logging in with a different account is not accepted.

Removing the integration

This integration follows standard integration removal.

To remove an integration instance from Home Assistant

  1. Go to Settings > Devices & services and select the integration card.
  2. Next to the entry you want to remove, select the three dots menu. Then, select Delete.
    • Depending on the integration, the entries are listed under one of the following headings:
      • Devices
      • Hubs
      • Services
      • Integration entries
  3. To confirm, select Delete.
    • Home Assistant also deletes the devices and entities of the entry.
  4. If Home Assistant asks you to restart, restart Home Assistant.
  5. If Home Assistant asks whether to also delete the application credentials, select Remove or Keep.

To also remove the access token from Seafile, delete the Home Assistant entry from the linked devices of your account.