Linux Emby Server Sleep on Inactivity?

Would probably need to write a script to check if something is running. I have no idea if below works.. it's a python script created by chatgpt

Can you write me a python script that checks Emby media server, if anything is playing? If nothing is playing for 10 minutes, put ubuntu server in hybernation mode.

import requests

import subprocess import time

def check_emby_status(): emby_base_url = "http://your.emby.server.com" emby_api_key = "your_api_key" url = f"{emby_base_url}/emby/Sessions?api_key={emby_api_key}"

time_nothing_playing = 0
while True:
    response = requests.get(url)

    if response.status_code == 200:
        sessions = response.json()
        if len(sessions) > 0:
            print("Something is currently playing on the Emby server.")
            time_nothing_playing = 0
        else:
            print("Nothing is currently playing on the Emby server.")
            time_nothing_playing += 1
            if time_nothing_playing >= 60:
                print("Putting the server in hibernation mode.")
                subprocess.call(["systemctl", "hibernate"])
                break
    else:
        print("Unable to retrieve Emby server status.")

    time.sleep(10)

check_emby_status()

/r/emby Thread Parent