Skip to main content
Smarthome 4 mins

Integrating NAS and network drives with Home Assistant

Home Assistant can play music and videos and work as a coordinator for many devices such as Amazon Echo, AV receivers, etc. But how do you get the media collection from a NAS or network drive into Home Assistant? Here’s a guide.

Integrating NAS and network drives with Home Assistant

Many of you have large media collections on NAS drives . Unfortunately, there is still no simple and direct way in Home Assistant to connect Windows/Samba network drives and make the data from them available in Home Assistant. However, with a few small settings, it’s relatively easy and quick.

First, you should set up the desired shares on your NAS or file server and ensure that they are accessible from other devices. This of course depends on your systems, and because there are so many possibilities, this cannot be part of the guide.

⚠ [affiliate] Keine Produkte mit Cache für home-assistant. Bitte affiliate-sync --lang en ausführen.

The actual connection of the network share to Home Assistant is done via the workaround of a shell command. This allows you to execute Linux commands from within Home Assistant. In this case, it’s the mount command with which we connect the network drive.

Enter the following in your configuration.yaml:

yaml
1
2
shell_command:
  mount_music_folder: mkdir -p /media/musik;mount -v -t cifs -o vers=1.0,noserverino,user=media,password=media123,domain=WORKGROUP,sec=ntlm //192.168.178.2/media/musik /media/musik

Let’s break down the entire command:

shell_command: simply tells Home Assistant that this Linux command should be available as a service. Services can then be used in automations and scripts. More on this later.

mount_music_folder - is an arbitrary name for the new service. You could also call it music_drive_connect or something similar.

mkdir -p - first creates a directory in Home Assistant that, upon successful mount command, reflects the content of the network drive. The -p says that the command should not output an error if the directory already exists.

/ media/musik: For Home Assistant to recognize the data in its media directory, we need to mount the network drive there. I want my music to be connected in the subdirectory /media/musik

mount - v -t cifs -o vers=1.0, noserverino - the actual mount command that connects Samba/Windows shares with Samba version 1.0. Version 1.0 (vers=1.0) is usually the most trouble-free, but also the slowest. Other values would be vers=2.0 or vers=3.0. See also: mount.cifs › Wiki › ubuntuusers.de

user=media,password=media123,domain=WORKGROUP,sec=ntlm - user specifies a username that has access permission to your network drive and password=media123 the associated password. sec=ntlm defines the hashing method of the password.

//192.168.178.2/media/musik - is the UNC path to your NAS or server where the desired data is located, and this is mounted in the initially mentioned and created directory /media/musik in Home Assistant

You should definitely test beforehand whether you can access your network drive with the network or UNC path and the associated user/password. You can also test this from the Home Assistant shell with the complete command. If this is successful, nothing stands in the way of using it.

However, the directory is not yet mounted with this. For this to happen at all, the service mount_musik_folder - or whatever you called it, must be executed, preferably whenever Home Assistant restarts.

First, you can test the service in the Developer Tools -> Services by searching for the service, in my case mount_music_folder, and then selecting Execute Service. The content of your network drive should now be found in Home Assistant in the Media Browser.

Now we just need to teach Home Assistant to also execute this service on restart. To do this, we create an automation:

First, we assign a name for the automation. In my case, it’s called Mount Unraid UnraidNAS operating system with flexible storage management (no RAID requirement). Popular for home servers with Home Assistant as a Docker container NAS

The trigger for the automation is the start of Home Assistant. And as the action type, our service mount_music_folder should be executed.

I have several drives that should be mounted on startup. These can simply be specified one after the other, but must be defined beforehand in the configuration.yaml exactly as in our example, i.e. in the form:

yaml
1
2
3
4
shell_command:
  mount_music_folder: ...
  mount_video_folder: ...
  mount_photos_folder: ...

Now save the automation and from now on, every time Home Assistant starts, your network drives will be made available in Home Assistant.


Hi! I'm Markus – the Fricklr. ⚡ Electrical engineer, 🎵 musician (bass, guitar, keys) and professionally 'something with the internet' 🌐 for over 30 years – nowadays with AI too 🤖 – a 55-year-old generalist from Bavaria, Germany.

Your feedback helps me write even more interesting posts. After "Yes" there's also a small option to support my work.

Explore related topics

Content Map →
Show related content as a list
💡 Drag, hover & click to explore
Bigger dots are more relevant

What do you think? Leave a comment!

Share your thoughts, questions or experiences with the community.

Links marked with this symbol are affiliate links. As an Amazon Associate I earn from qualifying purchases. There are no additional costs for you.