Monitor Samba share availability

I have Home Assistant installed in Docker on RaspberryPI. There is an external HDD connected to the same device, but sometimes it disconnects without any obvious reason. HDD is also mounted as a Samba share, so I want to monitor the HDD connectivity by checking if the Samba share is still alive. Is it there any way to check that from Home Assistant?

No sure if this aligns with what you are looking for. However, this is how I create 2 sensors to monitor a SAMBA connection on a Synology and one on a Ubuntu machine that I have attached to the Ubuntu machine that runs HA in a Docker container :

# nas00 mounted
  - platform: command_line
    name: NAS00-v00 Mounted
    command: "df -h | grep -q '192.168.2.5' && echo '1' || echo '0'"
    value_template: '{{ value }}'
    scan_interval: 60

# raid share on macmini2014 mounted
  - platform: command_line
    name: macmini2014 Mounted
    command: "df -h | grep -q '192.168.2.20' && echo '1' || echo '0'"
    value_template: '{{ value }}'
    scan_interval: 60

So are these shares available from the system where Home Assistant is installed? In my case HA is inside of a Docker container, so it doesn’t have access to mount points of the host system. Guess I have to mount the share to the container as well…

Yes, what you make visible to the Docker container matters. My SAMBA mounts are done at system boot time, no mounts are done within the Docker container running Home Assistant in my setup. Below is how I run the Docker container for HA, note the ‘-v’ volume maps. With this, I am able to see the hosts mounts as I showed in the HA sensor setup:

docker run -i -t -d --name="home-assistant-2021.6.6" -v /home/user/homeassistant:/config -v /media/:/media -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant:2021.6.6
1 Like

I mounted the HDD on the host level to a subfolder of
/usr/share/hassio/media/
via /etc/fstab, and now it is accessible from the docker container.

And how to monitor its use percent? There is in System Monitor sensor.system_monitor_disk_use_percent_share but it is most probably designated for folder SHARE (anyway not indicating folder SHARE disk usage but the whole disk usage).