Last active
February 21, 2020 21:36
-
-
Save satmandu/d4378d6e53e94f88480adeffe3595d45 to your computer and use it in GitHub Desktop.
Sets volumes for all Google home device on the local network programmatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Sets volumes for all Google home device on the local network programmatically. | |
# Adapted from script at https://pastebin.com/ke3Z65pm | |
# from this discussion by reddit user Mjjjjjjjjjjjjjjjj | |
# https://www.reddit.com/r/googlehome/comments/8b0b4o/python_script_to_manage_the_volume_of_multiple/ | |
# | |
from __future__ import print_function | |
import time | |
import sys | |
import pychromecast | |
# Wrote this for the fun of it and because I have OCD. | |
# I am sure there are better ways to do this but since I didn't see any, here it is. | |
# Find Devices | |
print ("-- Discovering Devices\n") | |
chromecasts = pychromecast.get_chromecasts() | |
for device in chromecasts: | |
# Check if a device is a Chromecast. | |
if "Chromecast" not in device.model_name: | |
# These sleeps seem necessary. | |
time.sleep(1) | |
device.wait() | |
print(str(device)) | |
print("-- Current Volume: {0}%".format(int(device.status.volume_level*100))) | |
print("-- Setting Night Volume to 10%...") | |
device.set_volume(.1) | |
time.sleep(1) | |
print("-- New Volume: {0}%\n".format(int(device.status.volume_level*100))) | |
# If device is a Chromecast and will not set volume | |
else: | |
device.wait() | |
print(str(device)) | |
print("-- Current Volume: {0}%".format(int(device.status.volume_level*100))) | |
print("-- Device is a Chromecast, leaving it alone...\n") | |
# Apparently needed so the script can terminate cool | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment