Point media_dirs: at NAS share?

Saw you mentioning samba mounting thread, I just checked it more and it mounts samba just as well as nfs. See 35st comment with NFS/Samba shell command different examples: Mount remote smb share on hassio

1 Like

Thanks a lot. Iā€™m having some issues getting this working. Iā€™m running on a proxmox box and hereā€™s the system info:

|arch|x86_64|
|---|---|
|chassis|vm|
|dev|false|
|docker|true|
|docker_version|19.03.11|
|hassio|true|
|host_os|HassOS 4.13|
|installation_type|Home Assistant OS|
|os_name|Linux|
|os_version|5.4.63|
|python_version|3.8.5|
|supervisor|245|
|timezone|Europe/London|
|version|0.115.2|
|virtualenv|false|

So there is already a ā€œmediaā€ directory in place as part of the install.

Iā€™m trying to connect to a share (movies) on my Western Digital Mycloud (drywall (192.168.1.121) which should be open to public.

  homeassistant:
    media_dirs:
      movies: /mnt/media2
shell_command:
  mount_movies_folder: mkdir -p /mnt/media2;mount -t cifs -o username=anonymous,domain=WORKGROUP //192.168.1.121/Movies /mnt/media2

This is the automation:

- id: 'XXXXXXXXXXXX'
  alias: Map Movies Folder
  description: ''
  trigger:
  - platform: homeassistant
    event: start
  condition: []
  action:
  - service: shell_command.mount_movies_folder
    data: {}
  - delay: 00:02:00
  - service: shell_command.mount_movies_folder
    data: {}
  mode: single

A config check brings back no errors so formatting looks good but Iā€™m not seeing what I was anticipating which would be my movies folder avaiable under media_browser and I get this error:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:111
Integration: Shell Command ([documentation](https://www.home-assistant.io/integrations/shell_command), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+shell_command%22))
First occurred: 17:27:21 (1 occurrences)
Last logged: 17:27:21

Error running command: `mkdir -p /mnt/media2;mount -t cifs -o username=anonymous,domain=WORKGROUP //192.168.1.121/Movies /mnt/media2`, return code: 255

NoneType: None

Is there some way I can test the command line etc via terminal? If you could me some pointers that would be appreciated.

1 Like

yes,

  1. go to http://homeassistant.local:8123/hassio/store (Add-on Store)
  2. Install Portainer (after install, disable Protection mode checkbox)
  3. Portainer -> Settings -> Hidden containers. Delete the listed hidden labels
  4. Open Containers section, open homeassistant container, click Console
  5. Connect as root (thatā€™s the default).
  6. Check that folder was created
cd /mnt
ls -la
#here configrm that media2 is here
  1. Execute
mount -t cifs -o username=anonymous,domain=WORKGROUP //192.168.1.121/Movies /mnt/media2
  1. If no errors, go into (cd /mnt/media2) folder and check that the files are there (ls -la)
  • Probably issue would be with username/domain combo. anonymous/WORKGROUP is what I use
  • It might be that SMB is configured to allow only 192.168.1.* IP addresses, this docker container has internal IP that is looking something like 172.30.32.2 - thatā€™s also possible culprit
8 Likes

Thanks a lot for the guidanceā€¦

Got portainer installed and configured as you said. media2 there but mount failed. as you suggested I tried changing the username and that works. - in the HA portainer console I can ls the directories and the content is there.

Unfortunately the media2/movies folder still doesnā€™t appear in HA media browser.

If I look at the HA instance console in proxmox I see this:

Really appreciate you help on this :slight_smile:

Reboot HA through server management: http://homeassistant.local:8123/config/server_control
after that, login with portainer, and check if folder is mounted (if files are there, then we can ignore the proxmox log, means it does mount)

  • if files are there - folder is mounted. then look into HA config. maybe ident is wrong?(in your code, youā€™ve got 2 spaces before homeassistant: is that right ?)
  • if files arenā€™t there - some mount issue from shell command. but if you can mount it from portainer, then try adding what log specifies to the shell command in HA:
#force less secure SMB version
mount_movies_folder: mkdir -p /mnt/media2;mount -t cifs -o vers=1.0,noserverino,username=anonymous,domain=WORKGROUP //192.168.1.121/Movies /mnt/media2

If still doesnā€™t work, add -v to mount command and compare output from portainer shell, and output from proxmox log and find differences if any

mount -t cifs -v -o vers=1.0,noserverino,username=anonymous,domain=WORKGROUP //192.168.1.121/Movies /mnt/media2

See more info on mount options https://linux.die.net/man/8/mount

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?