Command_line sensor not working for checking folder size (HAOS)

Hello everyone,

I am running Home Assistant OS on a mini PC and am trying to set up a command_line sensor to display the disk usage of a folder. While the command works perfectly in the terminal, the sensor is not created in Home Assistant. Instead, I get the following error:

“This entity is no longer being provided by the command_line integration. If the entity is no longer in use, delete it in settings.”

Here is the sensor definition in my configuration.yaml:

command_line:
  - sensor:
      name: Video Folder Size
      command: "du -sh /media/video_camera_1"
      unit_of_measurement: MB
      unique_id: video_folder_size

What I’ve Tested:

Manual test of the command in the terminal:
The command works perfectly in the Home Assistant terminal (SSH Add-on):

du -sh /media/video_camera_1

Output: 1.2M

Checked folder and permissions:

  • The folder /media/video_camera_1 exists.

  • Permissions have been set with chmod 777

ls -ld /media/video_camera_1

Output: drwxrwxrwx.

I fully restarted Home Assistant after making changes.

Questions:

  • Are there known limitations when using the command_line integration in HAOS, particularly with commands like du?
  • Do such commands require additional configurations to work within the HAOS container?
  • Are there alternative ways to monitor the disk usage of a folder in Home Assistant?

Thank you for your support!

Yes there are limitations, they are in the documentation.

https://www.home-assistant.io/integrations/command_line/#execution

Use the folder integration instead:

Thank you.

The folder integration didn’t work for me, so I solved the issue using a shell_command in the configuration.yaml:

shell_command:
  check_folder_size: "du -sh /media/video_camera_1"

Response:

stdout: "16.2M\t/media/video_camera_1"
stderr: ""
returncode: 0

This method works with Home Assistant OS. Thanks for the help!

1 Like