Last active
March 24, 2016 17:03
-
-
Save noestreich/362e0a458c34e43a98fe to your computer and use it in GitHub Desktop.
This file contains 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 python | |
import urllib, json, datetime, time, os, soco | |
# HUE Bridge IP | |
url = 'http://192.168.1.48/api/newdeveloper' | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
button = data['sensors']['3']['state']['buttonevent'] | |
klickzeit = data['sensors']['3']['state']['lastupdated'] | |
klickzeitunix = time.mktime(datetime.datetime.strptime(klickzeit, "%Y-%m-%dT%H:%M:%S").timetuple()) | |
timestamp = int(time.time()) | |
speakers = soco.discover() | |
swiss_media_uri = 'x-sonosapi-stream:s48811?sid=254&flags=32' | |
swiss_media_metadata = '<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="-1" parentID="-1" restricted="true"><dc:title>SwissGroove Radio</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>' | |
dradio_media_uri = 'x-sonosapi-stream:s15028?sid=254&flags=32&sn=0' | |
dradio_media_metadata = '<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="-1" parentID="-1" restricted="true"><dc:title>Deutschlandfunk</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>' | |
brklassik_media_uri = 'x-sonosapi-stream:s44284?sid=254&flags=8224&sn=0' | |
brklassik_media_metadata = '<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="-1" parentID="-1" restricted="true"><dc:title>BR-Klassik</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>' | |
if (timestamp-klickzeitunix-3600 > 0 and timestamp-klickzeitunix-3600 < 60): | |
if (button == 1000 or button == 1001 or button == 1002 or button == 1003): | |
print "AN innerhalb der letzten Minute" | |
print button | |
for speaker in speakers: | |
if speaker.group.coordinator is speaker: | |
speaker.partymode() | |
speaker.play_uri(swiss_media_uri, swiss_media_metadata, start=True) | |
break | |
speaker.volume = 16 | |
elif (button == 2000 or button == 2001 or button == 2002 or button == 2003): | |
print "Dimmer-Hoch innerhalb der letzten Minute" | |
print button | |
for speaker in speakers: | |
if speaker.group.coordinator is speaker: | |
speaker.partymode() | |
speaker.play_uri(dradio_media_uri, dradio_media_metadata, start=True) | |
break | |
speaker.volume = 17 | |
elif (button == 3000 or button == 3001 or button == 3002 or button == 3003): | |
print "Dimmer-Runter innerhalb der letzten Minute" | |
print button | |
for speaker in speakers: | |
if speaker.group.coordinator is speaker: | |
speaker.partymode() | |
speaker.play_uri(brklassik_media_uri, brklassik_media_metadata, start=True) | |
break | |
speaker.volume = 17 | |
elif (button == 4000 or button == 4001 or button == 4002 or button == 4003): | |
print "AUS innerhalb der letzten Minute" | |
print button | |
for speaker in speakers: | |
if speaker.group.coordinator is speaker: | |
speaker.partymode() | |
speaker.stop() | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment