Adding media sync to Home Assistant

I’m trying to remove unnecessary (electronic) equipment wherever possible. It’s mainly about cutting excess power usage, but also about being more minimalistic with devices lying around not serving a particular need.

Doing so I came across our family NAS, which mainly runs to host files (photos, documents, etc.) for easy local access. For remote access I’m running a Nextcloud instance that syncs with the NAS on a regular basis. While the NAS could of course do a lot more, it boils down to hosting and serving files at home (and consuming power around the clock to do it.

With Home Assistant already doing most of the smart(er) home stuff, I figured why not use it for this too. And in fact half the problem was already solved:

Home Assistant serves its /media folder in the Media panel, so local access was never the missing piece. What was missing was keeping that folder in step with my remote server.

A quick look around turned up viable options — shell scripts, the Syncthing integration — but nothing that stripped down to my essentials:

1. Automated synchronization between local and remote storage

2. Safety rails: test runs, and no deletion without my say-so

3. An easy-to-use UI in Home Assistant to control and monitor it

Media Sync – Home Assistant App + Custom integration

I ended up doing a couple of sessions with my buddy Claude Code to build the foundation as a Home Assistant App plus a custom integration. Say hello to Media Sync 🙂

The app does the work. The integration gives it a face in Home Assistant — buttons, status sensors and the deletion confirmation.

What it does

  • Two-way sync, keeping whichever copy of a file is newer
  • Everything over an encrypted SSH connection, using a key the app generates itself, so there’s no password to store
  • Works with any server you can reach over SSH: a NAS, a VPS, a rented storage box
  • Per-folder include and exclude rules
  • A dry run that reports what would happen and changes nothing
  • Scheduled checks, or full automations calling the media_sync.sync action
  • Sensors for status, last run, duration and pending deletions

[Hint: if your remote is a Nextcloud data directory: Media Sync moves files over SSH rather than through Nextcloud’s API, so run “occ files:scan” afterwards for Nextcloud to pick up what changed.]

About deletions

This is the part I care most about. When a file exists on one side but not the other, there is no way to tell whether it was deleted there or added here. So Media Sync doesn’t guess: nothing is deleted automatically. The items are listed, left alone, and Home Assistant raises a repair notification asking you to decide.

Deletion protection is on by default and can be turned off if you’d rather it just get on with it.

Getting it

  1. Settings -> Apps -> three-dot menu -> Repositories, add https://github.com/mkerstner/media-sync, then install Media Sync from the store.
  2. Start it once. It creates an SSH key and prints the public half to its log. Give that key to your remote server.
  3. Fill in its settings: which server, which folders.
  4. In HACS, add https://github.com/mkerstner/media-sync-integration as a custom repository (category: Integration), install it, and restart.

Both are open source under the Apache License 2.0, the same license Home Assistant itself uses.

Issues and ideas welcome.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.