How-to: get notified with Home Assistant when low disk space on DVR

I finally got around to play with this and got it to work quite easily with some help from ChatGPT, which saved me some time.

Nothing really complicated, Home Assistant makes it quite easy.

Step 1: create a new sensor in /config/configuration.yaml:

sensor:
  - platform: rest
    resource: http://192.168.0.155:8089/dvr
    name: channels_dvr_disk_space
    value_template: '{{ value_json.disk.free }}'

(YAML code accurately generated by ChatGPT)

--- Edit (5/14/2023) ---

This sensor as written returns the disk size in bytes, which is a big number with a lot of digits and that is not easy to digest. You can make it easier to use with this slight optimization:

sensor:
  - platform: rest
    resource: http://192.168.0.155:8089/dvr
    name: channels_dvr_disk_space
    value_template: '{{ value_json.disk.free  | int / (1024*1024*1024)) | round(2) }}'

Now it will have the value 102.89 instead of 110477296271. This is the way you see it on the server's web UI too.
image

This simplifies automations too because you can use simple numbers, such as 100 or 50.

--- End of edit ---

Make sure to use the IP address of your Channels DVR server in the "resource" field.

Step 2: restart Home Assistant to load the new configuration

Step 3: create an automation that uses the numeric state of this new sensor as a trigger and performs any actions you wish (send a mobile notification, send an email or SMS, flash some lights, make an announcement in your house on your smart speakers, etc.)

For example, as a quick test, I created an automation that sends me a notification in the Home Assistant Android companion app when the disk space on the DVR falls below 100 GB, which actually happened earlier before I started typing this post.

Notification received on my phone:

I prefer to use the UI as much as possible to create automations and this is what it looks like:

Here is the YAML version of the automation:

alias: Channels DVR Disk Space
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.channels_dvr_disk_space
    below: 100
    alias: Less than 100 GB left on DVR
    id: Less than 100 GB
condition: []
action:
  - service: notify.mobile_app_gildas_cell
    data:
      message: Disk space on DVR below 100 GB
      title: Low disk space on Channels DVR
mode: single

I will extend this automation so that it sends me a text when the disk space drops below 75 GB and, additionally, make an announcement in the house on my Google Nest speakers when it drops below 50 GB.

Once you have this sensor, the possibilities are endless with Home Assistant for what actions you want to perform.

This is fun and actually useful.

I hope this helps somebody.

1 Like

Low disk space is not a problem. The DVR actively manages the free space and proactively removes old recordings to free up more space.

Is that right? That must be a recent change in behavior because I got burnt once last year when I forgot to maintain my disk space and new recordings failed because the disk was full. For me, the DVR didn't do any cleanup, it simply stopped recording new shows.

Even if this is the case that it removes old recordings, I don't want it to do that so it is in my best interest to make sure there is always enough disk space for new recordings.
I have extra storage outside of the recording drive so once in a while I need to move recordings in order to make room.
We record a lot and keep a lot in order to build local libraries of shows.

1 Like

Channels DVR Server does not manage storage in the context of becoming low on storage. In that, it will not delete items from your library. That’s your responsibility.

It will automatically prune your recordings based on the rules you set in your pass, though, ensuring you don’t just keep using storage up or making you constantly be an administrator deleting recordings.

1 Like

That's what I thought. Thank you for the explanation and confirming.

I thought it would be fun - and hopefully helpful - to show the prompt that I used in ChatGPT in order to get to the solution very quickly.

I'm sure some of you may be very familiar with Home Assistant and YAML to the point of doing it very easily yourselves. That's not my case, I'm a newbie.
I probably could have figured out the solution on my own but it would probably have taken many hours, if not days, of reading documentation and possibly forum posts to see what others have done.

ChatGPT is not always correct in its answers but this time it was spot on and gave me the solution in 1 minute. It saved me a lot of time!

You will see in my prompt that I used the word "Please" as if I was chatting with a real person. :joy: Definitely not necessary but it happened. :grin:
Anyway, here is my "conversation" with ChatGPT:

Me:

I want to create a custom template named channels_dvr_disk_space in Home Assistant. Its value will come from a json array retrieved from the web page http://192.168.0.155:8089/dvr. The json value will be in the keys ['disk']['free']. Please suggest the code to write to create this template.

ChatGPT:

To create a custom template named channels_dvr_disk_space in Home Assistant that retrieves the disk['free'] value from the JSON array retrieved from http://192.168.0.155:8089/dvr , you can use the following code:

sensor:
  - platform: rest
    resource: http://192.168.0.155:8089/dvr
    name: channels_dvr_disk_space
    value_template: '{{ value_json.disk.free }}'

This code defines a REST sensor that retrieves data from the specified URL and extracts the disk['free'] value from the JSON array using the value_template . The resulting value will be stored in the channels_dvr_disk_space sensor in Home Assistant.

Me:

I don't see where value_json is defined

ChatGPT:

value_json is a variable in Home Assistant that represents the parsed JSON response from the resource defined in the rest sensor. The rest sensor platform automatically parses the JSON response from the specified resource URL and stores it in the value_json variable.

In the code snippet I provided, the value_template is used to extract the disk['free'] value from the value_json variable using the Jinja2 template syntax. The double curly braces {{ }} are used to indicate a Jinja2 template variable.

So, in the value_template for the channels_dvr_disk_space sensor, value_json.disk.free is used to access the disk['free'] value in the parsed JSON response.

I hope this clarifies things for you!

That's pretty good!
From a technical point of view, this is amazing (at least to me)!

Personally, I'm happy to be alive to witness the (r)evolution of AI.
I know some people have fears about AI "taking over" or whatever.
I don't mean this thread to be a philosophical discussion about AI so please keep it technical and on topic if you reply. Otherwise, I will request that this thread be closed.

I just wanted to post this for educational purposes.
Maybe this will inspire others. :slight_smile:

1 Like

As a Home Assistant noob, that's really cool. Unfortunately, I don't have this need as I'm only using 18.9TB of the 72TB UnRaid NAS I built last year. The NAS runs Home Assistant as a VM and I have docker containers for Channels-DVR, Plex, Wyze-Bridge, and 2 SQL Server instances.

1 Like

The HA folks actually hate Chat GPT. :slight_smile: But very cool that you got it to work!

1 Like

Wow, that's a great setup that you have. I only have 15 TB of external drives for now + 1 TB internal drive for recordings.
Sooner rather than later, I will need to expand my storage. :grin:

That's true, HA doesn't want anybody to use ChatGPT to generate answers to people's questions. :laughing: That's understandable because its answers are not always correct.

As your personal helper though, it is very convenient. :smiley:

1 Like