[SOLVED] HASSOS mount NAS network share

@sparkydave, your command-line seems sane. But maybe the issue is in quoting. Unless you use weird characters in your password, you don’t need the quotes on the parameter after -o. Instead, what I would suggest is to add quotes around the whole command.

# Try replacing this:
shell_command:
   mount_my_folder: mkdir … ; mount … -o 'ro,…' //192… /media/…
# With this:
shell_command:
   mount_my_folder: 'mkdir … ; mount … -o ro,… //192… /media/…'

In the second example above, the quotes are around the entire command, which explicitly tells the YAML parser this should be treated as a string. Well, YAML can automatically detect strings even without quotes, but YAML syntax rules are weird and can sometimes lead to unexpected results.

If you have weird characters in your password, try limiting to letters, numbers, and a few “safe” symbols: ._-+=:/@%^. If you insist on using other symbols, then you need to figure out how to safely escape those characters both in the shell syntax and in YAML.


But maybe your issue is somewhere else…

The whole setup is made of three parts (or four parts, depending how you count):

  • media_dirs configuration, which tells HA where to look for media files. If you’re running HA inside a container (and a HAOS install does run the HA core inside a container), please be aware this path is inside the container filesystem. See the documentation: Media Source - Home Assistant
  • shell_command that would create and mount the shared folders.
    • To avoid accidentally exposing the credentials if/when you share your main configuration.yaml file, you can move the entire command to secrets.yaml. See the documentation: Storing secrets - Home Assistant
    • We are actually chaining two commands in a single command line:
      • mkdir to create a new directory. The -p means “create any parent directories as needed, and don’t complain if the directory already exists”.
      • mount to actually mount the network share into that directory.
    • We can chain commands using:
      • ; → the second will run regardless of the state of the first one
      • && → the second will only run if the first one succeeded
      • || → the second will only run if the first failed
      • For our purposes here, both && and ; would work just fine.
    • This overview is enough for our purposes. If you want to learn more about this subject, look for tutorials and lessons about UNIX shell, sh, and bash.
  • An automation that would run the shell_command during the HA startup. See the documentation: Shell Command - Home Assistant and Automation Trigger - Home Assistant

If all these parts are correctly set up, the whole thing should work. If it doesn’t, look for clues and error messages in Open your Home Assistant instance and show your Home Assistant logs.. You can also manually trigger the automation Open your Home Assistant instance and show your automations. or manually call the shell_command service Open your Home Assistant instance and show your service developer tools. and then look for new error messages in the logs. Finally, you can also use ssh to open a shell inside your HA container and then you can inspect the directories and see what’s happening. Explaining this is beyond the scope of my reply, but this requires just some basic UNIX/Linux skills.