Home Media Center
There are multiple devices (e.g., laptop, tablet, smart TV, projects) in a home network, and we want to play local media (music, videos, photos, etc) from any of these devices. In this case, we may want to build a media center that enables media sharing and streaming across multiple devices.
A completely free and open-source option is Jellyfin. Installation of this software in linux is straightforward by simply following the instructions. Once installed successfully, a message from the terminal will instruct you to access the Jellyfin instance via a web browser to finalize the setup, e.g., setting username and password, creating libraries, etc.
To access and stream the media from a device, a client may be installed; see available clients from the website of Jellyfin.
NAS and Samba
In some cases, files stored in a device need to be accessed from another device as if they were local files. For example, the Music Assistant does not support access to remote files. In this case, we may set up a simple NAS (network attached storage) service in linux via Samba. First, if Samba is not installed in the target device, install it via the following command.
sudo apt install samba
Then we edit the configuration file /etc/samba/smb.conf
to append the following section to the end of the file:
[media]
comment = Shared Media
path = /media
guest ok = no
browseable = yes
create mask = 0777
directory mask = 0777
writable = yes
read only = no
Change the path in the above to suit your setting. Additional sections can be appended to share more folders. Finally, set up username and restart the samba service.
# add current user (e.g., smartopia) to the sambashare group
sudo usermod -aG sambashare $USER
# set up a password for the user
sudo smbpasswd -a $USER
# set up firewall
sudo ufw allow samba
# restart service
sudo systemctl restart smbd
Now, the shared files can be accessed via the address //[IP of the samba server]/media
by using the username (e.g., smartopia) and the password you set in the last step. For instance, we may mount this shared folder to the Home Assistant.
First, ensure that the following line is included in configuration.yaml
.
automation: !include automations.yaml
Then, place the following code to configuration.yaml
.
shell_command:
mount_samba_folder: mkdir -p /media/shared;mount -t cifs -o vers=2.1,noserverino,username=smartopia,password=xxxxxxxx,domain=WORKGROUP //10.0.0.1/media /media/shared
In the above, the path /media/shared
can be changed to suit your setting of Home Assistant. The username and password are the one we set in the last step of installing samba. The IP address 10.0.0.1 should be replaced with the IP address of your samba server, and /media
in //10.0.01/media
refers to the section we configured in the smb.conf
.
Finally, we put the following code in automations.yaml
.
- id: "mount_samba"
alias: Mount Shared Folder via Samba
description: For Music Assistant
trigger:
- platform: homeassistant
event: start
condition: []
action:
- service: shell_command.mount_samba_folder
data: {}
After restarting Home Assistant, we can see the shared folder in the Local Media section of the Media Source panel of Home Assistant.