Implements better CEC controls for Chromecasts. Currently has two functions:
Tested on Raspberry Pi running Raspbian Buster.
sudo apt-get install libcec-dev libcec4
sudo pip3 install -r requirements.txt
sudo python3 chromecast_controls.py --setup
for interactive setup and installChromecast can switch on modern TVs/receivers (using HDMI CEC) when you start casting to it. But for some reason, Google didn't implement a feature to switch off devices when it's been sitting idle for a while. This wastes power (somewhere in the ballpark of 50-100W). ChromecastControls fixes this by detecting when the Chromecast is sitting idle, and putting any connected equipment into standby.
Ever see the message "Surround Sound enabled. To adjust volume, use your TV's remote control" when trying to change the volume for something you're casting from your phone? Chromecast can modify volume for stereo sources, but not surround sound. However, CEC can send a signal to your TV/receiver to change the volume. Why the Chromecast doesn't send this signal is anyone's guess. But ChromecastControls can detect when you've attempted to change the volume via your phone, and sends the corresponding CEC signals to your equipment.
The PyChromecast library can listen on your network for any events related to your Chromecast. In this case, the events we're listening for are status changes (an app connects to or disconnects from the Chromecast) or volume changes. When ChromecastControls detects such a change it sends a corresponding signal on the HDMI CEC bus to control the equipment (using libcec and python-cec). The Raspberry Pi is perfect for this as it has an inbuilt CEC signalling in the HDMI connector - most computers don't have this (you could try a Pulse-8 adapter, but this hasn't been tested). For standby/power-off, ChromecastControls first waits for a set amount of time before turning things off.