Three Automation Ideas with Plex and Home Assistant


Plex is a media server that allows you to watch live TV and your own media typically stored on a NAS (Network Attached Storage)

Home assistant and Plex have a standard integration, once you have followed those simple steps you will be redirected to Plex’s website to link your account.

 

Automations

Notify when your kid is watching an R rated movies on Plex

This first automation is going to look at the attribute media_content_rating for the Plex media player that your Kids use, I’m looking for a rating of R specifically.

I want to be notified with the name of the Movie that they are watching as I might not deem it as inappropriate.

alias: 'Notify when your Kid is watching an R rating movie on Plex'
trigger:
  - platform: template
    value_template: "{{ is_state_attr('media_player.plex_mac','media_content_rating','R') }}"
action: 
  service: notify.mobile_app_giordano_s_iphone_7
  data_template:
   message: 'Your Kids are watching {{ state_attr("media_player.plex_mac","media_title") }}  on  {{ state_attr("media_player.plex_mac","friendly_name") }}'

Watching Plex on the TV at night time

In this automation I want certain things to happen when I start watching Plex at night time. In this example I’m turning on a light to orange at around 10% brightness, setting the volume down to 20% as other people might be sleeping. I’m using the sun to determine if it is night time or not, set the sun.sun entity to below_horizon.
At the end of this automation I’m turning this off as I would want this to trigger only once, and not every time I pause / play the movie. Remember you are gong to need a daily automation to turn this back on.

alias: 'Watching Plex on the TV at night time'
trigger:
  - platform: template
    value_template: "{{ is_state('media_player.plex_mac','playing') }}"
action:
-  service: light.turn_on
   entity_id: light.living_1
   data:
     entity_id: light.living_1
     color_name: orange
     brightness_pct: 10
- service: media_player.volume_set
  entity_id: media_player.lounge
  data:
    volume_level: 0.2
    entity_id: media_player.lounge
- service: homeassistant.turn_off
  entity_id: automation.watching_plex_on_the_tv_at_night_time
condition: 
  condition: state
  entity_id: sun.sun
  state: 'below_horizon'

Notify when Kids are watching plex after bedtime

When your kids go to bed in their room, are they really sleeping while you are enjoying are winding down? With this automation you will be notified when your kids start watching Plex after a certain time on certain days. In my example I’m using 9:30 pm as my bedtime to 6:00 am. This is valid through Monday to Thursday, Friday is movie night.

I’ve added a button to actually allow you to turn off Plex on their device without actually moving from a sofa.

alias: "Notify when Kids are watching plex after bedtime"
trigger:
  - platform: template
    value_template: "{{ is_state('media_player.plex_mac','playing') }}"
action:
  service: notify.mobile_app_giordano_s_iphone_7
  data_template:
    message: 'Your Kids are watching {{ state_attr("media_player.plex_mac","media_title") }} after their bedtime!, what shall I do?'
    data:
      push:
        category: plex
condition:
  condition: time
  # At least one of the following is required.
  after: '21:30:00'
  before: '06:00:00'
  weekday:
    - mon
    - tue
    - wed
    - thu

Add this into your configuration.yaml, this is an example or IOS, but with some adjustments it will work for Android.

ios:
  push:
    categories:
      - name: plex
        identifier: 'plex'
        actions:
          - identifier: 'TURN_OFF_PLEX'
            title: 'Turn OFF Plex'
            activationMode: 'background'
            authenticationRequired: true
            destructive: true
            behavior: 'default'

This automation will be triggered when you press the button “TURN OFF” (you might have noticed it in RED) that is because of the destructive parameter being true.
The media play will stop and a little notification will appear on the device reminding them of bedtime.

alias: 'Turn OFF Plex after bedtime'
trigger: 
  platform: event
  event_type: ios.notification_action_fired
  event_data:
    actionName: TURN_OFF_PLEX
action:
-  service: notify.mobile_app_giordano_s_iphone_7
   data_template:
    message: 'Go to BED!, with love!'
-  service:  media_player.media_stop
   entity_id: media_player.plex_mac

I hope I’ve given you some cool ideas around automations with Plex. Remember to let your kids watch some movies 🙂

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts