Command line sensor - directory recursive size not working

Hello,
I want to create sensor for counting directory with subdirectories size. I made something like this (yes I know I can add h parameter and ommit value templating) but it is not working as expected. I am using HassIO and I get this as a result:

8176 /config/www/camera_recordings 
  - platform: command_line
    name: Camera recordings size
    command: "du -s /config/www/camera_recordings" 
    unit_of_measurement: "MB"
    value_template: '{{ value | multiply(0.001) | round(2) }}' 

My whitelist looks like this:

  whitelist_external_dirs:
    - /config/

You have to split the return value first to get rid of the path after the number.
This works for me:

- platform: command_line
  name: Ordnergröße MotionEye
  command: 'du -s /media/HA/motioneye'
  unit_of_measurement: 'MiB'
  value_template: '{{ value.split("\t" )[0] | multiply(1/1024) | round(2) }}'

If your command_line template fails check the log.
There should be at least some hint to what went wrong.

I did not need to whitelist (or allowlist) any dirs to do this.
Be warned though that in the scope of the command_line shell execution it seems that only the following folders are mounted: /config, /share, /ssl, /media
NOT mounted by default are: /addons, /backup

1 Like