Vorstellung: meine MusicPal-Steuerung

Hallo zusammen,

da ich schon per PN nach meinen Skripten gefragt worden bin, möchte ich dass alle was von haben :smiley:

Was ist zur Zeit implementiert ?

  • Ein-/Ausschalten
  • Favouriten auswählen
  • Lautstärke einstellen
  • Anzeige „was wird gerade gespielt“
  • inkl. Abfragen aller oben genannten Optionen und Aktualisierung in IPS (per Timer)

Installation (V2.1):

Es wird die curl.dll im ext-Ordner benötigt.

Die musicpal.php.ips mit genau diesem Namen in IPS anlegen und den Code reinkopieren.

Eine Dummy-Instanz „MusicPal“ anlegen und nach dem Screenshot füllen, das sollte jeder selbst hinbekommen. Meine Skripte waren eigentlich nicht für die Veröffentlichung bestimmt, deshalb habe ich kein automatisches Anlegen der Variablen, Timer und Ereignisse eingebaut.

Die Power-Variable auf Variablen-Profil „~Switch“ einrichten.

Für die Lautstärke-Variable ein Profil nach Screenshot einrichten.

Der Favoriten-Variable noch kein Profil einrichten, das soll später automatisch funktionieren. Zur Zeit ist eine Funktion in IPS noch ohne Funktion, mit dem nächsten Update wird das hoffentlich was.

Workaround: Nach einmaligem Ein/Ausschalten ist das Variablen Profil angelegt. Das „Aktualisieren“-Skript von Hand ausführen und Ihr erhaltet eine Liste, nach der die Assoziationen im Variablenprofil von Hand anlegen werden können.

So genug geschrieben, ist schon spät … Bei Fragen - ich beiße nicht :smiley:

Grüße

Andreas

Musicpal_2.jpg

Musicpal_3.jpg

Die musicpal.ips.php


<?

//
// The class musicpal defines an musicpal object to control a musicpal device.
// It consists of several control functions like power_down, power_up, etc.
// The constructor expects an associative array containing the keys "ip", "user", "password"
// with the appropriate values
//

function gethttp($url,$user,$pass)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
	curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$pass);
	$data=curl_exec($ch);
	curl_close($ch);
	return($data);
}
	
class musicpal
{
   var $ip;
   var $user;
   var $password;
   var $state;


   //
   // musicpal(): creates the object and saves the IP address, user name and password
   // to access the musciapl device
   //
   function musicpal($mp_cfg)
   {
      $this->ip = $mp_cfg["ip"];
      $this->user = $mp_cfg["user"];
      $this->password = $mp_cfg["password"];
		$this->get_state();
   }
   

	
   //
   // power_up(): switches the musicpal on from standby
   //
   function power_up()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/ipc_send?power_up";
      gethttp($get_url,$this->user,$this->password);
   }

   //
   // power_down(): switches the musicpal down to standby
   //
   function power_down()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/ipc_send?power_down";
      gethttp($get_url,$this->user,$this->password);
   }

   function volume($vol)
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/admin.cgi?f=volume_set&v=".$vol;
      gethttp($get_url,$this->user,$this->password);
   }

   function favorite($no)
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/admin.cgi?f=favorites&n=../favorites.html&a=p&i=".$no;
      gethttp($get_url,$this->user,$this->password);
   }

   function get_favorites()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/favorites.cgi";
      $data = gethttp($get_url,$this->user,$this->password);
      $zeilen = explode("
",$data);
      foreach($zeilen as $key => $value)
		{
		   $teile = explode(",", $value);
		   if ( $teile[0] == "#EXTINF:-1" )
			{
		      $favorites[]= $teile[1];			}
		}
		return($favorites);
	}
   
   function play_pause()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/admin.cgi?f=play_pause";
      gethttp($get_url,$this->user,$this->password);
   }

   function get_state()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/state.cgi?fav=0";
      $state_xml = gethttp($get_url,$this->user,$this->password);
      //$state_xml = substr($state_xml,strpos($state_xml,"<volume>"));
      //$this->state = simplexml_load_string("<state>".$state_xml);
      $this->state = simplexml_load_string($state_xml);
   }

   function is_on()
   {
      $this->get_state();
      if ($this->state->power_state == 1)
         return TRUE;
      else
         return FALSE;
   }

   function is_off()
   {
      $this->get_state();
      if ($this->state->power_state == 1)
         return FALSE;
      else
         return TRUE;
   }

   //
   // This functions sets the brightness of the MusicPal display depending of its status
   //
   // $brightness: value in range from 0 to 10
   //
   // $displayStatus indicates which of the following 3 status you want to change
   // "active" - brightness when MP is in active mode
   // "sleeping" - brightness when MP is in dleeping mode
   // "sleep_timer" - brightness when sleep timer of MP is active
   //
   //function brightness($brightness,$mpStatus="active")
   //{
   //   $post_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/admin.cgi?f=display_brightness_".$mpStatus."&n=../display_brightness_".$mpStatus.".html";
   //   $post_data = array('brightness'=>$brightness, 'apply' => 'Verwenden');
   //   http_post_fields($post_url,$post_data);
   //}

   function is_playing()
   {
      $this->get_state();
      if ($this->state->player_state == 1)
         return TRUE;
      else
         return FALSE;
   }

   function pause()
   {
         if ($this->is_playing())
            $this->play_pause();
   }

   function play()
   {
         if (!$this->is_playing())
            $this->play_pause();
   }

   function get_volume()
   {
      $this->get_state();
      return $this->state->volume;
   }

   function get_playing()
   {
      $this->get_state();
      return $this->state->now_playing;
   }

   function is_radio()
   {
      if ($this->state->is_internet_radio == 1)
         return TRUE;
      else
         return FALSE;

   }

   function send_message($rows)
   {
      $msg = rawurlencode(implode("§",$rows));
      $get_url = "http://".$this->ip."/admin/cgi-bin/ipc_send?show_list%20".$msg;
      echo "URL: ".$get_url."
";
      gethttp($get_url,$this->user,$this->password);
   }

   function confirm_message()
   {
      $get_url = "http://".$this->ip."/admin/cgi-bin/ipc_send?menu_collapse";
      if (!$this->is_on())
      {
         $this->power_up();
         sleep(1);
         gethttp($get_url,$this->user,$this->password);
         $this->power_down();
      } else
         gethttp($get_url,$this->user,$this->password);

   }
}

?>



das „Steuer“-Skript


<?
require("musicpal.ips.php");

//Konfig anlegen
$mp_cfg["ip"]="10.11.1.194";
$mp_cfg["user"]="admin";
$mp_cfg["password"]="admin";

//Konfig der Variablen
$PowerID=35923 /*[OG\Küche\MusicPal\Power]*/;
$VolumeID=10159 /*[OG\Küche\MusicPal\Lautstärke]*/;
$SenderID=34339 /*[OG\Küche\MusicPal\Favouriten]*/;
$nowplayID=37916 /*[OG\Küche\MusicPal\Wiedergabe aktuell]*/;
$aktEventID=50313 /*[OG\Küche\MusicPal\Status aktualisieren\]*/;

//objekt erzeugen
$mp=new musicpal($mp_cfg);

if ( $IPS_SENDER == "Variable" ) {
	switch ($IPS_VARIABLE) {
		case $PowerID:
			if ( $IPS_VALUE == true and $mp->is_off() ) {
			   $mp->power_up();
			   }
			elseif ( $IPS_VALUE == false and $mp->is_on() ) {
			   $mp->power_down();
			   }
			break;
		case $VolumeID:
		   $mp->volume($IPS_VALUE);
		   break;
		case $SenderID:
		   $mp->favorite($IPS_VALUE);
		   break;
		default:
		   echo "FEHLER: case $IPS_VARIABLE nicht im Skript berücksichtigt!";
		   break;
		}
	}

//TimerEvent für Update nach Änderung setzen und aktivieren
IPS_SetEventCyclicTimeBounds($aktEventID, time(), 0);
IPS_SetEventActive($aktEventID, true);
      
?>

das „Aktualisieren“-Skript


<?
require("musicpal.ips.php");

//Konfig für den Musicpal
$mp_cfg["ip"]="10.11.1.194";
$mp_cfg["user"]="admin";
$mp_cfg["password"]="admin";

//Konfig der Variablen
$PowerID=35923 /*[OG\Küche\MusicPal\Power]*/;
$VolumeID=10159 /*[OG\Küche\MusicPal\Lautstärke]*/;
$SenderID=34339 /*[OG\Küche\MusicPal\Favouriten]*/;
$nowplayID=37916 /*[OG\Küche\MusicPal\Wiedergabe aktuell]*/;
$aktEventID=50313 /*[OG\Küche\MusicPal\Status aktualisieren\]*/;

//Wenn 10sec Timer, dann diesen Timer wieder ausschalten
if ( $IPS_SENDER == "TimerEvent" )
{
	if ( $IPS_EVENT == $aktEventID )
	{
   	IPS_SetEventActive($aktEventID,false);
	}
}
	
//objekt erzeugen
$mp=new musicpal($mp_cfg);

//Power Variable aktualisieren
if ( $mp->is_on() and GetValue($PowerID) == false )
{
	SetValue($PowerID,true);
}
if ( $mp->is_off() and GetValue($PowerID) == true )
{
	SetValue($PowerID,false);
}
	
//wenn eingeschalten
if ( $mp->is_on() )
{
	$volume=(Integer)$mp->get_volume();
	if ( $volume != GetValue($VolumeID) )
	{
	   SetValue($VolumeID,$volume);
	}
	$nowplay=(string)$mp->get_playing();
	if ( $nowplay != GetValue($nowplayID) )
	{
		SetValue($nowplayID,$nowplay);
	}
}
//wenn ausgeschalten
else
{
	$nowplay="Gerät ist aus";
   if ( $nowplay != GetValue($nowplayID) )
	{
		SetValue($nowplayID,$nowplay);
	}
}

if ( $IPS_SENDER == "TimerEvent" )
{
	if ( $IPS_EVENT == $aktEventID AND $mp->is_off() )
	{
		//ID der Dummy-Instanz herausfinden
		$ObjektInfo=IPS_GetObject($IPS_SELF);
		$ParentID=$ObjektInfo['ParentID'];
		//Variablenprofile löschen und neu anlegen und verknüpfen
		IPS_DeleteVariableProfile("MusicPal".$ParentID);
		IPS_CreateVariableProfile("MusicPal".$ParentID,1);
		IPS_SetVariableCustomProfile($SenderID,"MusicPal".$ParentID);
		//Variablenprofil mit Assoziationen füllen
		//Funktion funktioniert im Moment V2.1 laut paresy noch nicht !!
	   $favarray=$mp->get_favorites();
	   foreach($favarray as $num=> $value)
	   {
     		IPS_SetVariableProfileAssociation("MusicPal".$ParentID,$num,$value,"");
		}
   }
}

// Da "IPS_SetVariableProfileAssociation" im Moment nicht funktioniert
// (V2.1 laut paresy) die Infos so ausgeben, dass das Variabenprofile 
// von Hand erstellt werden kann ...
if ( $IPS_SENDER == "Execute" )
{
   $favarray=$mp->get_favorites();
   foreach($favarray as $num=> $value)
   {
  		echo $num.": ".$value."
";
	}
}

?>

In der aktuellen Beta ist die Funktion korrekt dabei:
http://www.ip-symcon.de/forum/f18/ip-symcon-2-1-beta-8323/#post68830

paresy

Paresy mein Held - ein ganz dickes DANKE !!!

Funktioniert !!!

Hier das „Aktualisieren“-Skript für die Beta-Nutzer :smiley: und nicht vergessen, die „Wird gerade gespielt“-Variable auf Profile ~TextBox zu setzen !!


require("musicpal.ips.php");

//Konfig für den Musicpal
$mp_cfg["ip"]="10.11.1.194";
$mp_cfg["user"]="admin";
$mp_cfg["password"]="admin";

//Konfig der Variablen
$PowerID=35923 /*[OG\Küche\MusicPal\Power]*/;
$VolumeID=10159 /*[OG\Küche\MusicPal\Lautstärke]*/;
$SenderID=34339 /*[OG\Küche\MusicPal\Favouriten]*/;
$nowplayID=37916 /*[OG\Küche\MusicPal\Wiedergabe aktuell]*/;
$aktEventID=50313 /*[OG\Küche\MusicPal\Status aktualisieren\]*/;

//Wenn 10sec Timer, dann diesen Timer wieder ausschalten
if ( $IPS_SENDER == "TimerEvent" )
{
	if ( $IPS_EVENT == $aktEventID )
	{
   	IPS_SetEventActive($aktEventID,false);
	}
}
	
//objekt erzeugen
$mp=new musicpal($mp_cfg);

//Power Variable aktualisieren
if ( $mp->is_on() and GetValue($PowerID) == false )
{
	SetValue($PowerID,true);
}
if ( $mp->is_off() and GetValue($PowerID) == true )
{
	SetValue($PowerID,false);
}
	
//wenn eingeschalten
if ( $mp->is_on() )
{
	$volume=(Integer)$mp->get_volume();
	if ( $volume != GetValue($VolumeID) )
	{
	   SetValue($VolumeID,$volume);
	}
	$nowplay=(string)$mp->get_playing();
	if ( $nowplay != GetValue($nowplayID) )
	{
		SetValue($nowplayID,$nowplay);
	}
}
//wenn ausgeschalten
else
{
	$nowplay="Gerät ist aus";
   if ( $nowplay != GetValue($nowplayID) )
	{
		SetValue($nowplayID,$nowplay);
	}
}

if ( $IPS_SENDER == "TimerEvent" )
{
	if ( $IPS_EVENT == $aktEventID AND $mp->is_off() )
	{
		//ID der Dummy-Instanz herausfinden
		$ObjektInfo=IPS_GetObject($IPS_SELF);
		$ParentID=$ObjektInfo['ParentID'];
		//Variablenprofile löschen und neu anlegen und verknüpfen
		IPS_DeleteVariableProfile("MusicPal".$ParentID);
		IPS_CreateVariableProfile("MusicPal".$ParentID,1);
		IPS_SetVariableCustomProfile($SenderID,"MusicPal".$ParentID);
		//Variablenprofil mit Assoziationen füllen
	   $favarray=$mp->get_favorites();
	   foreach($favarray as $num=> $value)
	   {
     		IPS_SetVariableProfileAssociation("MusicPal".$ParentID,$num,$value,"");
		}
   }
}

Hallo,

bin frisch ( 1 Woche ) vom Symcon Virus befallen und probier seit ein paar Tagen fast alles aus was mir unter die Finger kommt :slight_smile:

Da ich auch einen Musicpal besitze haben ich mich voller Begeisterung an die Umsetzung gemacht. Die Variablen werden auch korrekt angezeigt, also anschauen kann ich meinen MusicPal schon.

Was mir nich nicht gelingt ist das steuern.

Muss ich ein besonderes Script an die Variablen binden ?

Ein Kleiner Tip um mich auf die Spur zu bringen wäre toll.

Gruss

Guido

Du musst das Steuerskript bei den Variablen als Aktionsskript definieren (siehe Variablenprofile - IP-Symcon :: Automatisierungssoftware unten).

Hallo Horst,
danke für die schnelle Antwort, ich hatter das auch schon probiert.
Bist Du sicher ?

das Script reagiert auf „Variable“ und die Änderung kommt doch von „WebFront“ ?
Änder ich die Variablen über den Objektbaum dann funktioniert es.


if ( $IPS_SENDER == "Variable" ) {
    switch ($IPS_VARIABLE) {
        case $PowerID:
            if ( $IPS_VALUE == true and $mp->is_off() ) {
               $mp->power_up();

Ein anderes Problem sind Favouriten die RDS Meldungen mitsenden, dann schmiert anscheinend musicpal.ips.php ab, als Workaround habe ich die betreffenden Favouriten rausgeschmissen.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xC2 0x26 0x61 0x63 in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: WDR 2 - ´Wechsel beim VfB: Marica geht, Cacau kommt (61.) in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser error : Entity ‚acute‘ not defined in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: WDR 2 - ´Wechsel beim VfB: Marica geht, Cacau kommt (61.) in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser error : Entity ‚acute‘ not defined in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: playing>WDR 2 - ´Wechsel beim VfB: Marica geht, Cacau kommt (61.)´ in C:\IP-Symcon\scripts\musicpal.ips.php on line 101 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\IP-Symcon\scripts\musicpal.ips.php on line 101
19:51:37Es ist ein Kommunikationsproblem aufgetreten! Bitte laden Sie die Seite erneut.

Guido

Manchmal ist es einfacher als man denkt


 SetValue($IPS_VARIABLE,$IPS_VALUE);
 

Vermute das wars, die Steuerung klappt jetzt.
Gesetzt werden die Werte über Ereignis:OnChange.

Guido

Hallo Guido,

da wart ihr schneller das Problem zu lösen, wie ich das Forum lesen konnte.
Das Problem oben sieht ja garnicht gut aus. Könntest Du mir sagen, bei welchen Sendern das Problem auftritt …

Grüße

Andreas

Hallo Andreas,

FFN verursacht z.B. einen Fehler

http://freecom.vtuner.com/setupapp/fc/asp/func/dynamOD.asp?ex45v=0001DB091C30&id=17392

Guido

Hallo,

habe mir jetzt auch eine musicPal bestellt und wollte schon mal die Skripte einrichten.

ich bekomme aber immer folgende Fehlermeldung:

Fatal error: Call to undefined function curl_init() in C:\Programme\IP-Symcon\scripts\musicpal.ips.php on line 12

Habe die „php_curl.dll“ im ext verzeichnis und in php.ini angemeldet.

Hat jemand eine Idee?

curl gehört nur nach ext ab 2.1 und das in der richtigen Version jenachdem was Du für eine IPS Version verwendest. Ab 2.2b 5.3.1!

Hallo,

ich verwende die IPS 2.20 und habe die php dateien von 5.3.1 verwendet.

Wie kann ich den Fehler etwas eingrenzen?

Danke für jegliche Hilfe

Viele Grüße

Markus

im Log nachsehen ob sie eingebunden wird und in einem Leerscript mit

phpinfo();

ausführen.

php_curl.rar (126 KB)

habe phpinfo ausgeführt.

kann darin aber nichts finden was auf curl hindeutet.
Habe die Datei mal angehängt.

phpinfo.txt (19.3 KB)

den IPS Dienst hast aber schon neu gestartet nach dem Du curl hinzugefügt hast. Im letzten Post hab ich dir auch die richtige Datei angehängt.

Hallo,

ich hab die Verwaltungskonsole geschlossen und erneut geöffnet.
muss ich da sonst noch was machen?

IPS Tray, Dienst beenden und wieder starten!