stoffi hat geschrieben: Drückt man die Taste aber lange im Wohnzimmer, schaltet sich das Wohnzimmer an und die anderen Räume ab. So eine Art follow me.
Ein umschalten wäre dann auch mit Bewegungsmeldern und automatisch denkbar
Da ist die Lösung Irgendwie komplizierter als gedacht ... Code kann vielleicht noch etwas optimiert werden z.b. durch Repeatschleifen. Aber das ist erstmal die Quick & Dirty Funktioniert Lösung
Code: Alles auswählen
--Multiroom Scripte für Airplay, zur Steuerung über SSH von der Homematic CCU2!
--Version 0.9 (Server Version)
--Copyright by eiGelbGeek / Kontakt: geekmatic (at) icloud.com
#Räume an den Namen der Airplay Devices anpassen!
set Raum1 to "Wohnzimmer"
set Raum2 to "Schlafzimmer"
set Raum3 to "Büro"
set Raum4 to "Küche"
set Raum5 to "Badezimmer"
# CCU IP und ise ID von den CCU Systemvaribalen für AN/AUS und Volume Anzeige der Airplay Lautsprecher!
set ccu_ip to "192.168.20.100"
set ise_ID_OnOff_Raum1 to "00000"
set ise_ID_Vol_Raum1 to "00000"
set ise_ID_OnOff_Raum2 to "00000"
set ise_ID_Vol_Raum2 to "00000"
set ise_ID_OnOff_Raum3 to "00000"
set ise_ID_Vol_Raum3 to "00000"
set ise_ID_OnOff_Raum4 to "00000"
set ise_ID_Vol_Raum4 to "00000"
set ise_ID_OnOff_Raum5 to "00000"
set ise_ID_Vol_Raum5 to "00000"
#################################
# Ab hier keine Änderungen vornehmen !!! #
#################################
#Sound Ausgang des Mac auf Mute setzen
set volume with output muted
tell application "iTunes"
#Sound Volume vom Computer auf 100 setzen, sonst kommt es zu Problemen in der Lautstärkeregelung einzelner Airplay Lautsprecher!
set sound volume of AirPlay device "Computer" to 100
#Abfragen der ausgewählten Airplay Lautsprecher
set apSpeakersSelected to (get name of every AirPlay device whose selected is true)
#Definition des einzuschaltenden Airplay Lautsprecher
set apOn to Raum1
#Neue Auswahl der Airplay Lautsprecher zusammen setzen
#CCU Status setzen wenn Raum 1 vorhanden, sonst Script beenden!
set apSpeakersAvailable to (get name of every AirPlay device whose available is true)
end tell
if apSpeakersAvailable contains Raum1 then
set apSpeakersNewSelected to apSpeakersSelected
set end of apSpeakersSelected to apOn
set aURL to "curl /dev/null 'http://"
set bURL to "/config/xmlapi/statechange.cgi?ise_id="
set cURL to "&new_value=1'"
set dURL to aURL & ccu_ip & bURL & ise_ID_OnOff_Raum1 & cURL
do shell script dURL
else
set aURL to "curl /dev/null 'http://"
set bURL to "/config/xmlapi/statechange.cgi?ise_id="
set cURL to "&new_value=0'"
set dURL to aURL & ccu_ip & bURL & ise_ID_OnOff_Raum1 & cURL
do shell script dURL
return
end if
tell application "iTunes"
#Airplay Lautsprecher Name zur Airplay Device ID umwandeln
set apNEW to {}
set speakerComputer to (first AirPlay device whose name = "Computer")
set end of apNEW to speakerComputer
if apSpeakersNewSelected contains Raum1 then
set speakerRaum1 to (first AirPlay device whose name = Raum1)
set end of apNEW to speakerRaum1
end if
if apSpeakersNewSelected contains Raum2 then
set speakerRaum2 to (first AirPlay device whose name = Raum2)
set end of apNEW to speakerRaum2
end if
if apSpeakersNewSelected contains Raum3 then
set speakerRaum3 to (first AirPlay device whose name = Raum3)
set end of apNEW to speakerRaum3
end if
if apSpeakersNewSelected contains Raum4 then
set speakerRaum4 to (first AirPlay device whose name = Raum4)
set end of apNEW to speakerRaum4
end if
if apSpeakersNewSelected contains Raum5 then
set speakerRaum5 to (first AirPlay device whose name = Raum5)
set end of apNEW to speakerRaum5
end if
#Hier werden der Airplay Lautsprecher mit einen Fade In und die abzuschaltenden mit einen Fade Out übergeben!
set initialvolume to 50 #Wenn hier geändert wird, dann im unteren Abschnitt das setvolume anpassen!
set tickerdelay to 0.1
set current AirPlay devices to apNEW
if apSpeakersNewSelected contains Raum1 then
if sound volume of AirPlay device Raum1 is equal to initialvolume then
set sound volume of AirPlay device Raum1 to initialvolume
set ccuVOL_Raum1 to initialvolume
else if sound volume of AirPlay device Raum1 is greater than initialvolume then
set ccuVOL_Raum1 to (get sound volume of AirPlay device Raum1)
else
delay 2
repeat
set newVolume to ((sound volume of AirPlay device Raum1) + 2)
if newVolume is greater than initialvolume then
set sound volume of AirPlay device Raum1 to initialvolume
exit repeat
else
set sound volume of AirPlay device Raum1 to newVolume
delay tickerdelay
end if
end repeat
set ccuVOL_Raum1 to initialvolume
end if
end if
end tell
#Volume Status in der CCU setzen
if apSpeakersNewSelected contains Raum1 then
set aURL to "curl /dev/null 'http://"
set bURL to "/config/xmlapi/statechange.cgi?ise_id="
set cURL to "&new_value="
set dURL to "'"
set eURL to aURL & ccu_ip & bURL & ise_ID_Vol_Raum1 & cURL & ccuVOL_Raum1 & dURL
do shell script eURL
end if
tell application "iTunes"
#Raum2 aktiv? Wenn ja dann Fade Out auf 0! CCU Variable AN/AUS auf AUS und CCU Variable für Volume auf 0 setzen!
if apSpeakersSelected contains Raum2 then
repeat
if (get sound volume of AirPlay device Raum2) is equal to 0 then
exit repeat
end if
set sound volume of AirPlay device Raum2 to ((sound volume of AirPlay device Raum2) - 2)
delay 0.1
end repeat
set ccuVOL_Raum2 to 0
end if
end tell
if apSpeakersSelected contains Raum2 then
set aURL1 to "curl /dev/null 'http://"
set bURL1 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL1 to "&new_value=0'"
set dURL1 to aURL1 & ccu_ip & bURL1 & ise_ID_OnOff_Raum2 & cURL1
do shell script dURL1
set aURL2 to "curl /dev/null 'http://"
set bURL2 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL2 to "&new_value=0'"
set dURL2 to aURL2 & ccu_ip & bURL2 & ise_ID_Vol_Raum2 & cURL2
do shell script dURL2
end if
tell application "iTunes"
#Raum3 aktiv? Wenn ja dann Fade Out auf 0! und CCU Variable AN/AUS auf AUS setzen!
if apSpeakersSelected contains Raum3 then
repeat
if (get sound volume of AirPlay device Raum3) is equal to 0 then
exit repeat
end if
set sound volume of AirPlay device Raum3 to ((sound volume of AirPlay device Raum3) - 2)
delay 0.1
end repeat
set ccuVOL_Raum3 to 0
end if
end tell
if apSpeakersSelected contains Raum3 then
set aURL1 to "curl /dev/null 'http://"
set bURL1 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL1 to "&new_value=0'"
set dURL1 to aURL1 & ccu_ip & bURL1 & ise_ID_OnOff_Raum3 & cURL1
do shell script dURL1
set aURL2 to "curl /dev/null 'http://"
set bURL2 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL2 to "&new_value=0'"
set dURL2 to aURL2 & ccu_ip & bURL2 & ise_ID_Vol_Raum3 & cURL2
do shell script dURL2
end if
tell application "iTunes"
#Raum4 aktiv? Wenn ja dann Fade Out auf 0! und CCU Variable AN/AUS auf AUS setzen!
if apSpeakersSelected contains Raum4 then
repeat
if (get sound volume of AirPlay device Raum4) is equal to 0 then
exit repeat
end if
set sound volume of AirPlay device Raum4 to ((sound volume of AirPlay device Raum4) - 2)
delay 0.1
end repeat
set ccuVOL_Raum4 to 0
end if
end tell
if apSpeakersSelected contains Raum4 then
set aURL1 to "curl /dev/null 'http://"
set bURL1 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL1 to "&new_value=0'"
set dURL1 to aURL1 & ccu_ip & bURL1 & ise_ID_OnOff_Raum4 & cURL1
do shell script dURL1
set aURL2 to "curl /dev/null 'http://"
set bURL2 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL2 to "&new_value=0'"
set dURL2 to aURL2 & ccu_ip & bURL2 & ise_ID_Vol_Raum4 & cURL2
do shell script dURL2
end if
tell application "iTunes"
#Raum5 aktiv? Wenn ja dann Fade Out auf 0! und CCU Variable AN/AUS auf AUS setzen!
if apSpeakersSelected contains Raum5 then
repeat
if (get sound volume of AirPlay device Raum5) is equal to 0 then
exit repeat
end if
set sound volume of AirPlay device Raum5 to ((sound volume of AirPlay device Raum5) - 2)
delay 0.1
end repeat
set ccuVOL_Raum5 to 0
end if
end tell
if apSpeakersSelected contains Raum5 then
set aURL1 to "curl /dev/null 'http://"
set bURL1 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL1 to "&new_value=0'"
set dURL1 to aURL1 & ccu_ip & bURL1 & ise_ID_OnOff_Raum5 & cURL1
do shell script dURL1
set aURL2 to "curl /dev/null 'http://"
set bURL2 to "/config/xmlapi/statechange.cgi?ise_id="
set cURL2 to "&new_value=0'"
set dURL2 to aURL2 & ccu_ip & bURL2 & ise_ID_Vol_Raum5 & cURL2
do shell script dURL2
end if
#Airplay Lautsprecher Disconnect
tell application "iTunes"
set apNEW_Follow to {}
set speakerComputer to (first AirPlay device whose name = "Computer")
set end of apNEW_Follow to speakerComputer
if apSpeakersNewSelected contains Raum1 then
set speakerRaum1 to (first AirPlay device whose name = Raum1)
set end of apNEW_Follow to speakerRaum1
end if
set current AirPlay devices to apNEW_Follow
end tell