Last active
April 22, 2023 02:01
-
-
Save xthesaintx/512845b202df4cb171614ce7ce71cff8 to your computer and use it in GitHub Desktop.
Switch Wiim to Line-in
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/env python3 | |
import requests | |
import json | |
#disable the ssl warning as Wiim SSL cert is trash | |
from urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) | |
#Set vars for the modes to switch to | |
linein="setPlayerCmd:switchmode:line-in" | |
wifi="setPlayerCmd:switchmode:wifi" | |
#Execute a command via WiiM API | |
def wiimCommand(t): | |
url="https://192.168.0.101/httpapi.asp?command="+t | |
return requests.get(url, verify=False) | |
#Returns the mode of the WiiM | |
def getMode(jsonIn): | |
status = json.loads(jsonIn) | |
return(status["mode"]) | |
#Gets the status of the WiiM as json | |
mode = wiimCommand("getPlayerStatus") | |
#Switches between modes, checks mode 40(line in) before switching | |
#10(wifi/default), if it's in rest mode it will throw up another number | |
#wont rest from linein so is the easier check | |
if getMode(mode.text) == "40": | |
wiimCommand(wifi) | |
else: | |
wiimCommand(linein) |
Updated to switch between wifi/default and line-in.
#WIIM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paired this python script (saved as a .command file) with a shortcut in MacOS that uses "run shell script" so I have a hot key to "wake-up" and switch the input to line-in of the WiiM pro that the Mac Audio is plugged into.
Shortcut Run Shell Script command:
/Users/USER/Documents/Python/wiim.command > /Users/USER/Documents/Python/error.log 2>&1