-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonosmusic2lox.py
25 lines (21 loc) · 968 Bytes
/
sonosmusic2lox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import time
from soco import discover
import requests
while True:
for zone in discover():
# Check if this zone is part of a group and not the coordinator
if zone.group.coordinator.player_name != zone.player_name:
# Get track info from the coordinator
track_info = zone.group.coordinator.get_current_track_info()
else:
# Get track info from this zone
track_info = zone.get_current_track_info()
# Check if the track_info is not empty -> music is playing
if track_info["title"] != "":
music_info = f"{zone.volume}% | {track_info['title']} | {track_info['artist']}"
else:
music_info = f"{zone.volume}% | Idle"
print(f"{zone.player_name}: {music_info}")
# Send the music info to the Loxone Miniserver
r = requests.get(f"http://USER:PASSWORT@IPADDRESS/dev/sps/io/Sonos {zone.player_name}/{music_info}")
time.sleep(10)