149 lines
16 KiB
JSON
149 lines
16 KiB
JSON
[
|
|
{
|
|
"id": "Tautulli Kill Stream - Paused Sessions After X Minutes",
|
|
"automation": "- alias: Tautulli Kill Stream - Paused Sessions After X Minutes\n description: 'Terminates any Plex session reported by Tautulli that has been paused\n longer than a specified number of minutes (configurable in ''pause_limit_minutes'').\n\n '\n mode: single\n variables:\n pause_limit_minutes: 10\n trigger:\n - platform: time_pattern\n minutes: /1\n condition: []\n action:\n - variables:\n sessions: '{{ state_attr(''sensor.tautulli_stream_count'',''sessions'') | default([])\n }}'\n - repeat:\n for_each: '{{ sessions }}'\n sequence:\n - variables:\n this_session: '{{ repeat.item }}'\n sid: '{{ this_session.session_id | default(''unknown'') }}'\n paused_sec: '{{ this_session.Stream_paused_duration_sec | float(0) }}'\n state: '{{ this_session.state | lower | default(''unknown'') }}'\n - if:\n - condition: template\n value_template: \"{{ state == 'paused'\\n and paused_sec > (pause_limit_minutes\\\n \\ * 60) \\n and sid != 'unknown' }}\\n\"\n then:\n - service: tautulli_active_streams.kill_session_stream\n data:\n session_id: '{{ sid }}'\n message: 'Session paused more than {{ pause_limit_minutes }} minutes. Terminating.\n\n '",
|
|
"config": [
|
|
{
|
|
"name": "tautulli stream count sensor",
|
|
"room": null,
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.tautulli_stream_count",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "tautulli active streams service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "tautulli_active_streams"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Tautulli Kill Streams - Limit All Users to One Session ( With User Exclusions)",
|
|
"automation": "- alias: Tautulli Kill Streams - Limit All Users to One Session ( With User Exclusions)\n description: 'Terminates the newest stream when any non-excluded user has multiple\n active sessions, based on ''user'' and ''start_time_raw''. Skips partial updates\n where session_id is missing or empty, and allows excluded users to have multiple sessions\n without being terminated.\n\n '\n variables:\n excluded_users:\n - admin\n - plex_admin\n mode: single\n trigger:\n - platform: state\n entity_id: sensor.tautulli_stream_count\n condition:\n - condition: template\n value_template: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is none or sessions|length <= 1 %}\\n false\\n{% else %}\\n\\\n \\ {% set ns = namespace(duplicate_found=false, seen=[]) %}\\n {% for s in sessions\\\n \\ %}\\n {% if s.user is defined and s.user|trim != '' \\n and s.session_id\\\n \\ is defined and s.session_id|trim != '' %}\\n {% set user_lower = s.user|lower|trim\\\n \\ %}\\n {% if user_lower not in excluded_users %}\\n {% if user_lower\\\n \\ in ns.seen %}\\n {% set ns.duplicate_found = true %}\\n {% else\\\n \\ %}\\n {% set ns.seen = ns.seen + [user_lower] %}\\n {% endif\\\n \\ %}\\n {% endif %}\\n {% endif %}\\n {% endfor %}\\n {{ ns.duplicate_found\\\n \\ }}\\n{% endif %}\"\n action:\n - service: persistent_notification.create\n data:\n title: Duplicate Plex Sessions Detected\n message: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is not none %}\\n {% set ns = namespace(duplicates=[])\\\n \\ %}\\n {% set seen_users = namespace(list=[]) %}\\n {% for s in sessions\\\n \\ %}\\n {% if s.user is defined and s.user|trim != '' \\n and s.session_id\\\n \\ is defined and s.session_id|trim != '' %}\\n {% set user_lower = s.user|lower|trim\\\n \\ %}\\n {% if user_lower not in excluded_users %}\\n {% if user_lower\\\n \\ in seen_users.list %}\\n {% set ns.duplicates = ns.duplicates +\\\n \\ [s] %}\\n {% else %}\\n {% set seen_users.list = seen_users.list\\\n \\ + [user_lower] %}\\n {% endif %}\\n {% endif %}\\n {% endif\\\n \\ %}\\n {% endfor %}\\n Found {{ ns.duplicates|length }} duplicate session(s):<br><br>\\n\\\n \\ {% for d in ns.duplicates %}\\n - User: {{ d.user }}<br>\\n Session ID:\\\n \\ {{ d.session_id }}<br>\\n Title: {{ d.full_title }}<br>\\n start_time:\\\n \\ {{ d.stream_start_time if d.stream_start_time is defined else 'unknown'\\\n \\ }}<br><br>\\n {% endfor %}\\n{% else %}\\n No sessions found.\\n{% endif %}\"\n - service: tautulli_active_streams.kill_session_stream\n data:\n session_id: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is none %}\\n unknown\\n{% else %}\\n {% set ns = namespace(duplicates=[])\\\n \\ %}\\n {% set seen_users = namespace(list=[]) %}\\n {% for s in sessions\\\n \\ %}\\n {% if s.user is defined and s.user|trim != '' \\n and s.session_id\\\n \\ is defined and s.session_id|trim != '' %}\\n {% set user_lower = s.user|lower|trim\\\n \\ %}\\n {% if user_lower not in excluded_users %}\\n {% if user_lower\\\n \\ in seen_users.list %}\\n {% set ns.duplicates = ns.duplicates +\\\n \\ [s] %}\\n {% else %}\\n {% set seen_users.list = seen_users.list\\\n \\ + [user_lower] %}\\n {% endif %}\\n {% endif %}\\n {% endif\\\n \\ %}\\n {% endfor %}\\n {% if ns.duplicates|length > 0 %}\\n {% set sorted\\\n \\ = ns.duplicates|sort(attribute='start_time_raw') %}\\n {{ sorted[-1].session_id\\\n \\ }}\\n {% else %}\\n unknown\\n {% endif %}\\n{% endif %}\"\n message: Admin Notified! Multiple sessions detected. Session Terminated.",
|
|
"config": [
|
|
{
|
|
"name": "tautulli stream count sensor",
|
|
"room": null,
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.tautulli_stream_count",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "tautulli active streams service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "tautulli_active_streams"
|
|
}
|
|
},
|
|
{
|
|
"name": "persistent notification service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "persistent_notification"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Tautulli Kill Duplicate Plex Streams (Username)",
|
|
"automation": "- alias: Tautulli Kill Duplicate Plex Streams (Username)\n description: 'Terminates the newest stream when a user has multiple active sessions,\n based on ''username'' and ''start_time_raw''.\n\n '\n triggers:\n - entity_id: sensor.tautulli_stream_count\n trigger: state\n conditions:\n - condition: template\n value_template: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is none or sessions|length <= 1 %}\\n false\\n{% else %}\\n\\\n \\ {% set ns = namespace(duplicate_found=false, seen=[]) %}\\n {% for s in sessions\\\n \\ %}\\n {% if s.username is defined and s.username|trim != '' %}\\n {%\\\n \\ set user_lower = s.username|lower|trim %}\\n {% if user_lower in ns.seen\\\n \\ %}\\n {% set ns.duplicate_found = true %}\\n {% else %}\\n \\\n \\ {% set ns.seen = ns.seen + [user_lower] %}\\n {% endif %}\\n {% endif\\\n \\ %}\\n {% endfor %}\\n {{ ns.duplicate_found }}\\n{% endif %}\\n\"\n actions:\n - data:\n title: Duplicate Plex Sessions Detected\n message: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is not none %}\\n {# Use a namespace to ensure our duplicates\\\n \\ list persists #}\\n {% set ns = namespace(duplicates=[]) %}\\n {% set seen_users\\\n \\ = namespace(list=[]) %}\\n \\n {# Gather duplicates #}\\n {% for s in sessions\\\n \\ %}\\n {% if s.username is defined and s.username|trim != '' %}\\n \\\n \\ {% set user_lower = s.username|lower|trim %}\\n {% if user_lower in\\\n \\ seen_users.list %}\\n {% set ns.duplicates = ns.duplicates + [s] %}\\n\\\n \\ {% else %}\\n {% set seen_users.list = seen_users.list + [user_lower]\\\n \\ %}\\n {% endif %}\\n {% endif %}\\n {% endfor %}\\n \\n Found {{ ns.duplicates|length\\\n \\ }} duplicate session(s):<br><br>\\n {% for d in ns.duplicates %}\\n - Username:\\\n \\ {{ d.username }}<br>\\n Session ID: {{ d.session_id }}<br>\\n Title:\\\n \\ {{ d.full_title }}<br>\\n Start Time (raw): {{ d.start_time_raw }}<br><br>\\n\\\n \\ {% endfor %}\\n{% else %}\\n No sessions found.\\n{% endif %}\\n\"\n action: persistent_notification.create\n - data:\n session_id: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is none %}\\n unknown\\n{% else %}\\n {% set ns = namespace(duplicates=[])\\\n \\ %}\\n {% set seen_users = namespace(list=[]) %}\\n {% for s in sessions\\\n \\ %}\\n {% if s.username is defined and s.username|trim != '' %}\\n \\\n \\ {% set user_lower = s.username|lower|trim %}\\n {% if user_lower in\\\n \\ seen_users.list %}\\n {% set ns.duplicates = ns.duplicates + [s] %}\\n\\\n \\ {% else %}\\n {% set seen_users.list = seen_users.list + [user_lower]\\\n \\ %}\\n {% endif %}\\n {% endif %}\\n {% endfor %}\\n {% if ns.duplicates|length\\\n \\ > 0 %}\\n {% set sorted = ns.duplicates|sort(attribute='start_time_raw')\\\n \\ %}\\n {{ sorted[-1].session_id }}\\n {% else %}\\n unknown\\n {% endif\\\n \\ %}\\n{% endif %}\\n\"\n message: Admin Notified! Multiple sessions Detected. Terminated Stream.\n action: tautulli_active_streams.kill_session_stream\n mode: single",
|
|
"config": [
|
|
{
|
|
"name": "tautulli stream count sensor",
|
|
"room": null,
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.tautulli_stream_count",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "tautulli active streams service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "tautulli_active_streams"
|
|
}
|
|
},
|
|
{
|
|
"name": "persistent notification service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "persistent_notification"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Tautulli Kill Streams - Limit Fixed User - Kill All",
|
|
"automation": "- alias: Tautulli Kill Streams - Limit Fixed User - Kill All\n description: 'Terminates all Plex streams for \"CHANGE_ME\" whenever sensor.tautulli_stream_count\n changes.\n\n '\n trigger:\n - platform: state\n entity_id: sensor.tautulli_stream_count\n condition:\n - condition: template\n value_template: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is none or sessions|length == 0 %}\\n false\\n{% else %}\\n\\\n \\ {% set ns = namespace(found=false) %}\\n {% for s in sessions %}\\n {%\\\n \\ if s.username is defined and s.username|lower|trim == 'CHANGE_ME' %}\\n \\\n \\ {% set ns.found = true %}\\n {% endif %}\\n {% endfor %}\\n {{ ns.found\\\n \\ }}\\n{% endif %}\"\n action:\n - service: tautulli_active_streams.kill_user_stream\n data:\n user: CHANGE_ME\n message: Stream has been stopped by Admin. Contact for Support\n mode: single",
|
|
"config": [
|
|
{
|
|
"name": "tautulli stream count sensor",
|
|
"room": null,
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.tautulli_stream_count",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "tautulli active streams service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "tautulli_active_streams"
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"id": "Tautulli Kill Streams - Limit Fixed User - One Stream Only",
|
|
"automation": "- alias: Tautulli Kill Streams - Limit Fixed User - One Stream Only\n description: 'Monitors sensor.tautulli_stream_count for the user \"CHANGE_ME\". If\n that user has more than one active session, the newest session is terminated.\n\n '\n trigger:\n - platform: state\n entity_id: sensor.tautulli_stream_count\n condition:\n - condition: template\n value_template: \"{% set sessions = state_attr('sensor.tautulli_stream_count',\\\n \\ 'sessions') %} {% if sessions is none or sessions|length < 2 %}\\n false\\n\\\n {% else %}\\n {% set matched = sessions\\n | selectattr('username','defined')\\n\\\n \\ | selectattr('username','equalto','CHANGE_ME')\\n | list %}\\n {{ matched|length\\\n \\ >= 2 }}\\n{% endif %}\"\n action:\n - service: persistent_notification.create\n data:\n title: Duplicate Sessions Detected for CHANGE_ME\n message: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is not none %}\\n {% set matched = sessions\\n | selectattr('username','defined')\\n\\\n \\ | selectattr('username','equalto','CHANGE_ME')\\n | list %}\\n {%\\\n \\ if matched|length >= 2 %}\\n Found {{ matched|length }} sessions for CHANGE_ME:<br><br>\\n\\\n \\ {% for s in matched %}\\n - Session ID: {{ s.session_id }}<br>\\n \\\n \\ Title: {{ s.full_title }}<br>\\n start_time_raw: {{ s.start_time_raw\\\n \\ }}<br><br>\\n {% endfor %}\\n {% else %}\\n No duplicates found.\\n \\\n \\ {% endif %}\\n{% else %}\\n No session data available.\\n{% endif %}\"\n - service: tautulli_active_streams.kill_session_stream\n data:\n session_id: \"{% set sessions = state_attr('sensor.tautulli_stream_count','sessions')\\\n \\ %} {% if sessions is not none %}\\n {% set matched = sessions\\n | selectattr('username','defined')\\n\\\n \\ | selectattr('username','equalto','CHANGE_ME')\\n | sort(attribute='start_time_raw')\\\n \\ \\n | list %}\\n {% if matched|length >= 2 %}\\n {{ matched[-1].session_id\\\n \\ }}\\n {% else %}\\n unknown\\n {% endif %}\\n{% else %}\\n unknown\\n{%\\\n \\ endif %}\"\n message: 'Admin Notice: Exceeded the one-session limit. Terminating newest session.'\n mode: single",
|
|
"config": [
|
|
{
|
|
"name": "tautulli stream count sensor",
|
|
"room": null,
|
|
"type": "sensor",
|
|
"id": {
|
|
"entity_id": "sensor.tautulli_stream_count",
|
|
"device_id": null
|
|
}
|
|
},
|
|
{
|
|
"name": "tautulli active streams service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "tautulli_active_streams"
|
|
}
|
|
},
|
|
{
|
|
"name": "persistent notification service",
|
|
"room": null,
|
|
"type": "service",
|
|
"id": {
|
|
"entity_id": null,
|
|
"device_id": "persistent_notification"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
] |