import time import pychromecast from pychromecast.controllers.receiver import CastStatusListener import sys class MyCastStatusListener(CastStatusListener): """Cast status listener""" def __init__(self, name, cast): self.name = name self.cast = cast def new_cast_status(self, status): print("event listener triggered and waiting") time.sleep(120) print("Event listener done") chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["replace this"]) for cc in chromecasts: print(cc.cast_info) cc.wait() cc.register_status_listener(MyCastStatusListener(cc.name,cc)) while True: #may need to run set_volume once just to trigger the event handler, hence the loop try: print("about to set volume") cc.set_volume(.3) print("setting volume worked") except Exception as e: print("setting volume failed: ",e) sys.exit() time.sleep(1)