Monitor your DVR activity with Home Assistant

I got inspired by @Ahwman in this thread:

That got me thinking about monitoring the DVR activity in real time and more specifically what it is recording. I came up with this sensor in Home Assistant:

sensor:
  - platform: rest
    name: channels_dvr_recordings
    resource: http://192.168.4.100:8089/dvr
    value_template: >
      {% set recordings = namespace(list=[]) %}
      {% for key, value in value_json.activity.items() %}
        {% if 'Recording' in value %}
          {% set program_name = value.split(' for ')[1].split(' until')[0].strip() %}
          {% set recordings.list = recordings.list + [program_name] %}
        {% endif %}
      {% endfor %}
      {% if recordings.list | length == 0 %}
        No recordings in progress
      {% else %}
        {{ recordings.list | join(', ') }}
      {% endif %}
    scan_interval: 60

This sensor in Home Assistant will check every minute what the DVR is recording and will contain a string with the names of all the programs currently being recorded. Something like this:

As seen in Channels itself:

image

So what can you do with this?
Well, you can use it as a trigger to check if a specific program is being recorded.

Here is an example of automation to match what @Ahwman wanted to achieve:

- id: '<Redacted>' 
  alias: NHL Hockey is being recorded
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.channels_dvr_recordings
  condition:
  - condition: template
    value_template: '{{ ''NHL Hockey'' in states(''sensor.channels_dvr_recordings'')
      }}'
  action:
  - action: <turn the TV on, whatever...>

In this post, the main focus was to retrieve the current recordings but you could easily tweak the sensor to monitor other activities from the DVR (the part {% if 'Recording' in value %}) and do whatever.

Some ideas:

  • if the DVR is busy recording, turn a light on in red
  • if somebody starts watching something from the library, dim the lights in the room

Really whatever, this is Home Assistant after all, the possibilities are endless. :slight_smile:

I hope this is useful for somebody.

This is truly brilliant! It looks like you put some serious work into this, I can’t wait to play around with it. Thanks so much for sharing! :grinning:

1 Like

Here is the sensor to monitor if somebody is watching something from the library:

  - platform: rest
    name: channels_dvr_watching
    resource: http://192.168.4.100:8089/dvr
    value_template: >
      {% set watching = namespace(list=[]) %}
      {% for key, value in value_json.activity.items() %}
        {% if 'Watching' in value %}
          {% set program_name = value.split('Watching ')[1] %}
          {% set watching.list = watching.list + [program_name] %}
        {% endif %}
      {% endfor %}
      {% if watching.list | length == 0 %}
        No watching in progress
      {% else %}
        {{ watching.list | join(', ') }}
      {% endif %}

Notice that I didn't specify the scan interval. In this case, it uses the default value of 30 seconds.

For fun, I added a page on my Home Assistant dashboard with two cards:

Not particularly very useful until you create automations. :slight_smile:

I just got around to creating the sensors and they work like a charm! I wish I had a small fraction of the coding prowess that you possess, well done my friend. :grinning:

2 Likes

Thank you but I can't take all the credits. I had help from a friend: first name = Chat, last name = GPT. :grin:

Well you’re the one who put it all together and had the original idea. In any case, I will be using these templates in several automations. Fun stuff for a nerd like me :grinning:.

1 Like

thanks