Using Folder Sensor with /backup

I am running HA Supervised. I would like to monitor the size of my backup. Was going to use:

    - /backup

  - platform: folder
    folder: /backup

But I get the following config errors:
not a directory @ data['whitelist_external_dirs'][1]


Invalid config for [sensor.folder]: not a directory for dictionary value @ data['folder']. Got '/backup'.

I have also tried '/backup' and '/backup/'. Is this folder just not available to accomplish this?

Did you find any solutions? I am also looking.

I did not. I just abandoned the idea

If you are running Home Assistant in docker, I have a work around.

alternative, path needs to be changed of course

  - platform: command_line
    scan_interval: 300
    unit_of_measurement: bytes
    name: Backup Size
    command: "du -cs /usr/share/hassio/backup | grep total | sed 's/\<total\>//g'"

possible issue with your approach:

If you’re running on docker check if there’s a volume mapped to /backup or in other words check if the directory exists

I changed the path to /backup and I am getting the following:

unknown escape sequence at line 42, column 53:
… /backup | grep total | sed ‘s/<total>//g’"

It seems you didnt escape the < and > as above code works fine for me. Also make sure /backup exists in your filesystem.

I think you were using the wrong type of apostrophe, at least it looks like it

what is your workaround?

I pasted it in exactly as you have it. Not sure what the issue is. I can’t even whitelist /backup so I am stuck anyway

This is how I have successfully implemented it. I am using HA docker installed in Raspbian OS. I also use the auto snapshot backup addon with HA. First I have used the crontab -e command in terminal to schedule a command maybe 30 minutes after the time set for initiating auto backup. The command is 30 4 * * * sudo du -h -s /usr/share/hassio/backup |cut -d'M' -f1 | sudo tee /usr/share/hassio/homeassistant/www/node_red/size.text . In my case the above command is scheduled to run at 4.30am every day as I have set the time for auto backup at 4am. Please mind this time difference is very crucial.

This command will write the size of the snapshot created to a file with the name size.text in www folder of HA, after the backup has been initiated. Then you can use a file sensor in HA to read the contents of the file which is the size of the snapshot.

Due to the limitations of the folder sensor (not able to access /backup as HA container when running HA OS), I went the MQTT path instead of using a file as temporary information cache. Works the same. Following InfluxDB information (database size) as sensor in Home Assistant - #17 by e-raser where InfluxDB folder size is gathered - same process.

The clue is to get the information at all, for this I used the community SSH & Web Terminal with protection mode off and using this within the init_commands in the addons configuration section:

while [ 1 = 1 ]; do du -shm /backup | cut -f1 | mosquitto_pub -t homeassistant/sensor/system/foldersize/backup -r -u '<mqtt_username>' -P '<mqtt_password>' -l -i 'SSH-addon_init-command_1' && sleep 900; done &

So every 15 minutes (sleep 900) the size is calculated and sent to the MQTT broker.

Then the following MQTT sensor creates the sensor entity:

    - name: Home-Assistant Size Folder /backup
      unique_id: abc-abc-abc-abc
      #entity_id: sensor.home_assistant_size_folder_backup
      unit_of_measurement: MB
      icon: mdi:folder
      state_topic: "homeassistant/sensor/system/foldersize/backup"
      state_class: total
      entity_category: diagnostic
      value_template: "{{ value }}"