Point media_dirs: at NAS share?

Getting somewhere but its now 1:30am and I have work tomorrow :frowning: Will update later today :wink: - thank you so much.

EDIT:

so I got it working with the following config.

homeassistant:
  media_dirs:
    music: /mnt/media2

shell_command:
  mount_music_folder: mkdir -p /mnt/media2;mount -t cifs -o vers=1.0,noserverino,username=<username>,domain=WORKGROUP //192.168.1.121/music /mnt/media2

You were right about the spacing - my bad. My WDis old, a version 1 hardware/firmware and the key point seems to be specifying the “vers=1.0,noserverino,”. Using the same principles I was able to mount other shares as well.

Thanks again for the assistance and the education. :slight_smile:

2 Likes

hi,
First I tried it with

mount -t cifs -o username=hassos,domain=NASVolume //192.168.178.49/media /mnt/media

but I got

mount: mounting //192.168.178.49/media on /mnt/media failed: Host is down

Because my NAS is running on v1.0 I tried it with

mount -t cifs -o vers=1.0,noserverino,username=hassos,domain=NASVolume //192.168.178.49/media /mnt/media

But then I got

mount: mounting //192.168.178.49/media on /mnt/media failed: No error information

Any idea what could cause “No error information”?
Homeassistant is running on a raspi 3B+ with HassOS 4.13.
I just wanted to test the mounting part and haven’t done the automation part yet.
Also, my NAS has two shares: backup and media. Is it possible to mount the whole share or do I have to specify the folders in it?

Thanks

I got the share working on my NAS by making sure that not only did the USER have access, but also the EVERYONE group.

Also needed to be su root. The command as per below prompted me for the password and then worked!

mkdir -p /mnt/media;mount -t cifs -o vers=1.0,noserverino,username=<username>,domain=WORKGROUP //192.168.1.x/Music /mnt/media
1 Like

With some adjustments i was able to make is work for a remote folder shared on my Plex PC.
Thank you for your help.

  • I have added password to the command
1 Like

Could you specify what you did?
I now managed to mount the nas (the nas folders are visible via ssh and ls command)
But i can’t add it to the media browser (HA doesn’t accepts the mounted folder as a media source)

So I have arrived at a similar point<successfully mounted via shell and visible to the ls command but not visible in the media browser, nor samba add on via windows explorer> (if not the exact same point) via different method.

I discovered this (Use network drive ) post before I discovered the post that I am replying to now, but my goal is media as is the point of our current post. I used the SSH & Terminal addon (the unofficial one, that allows for unprotected mode, the official one failed when I tried)

being that the files are indeed mounted from the shell command and ls -la lists root twice for each line item and based on a few other context clues my current suspicion is that that all of the files are mounted and only visible too the root user account. I suspect that whatever user account the system sees me and the lovelace media browser as is a different non-root user. I am a utter linux novice so I have no idea how to even begin testing for that or changing the user account the network share is mounted to.

but maybe with that idea as a prompt someone else here can add some magic to the conversation???

Edit to add:

after reboot the mount seemed gone, remounting was trivial via the same method as before (hell the shell remembered the command and suggested it just a few characters in). Of note and lending weight to my suspicion, after remounting the share and validating via the ls command everything was listed; I switch over to the official ssh & Terminal and navigated to the same directory and issued the same ls command only to see absolutely nothing. I believe the official SSH & Terminal sees the directory from the same non-root user account as everything else.

I guess I should also add the command just because it might help so

mount -t cifs -o username=user,password="password",domain=domain.com "//192.168.1.250/some folder/structure that had/spaces so I fixed/with quotes" /media/mount

Should be noted my password which has a symbol in it was screwing things up for the longest until I put it in quotes. if the folder structure has spaces in the name you will need quotes on that too, also if copying from windows explorer address bar make sure to reverse all of the slashes from \192… to //192…

1 Like

This really needs to be done as an integration, ideally from the base platform, alternatively via HACS.

7 Likes

My easy way:

On the root system

sudo nano /etc/mountnasha.sh

insert

#!/bin/bash
sleep 5m
sudo docker exec homeassistant mount -t cifs -o "domain=WORKGROUP,username=xxxxxx,password=xxxxxx" //192.168.1.xxx/Medien /media

then

sudo nano /etc/systemd/system/mountnasha.service

insert

[Unit]
Description=Mount NAS Media to HomeAssistant

[Service]
Type=simple
ExecStart=/etc/mountnasha.sh

[Install]
WantedBy=multi-user.target

then

sudo systemctl enable mountnasha

restart your host and you’re done…

3 Likes

Thanks! Does this persist after update if using Home Assistant OS ?

Yes. Because you change it on the host, not inside the homeassistant docker container…
Did it work for you?

But if you do an server restart in HA, the mount is gone… than you can type the command manually in an ssh shell… perhaps there is another way… I’ll think about it…

1 Like

I guess this doesn’t work on hassos?

A couple of ideas have stemmed from this:

  1. run the script periodically, build in a test if the mount is not working, then activate, if it is active then igore
  2. create a file sensor in HA, if the file isn’t detected (on the nas mount) run the script

Hello -

I’ve got my cifs mount and copy working but I need some help structuring the copy. I’m running Frigate add-on and it stores video clips like this:

parking-1614646104.016776-mbk3v1.mp4

I have an automation running the shell command below every 5 mins to transform the filename by extracting the file creation date and prepending it onto the file name, then truncating the data at the end, and copy it to a mounted folder.

cd /media/frigate/clips;for file in *.mp4;do cp -u “$file” /media/camsonplex/"$(date -r “$file” +"%Y%m%d_%H_%M_%S")_${file:0: -29}.mp4";done

This is working great and produces this from the file above:

20210302_00_48_51_parking.mp4

The file creation date is in UTC. The last thing I want to accomplish here is to change that to my local time. Which is Detroit time (or UTC-5). All my attempts so far have not worked. If successful, the resulting file name would instead be:

20210302_19_48_51_parking.mp4

Can someone smarter than me re-work my cp statement to make this happen?

Thanks in advance! Let me know if this is not the best place for this question and I can move it.

Disregard - found help on Reddit!

If anyone is wondering:
‘cd /media/frigate/clips;for file in *.mp4;do cp -u “$file” /media/camsonplex/"$(TZ=America/New_York date -r “$file” +"%Y%m%d_%H_%M_%S")_${file:0: -29}.mp4";done’

Great idea!

I think a file sensor in HA would be the best solution.
Any ideas how to implement this?

Dominik - That may be a better solution that I have not looked into. My guess is you’d have to set the sensor to run the shell command when a new file is detected. Might even be possible through the sensor to identify the specific file name and avoid my for loop solution.

The 5-minute check is a bit wasteful as it could be hours between actual clip generation. The “-u” flag prevents it from continually overwriting existing files though. It only actually writes new files over.


it needs testing, but would it be as simple as putting a text file in a location with a status of “up”

so text file on NAS called sensor.json
{“nasshare”: “up”}

configuration.yaml:

sensor:
  - platform: file
    name: Media_Status
    file_path: /<media mount>/<directory>/sensor.json
    value_template: '{{ value_json.media_up }}'
    unit_of_measurement: "status"

Honestly not sure if this will “just work”, probably best to try with a local file before making it a remote file. testing might just involve renaming the file

@Dominik.W thanks for reawakening my interest in this question. I believe I may have found an even easier way :slight_smile: This is completely inspired by your service which launched a command from within a docker container

As above - much cleaner approach and helps keep us out of the linux shell :slight_smile: Of course confirming the command works in the shell is definitely appropriate.

configuration.yaml

shell_command:
  mount_media: mount -v -t cifs -o vers=1.0,noserverino,username=<youruser>,pass=<yourpass>,domain=WORKGROUP,sec=ntlm //192.168.1.x/Music /media

Then create an automation:
Name: Mount Media on Start

Triggers:
Trigger type: Home Assistant
Event: start

Conditions:

Actions:
Action type: Call service
Service: shell_command.mount_media

Now to figure out the file sensor … and a tweaked automation to remount if the folder/mount drops.

4 Likes

Thanks a lot for your command and automation. For me the command in terminal is working fine and I have no issue to see all my movies on my NAS in the terminal when I list the mounted dir.

But whenever I add the mounted folder to a media library (Jellyfin in this case) it says the mount folder is empty.

Any idea?

Hey @bjornb the first time I mounted it, I had a similar experience, what was critical was to mount it as /media that is the default location for the media integration to look for files. On my system /media is empty by default

Also see this post for an example: