Plex & SABnzbd Downloads Automation

Hello all! I thought I’d share something I put together today to help me out, in the hopes that it may help others too…

I run a Plex server at home and with my speeds not being supersonic (80Mbps download, 20Mbps upload) I often find that if something is downloading whilst users are watching Plex then people get buffering. For my downloads I used SABnzbd and I was pleased to spot that it has integration this morning, so on my lunch break I set it up along with a handy automation!

To combat this issue pre-Home Assistant I just had SAB pausing after 17:00 daily as that’s when usage usually rises, however it wasn’t very reliable and I still had people messaging me asking if something was wrong at random times.

With the help of Home Assistant I’ve set up an automation that pauses SABnzbd downloads if someone is watching Plex and then resumes the download when people have finished. Generally I don’t see this causing any issues with getting content as downloads can continue through the night, however if it does start causing problems then I may add in a time condition.

I did originally set this up as two separate automations (one for pausing, one for playing), however with the new choose functionality I realised that I was able to build this all into one automation instead!

Prerequisites:

The automation:

sensor.sabnzbd_status = the sensor for the status of SABnzbd, yours may be different
sensor.plex_zeus = the sensor for my Plex server (called ‘Zeus’), yours will be different!

(this has all been set up via the UI, I’m just copying the YAML for ease of sharing)

- id: '1597401858182'
  alias: SABnzbd Download Handling
  description: Pause SABnzbd downloads whilst someone is watching Plex, resume downloads
    when no one is watching!
  trigger:
  - platform: template # When the number of Plex users is more than zero (for pausing) - This catches people who start watching Plex after a SABnzbd download has already started.
    value_template: '{{ states(''sensor.plex_zeus'') | int > 0 }}' 
  - entity_id: sensor.sabnzbd_status # When the state of SABnzbd changes to 'Downloading' (for pausing) - This catches SABnzbd downloads that start when someone is already watching Plex.
    platform: state
    to: Downloading
  - entity_id: sensor.plex_zeus # When the number of Plex users changes to zero (for resuming) - This is hopefully an obvious trigger!
    platform: state
    to: '0'
  condition: []
  action:
  - choose:
    - conditions: # Condition 1 (for pausing) - When the number of Plex users is above zero **and** SABnzbd is downloading content then pause SABnzbd downloads. (I have the **and** statement in there to stop unnecessary pauses)
      - condition: and
        conditions:
        - condition: template # Just like the trigger above, here we're checking that the number of people watching Plex is above zero to meet this condition.
          value_template: '{{ states(''sensor.plex_zeus'') | int > 0 }}'
        - condition: state # Again, like the trigger we're checking that a download in ongoing in order to meet this condition.
          entity_id: sensor.sabnzbd_status
          state: Downloading
      sequence:
      - data: {}
        service: sabnzbd.pause # Pause SABnzbd downloads
    - conditions: # Condition 2 (for resuming) - When the number of people watching Plex drops to zero, resume SABnzbd downloads.
      - condition: state # Once more, we're making sure this condition is met by ensuring that the number of people watching Plex is zero!
        entity_id: sensor.plex_zeus
        state: '0'
      sequence:
      - data: {}
        service: sabnzbd.resume # Resume SABnzbd downloads!
    default: [] # No default condition is needed as if one of the above two condition is not met then we don't need Home Assistant to do anything!
  mode: single # To save any issues arising from things being paused / played at the same time I'm running this is 'single' mode.

Any questions, comments or feedback are appreciated!

Edit: Added clarity around the name of my sensors and a little bit of formatting!

4 Likes

Great automation. Works perfectly!

Thanks! I’ve actually made some big changes to this since I posted it last year. The main changes being:

  • I’ve added an override boolean so that if I want things to download despite people watching Plex
  • I’ve connected it to Tautulli so that downloads are only paused when there is someone watching Plex externally. The main reason for this was the fact that I don’t need to worry about my internet bandwidth whilst consuming Plex locally.

I’ve not put together a Blueprint yet so I’ll do that for this automation within the next couple of days to make copying it easier :+1:

1 Like

tnx, simple and very usefull :slight_smile:

Thanks for the reminder, I never did create that Blueprint :sweat_smile:

Here it is