One way to get info from the device is by using ssh.
So on the Home Assistant machine, first make ssh keys. Then appropriately locate and permission these files, and make a back up of them.
Next enable ssh on the WD Dashboard (RTFM > Configuring Settings > Network ).
Log in to the WD as the ssh user and create a .ssh directory, permissioned as 700. Within that create a file named ‘authorized_keys’, permissioned as 600, and copy/paste the public key part of the ssh files pair, into here.
Next back up the .ssh directory:
tar -cvzf /shares/<username>/ssh_backup.tar.gz .ssh
Every time the WD reboots, it wipes the directory, so you’ll need to manually ssh in and restore the ssh directory:
tar -xvzf /shares/<username>/ssh_backup.tar.gz
Not ideal, but then it isn’t often that it needs a reboot.
With that done, back up the tar.gz file, to somewhere off the device.
Next test connecting using the keys, over ssh:
ssh -i <path_to_private_key_file> <ssh_user>@<device_ip_or_hostname>
… and accept when the confirmation happens.
Once the ssh part is working, the next task is to get the data. Here’s what I have in my sensors.yaml file:
- platform: command_line
name: nas_cpu_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep CPU | cut -d' ' -f 2 | cut -d'=' -f 2
# NAS Board Temperature
- platform: command_line
name: nas_board_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep Current | cut -d' ' -f 4
# NAS HD0 Temperature
- platform: command_line
name: nas_hd0_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep hd0 | cut -d' ' -f 2 | cut -d'=' -f 2
# NAS HD1 Temperature
- platform: command_line
name: nas_hd1_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep hd1 | cut -d' ' -f 2 | cut -d'=' -f 2
# NAS HD2 Temperature
- platform: command_line
name: nas_hd2_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep hd2 | cut -d' ' -f 2 | cut -d'=' -f 2
# NAS HD3 Temperature
- platform: command_line
name: nas_hd3_temp
unit_of_measurement: '°C'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 0 | grep hd3 | cut -d' ' -f 2 | cut -d'=' -f 2
# NAS Fan RPM
- platform: command_line
name: nas_fan_rpm
unit_of_measurement: 'rpm'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> fan_control -g 4 | cut -d' ' -f 4
# NAS SMART Status
- platform: command_line
name: nas_smart_status
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> /usr/local/sbin/getSmartStatus.sh
# NAS Firmware Status
- platform: command_line
name: nas_firmware_status
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> /usr/local/sbin/getNewFirmwareAvailable.sh | sed 's/"//g' | sed 's/no upgrade/current/g'
# NAS Disk Space Total
- platform: command_line
name: nas_disk_space_total
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> df | sed -n '/HD_a2/s/ \+/ /gp' | cut -d' ' -f 2
# NAS Disk Space Used
- platform: command_line
name: nas_disk_space_used
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> df | sed -n '/HD_a2/s/ \+/ /gp' | cut -d' ' -f 3
# NAS Disk Space Free
- platform: command_line
name: nas_disk_space_free
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> df | sed -n '/HD_a2/s/ \+/ /gp' | cut -d' ' -f 4
# NAS Disk Space Percent Used
- platform: command_line
name: nas_disk_perc_used
unit_of_measurement: '%'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> df | sed -n '/HD_a2/s/ \+/ /gp' | cut -d' ' -f 5 | sed 's/%//g'
# NAS CPU Usage
- platform: command_line
name: nas_cpu_idle
unit_of_measurement: '%'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> mpstat | sed -n '/all/s/ \+/ /gp' | cut -d' ' -f 12 | sed 's/%//g'
# NAS RAM Total
- platform: command_line
name: nas_mem_tot
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/Mem:/s/ \+/ /gp' | cut -d' ' -f 2
# NAS RAM Used
- platform: command_line
name: nas_mem_used
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/buffers:/s/ \+/ /gp' | cut -d' ' -f 3
# NAS RAM Free
- platform: command_line
name: nas_mem_free
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/buffers:/s/ \+/ /gp' | cut -d' ' -f 4
# NAS RAM Cached
- platform: command_line
name: nas_mem_cached
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> cat /proc/meminfo | sed -n '/Cached/s/ \+/ /gp' | head -n 1 | cut -d' ' -f 2
# NAS Swap Total
- platform: command_line
name: nas_swap_tot
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/Swap/s/ \+/ /gp' | cut -d' ' -f 2
# NAS Swap Free
- platform: command_line
name: nas_swap_free
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/Swap/s/ \+/ /gp' | cut -d' ' -f 4
# NAS Swap Used
- platform: command_line
name: nas_swap_used
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> free -m | sed -n '/Swap/s/ \+/ /gp' | cut -d' ' -f 3
# NAS Swap Cached
- platform: command_line
name: nas_swap_cached
unit_of_measurement: 'kB'
command: ssh -i <path_to_private_key_file> -o StrictHostKeyChecking=no -q <ssh_user>@<device_ip_or_hostname> cat /proc/meminfo | sed -n '/SwapCached/s/ \+/ /gp' | cut -d' ' -f 3
# Some derived values
- platform: template
sensors:
nas_cpu_perc_used:
friendly_name: NAS CPU Usage
value_template: "{{ (100 - states('sensor.nas_cpu_idle')|float) | round(1) }}"
unit_of_measurement: '%'
nas_ram_perc_used:
friendly_name: NAS RAM Usage
value_template: "{{ ((states('sensor.nas_mem_used')|int / states('sensor.nas_mem_tot')|int) * 100) | round(1) }}"
unit_of_measurement: '%'
nas_swap_perc_used:
friendly_name: NAS Swap Usage
value_template: "{{ ((states('sensor.nas_swap_used')|int / states('sensor.nas_swap_tot')|int) * 100) | round(1) }}"
unit_of_measurement: '%'
Edit:
- Added sensors
- I had a quick look at the WD MyCloud API’s and there’s nothing there (that I can see) about getting this kind of information from the device, rather it’s more about file handling, geared at application integration.