Report Disk Space Usage

Is there a way I can run a cron job (or some other periodical script) under Hassio that will report the disk space use/available? On my other two Raspberry pi, (running Stretch) I use a simple script that runs periodically and sends my “Eventghost” server a message when usage exceeds 90%. The script looks similar to:

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' | sed 's/\//./g' )
  if [ $usep -ge 90 ]; then
    curl "http://my-eventghost.org:portNum/?RaspPi.White.$partition.Space.Used&$usep"
  fi
done

Ironically, where I need it most, on my Hassio server, I can not get this method to work. Any one have any suggestions?

1 Like

Yes, I do have this working however I cant figure out how I can report this info on a periodic time. In fact, I cant seem to get it to report at all. This is what I have

sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /home
      - type: memory_free

Then for the automation I have:

automation 30:
  alias: 'Disk Space Event'
  trigger:
    platform: state
    entity_id: sensor.disk_use_percent_home
  action:
    service: notify.EventGhost
    data:
      message: 'Disk Usage Event'

If you want to report the actual disk use rather than just the words ‘Disk Usage Event’

  action:
    service: notify.EventGhost
    data_template:
      message: "{{ states('sensor.disk_use_percent_home') }}"

Your current trigger will report whenever there is a change in the value of your disk sensor. Which is efficient. However if you really do want it to report periodically, whether the value has changed or not, use a time trigger:

  trigger:
    platform: time  # This will match every 10 minutes
    minutes: '/10'
    seconds: 00

See here for more time trigger options (every 15 minutes past the hour for example) https://www.home-assistant.io/docs/automation/trigger/#time-trigger
Also your sensor is only reporting the /home directory disk use. For total disk use, drop the argument.

sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
      - type: memory_free
2 Likes

Yes I did manage to get the actual value in the message to

data:
  message: 'Disk.Usage.Event {{ states("sensor.disk_use_percent_home") }}'

but now encounter an old problem I have never found a solution for. Assume disk percent is at 11%. To pass this message along with the 11% value the subsequent URL has to look something like

http://my-eventghost:portNum/?Disk.Usage.Event&diskusagepct

Which, when received by EG, looks like:

HTTP.Raspi.i.Disk.Usage.Event[u'11']

No matter what I have tried, I cannot get this format. I always end up with

HTTP.Raspi.i.Disk.Usage.Event11[]

I agree that reporting disk usage only when it changes is most efficient. I really don’t need to get a report for every change but only when usage exceeds at certain amount. Therefore, I came up with this:

automation 30:
  alias: 'Disk Space Event'
  trigger:
    platform: numeric_state
    entity_id: sensor.disk_use_percent_
    above: '90'
  action:
    service: notify.EventGhost
    data:
      message: 'Disk.Usage.Above.90'

Seems to work well.

Thanks everyone for your input.

Hi!

Old topic and that automation gives me an error so I created new one which send telegram message:

alias: Disk used more than 85%
description: ''
trigger:
  - platform: state
    entity_id: sensor.disk_use_percent_config
    from: '85'
condition: []
action:
  - service: telegram_bot.send_message
    data:
      message: Disk almost full (85%)
      title: Disk Space problem
mode: single

That is not a more than 85% trigger. That is a trigger that will happen if the disk use changes from 85% to anything. So it would not trigger if your use went from 70 directly to 90, or if it does hit 85% then drops back to anything below 85% it will still trigger.

You want this:

trigger:
  - platform: numeric_state
    entity_id: sensor.disk_use_percent_config
    above: 85