Ankündigung

Einklappen
Keine Ankündigung bisher.

VLC-Steuerung mit KNX

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    [linKNX] VLC-Steuerung mit KNX

    Hier mal ein Beispiel zur Ansteuerung von VLC mit linknx. Im Einsatz habe ich einen ähnlichen linknx-Code der ein "Radio" in der Küche und im Bad realisiert.

    Hardware bei mir:
    • linknx läuft auf einem Wiregate
    • Ein Linux-Server mit (mehreren) Soundkarten (darauf läuft VLC)
    • Ein 1HE Verstärker im Serverschrank mit Lautsprechern in den Räumen
    • Als Bedienteil dient ein Denro One in den Räumen


    Software (ebenfalls bei mir):
    • linknx 0.0.1.30 mit LUA-Unterstützung
    • VLC 2.xx bei mir die Version von Ubuntu 12.04 LTE Server


    Die Regeln sind noch nicht bis ins Detail getestet, da dieser Code für mich als so etwas wie der Einstieg in die LUA-Programmierung diente. Aber bevor der Code in den Tiefen meines Computers verschwindet, dachte ich mir kann ich es auch hier Posten, weil es vielleicht jemand gebrauchen kann, gerade weil es wenig Beispiele für linknx gibt...

    Funktionsweise:
    Voraussetzung ist ein SSH-Zugriff mit einer Authentifizierung über Public-Keys ohne Passphrase (wenn linknx und VLC auf dem selben Rechner laufen, kann man ssh natürlich auch in den rules rausnehmen).
    Eine Anleitung zum Einrichten dieses SSH-Zugriffs unter Ubuntu finde man z.B. hier.

    Ablauf der Steuerung:
    • Wenn ein Wert der GA Play von linknx "empfangen" wird, dann wird per SSH auf dem Server eine VLC Instanz gestartet oder wenn VLC bereits läuft mittels kill beendet. Dies habe ich so gemacht, damit beim Beenden immer ein sauberer Start möglich ist, auch wenn VLC mal abstürzt (VLC ist halt kein mpd ). Die 1 für Play und 0 für Stopp werte ich in den Rules nicht so aus, da der Denro hier nicht sauber arbeitet. Das kann natürlich jeder selbst anpassen, im Bad wird bei mir VLC z.B. über den Präsenzmelder gestartet und beendet.
    • Wenn VLC gestartet wird, dann lädt die angegebenen Playlist (bei mir mit verschiedenen Internetstreams) und der erste Eintrag abgespielt.
    • Die Steuerung von VLC geschieht dann z.B. mit einer 1 bzw. 0 der GA Vor-Zurück, um ein Stream vor bzw. zurück zuspringen.
    • Da ich bisher nur Internetstreams höre, habe ich Pause weggelassen (der Denro hat auch keine Pause-Taste), sondern Beende und Starte VLC immer neu.
    • Ein Bearbeiten der Playlist habe ich nicht vorgesehen, dafür kann das Webinterface unter http://xxx.xxx.xxx.xxxx:8010 oder z.B. eine entsprechende iOS oder Android App genutzt werden.


    Hinweis:
    • Der folgende Code wird für jeden Raum einmal benötigt.
      Wird VLC für mehrere Räume benötigt, können mit der "Suchen und Ersetzen"-Funktion eines Texteditors die Begriffe "raum" und "Raum" z.B. durch den Namen des jeweiligen Raumes ersetzt (z.B. essen und Essen oder kueche und Kueche) und dann der "modifizierte" Code in die linknx.xml an den richtigen Stellen einfügt werden.
    • Weitere Befehle (z.B. Fast Forward usw.) können einfach integriert werden, die Kommandos die das RC-Interface von VLC kennt können mit help angezeigt werden. Die Befehle müssen dann als ASCII-Hexadezimal-Werte mit einem abschließenden CR bzw. "\n" (Hex: 13) eingefügt werden.


    Da ich noch nicht so lange linKNX verwende und LUA kenne ich gerade mal zwei Tage, wäre es schön, wenn ihr mir ein wenig Feedback zur Realsierung bzw. Verbesserungsvorschläge gebt.

    Folgende GAs bzw. Variablen werden in <Objects> benötigt, wobei die Portnummern 6010 und 8010 nur einmal vorkommen dürfen, die Variablen/Parameter müssen entsprechend angepasst werden:
    Code:
        <!-- #################################################################################################################################
             ## Objekte Radio Raum xyz                                                                                                         ##
             ################################################################################################################################# -->
        <object type="1.001" id="raum_verstaerker_ein-aus" gad="x/x/x" init="persist" log="true">Verstaerker</object>
        <object type="5.001" id="raum_lautstaerke" gad="x/x/23" init="persist" flags="cwtus" log="true">Lautstaerke</object>
        <object type="5.001" id="raum_lautstaerke_status" gad="x/x/x" flags="cwtus" log="true">Lautstaerke Status</object>
        <object type="1.001" id="raum_play" gad="x/x/x" flags="cwtus" log="true">Play</object>
        <object type="1.001" id="raum_pause" gad="x/x/x" flags="cwtus" log="true">Pause</object>
        <object type="1.001" id="raum_play_status" gad="x/x/x" init="persist" flags="cwtus" log="true">Play Status</object>
        <object type="1.001" id="raum_mute" gad="x/x/x" flags="cwtus" init="persist" log="true">Mute</object>
        <object type="1.001" id="raum_vor-zurueck" gad="x/x/x" flags="cwtus" log="true">Vor-Zurueck</object>
        <object type="16.001" id="raum_title" gad="x/x/x" init="persist" log="true">Title</object>
        <!-- <object type="1.001" id="raum_rewind" gad="x/x/x" log="true">Zurueckspulen</object>
             <object type="1.001" id="raum_fastforward" gad="x/x/x" log="true">Schnellervorlauf</object>-->
        <!-- ## Parameter von VLC - Variablen-->
        <object type="28.001" id="raum_vlc_ip" init="xxx.xxx.xxx.xxx">IP-Adresse von VLC</object>
        <object type="28.001" id="raum_vlc_port_rc" init="6010">Port des VLC-RC-Interface</object>
        <object type="28.001" id="raum_vlc_port_web" init="8010">Port des VLC-Web-Interface</object>
        <object type="28.001" id="raum_vlc_alsa_device" init="hw:0,0">VLC Alsa Soundkarte</object>
        <object type="5.001" id="raum_vlc_default_volume" init="50">Einschaltlautstärke</object>
        <object type="5.001" id="raum_vlc_mute_volume" init="10">Mute-Lautstärke</object>
        <object type="28.001" id="raum_vlc_playlist" init="/Pfad/zur/Playlist">Playlist zum Abspielen</object>
        <object type="16.001" id="raum_vlc_room" init="Küche">Identifizierung des VLC</object>
        <!-- VLC Extra Parameter
                 Equalizer mit folgenden moegliche Voreinstellungen:
                 flat, classical, club, dance, fullbass, fullbasstreble, fulltreble, headphones, 
                 largehall, live, party, pop, reggae, rock, ska, soft, softrock, techno -->
        <object type="28.001" id="raum_vlc_options" init="--equalizer-preset largehall">VLC extra Options</object>
        <!-- SSH Einstellungen -->
        <object type="28.001" id="raum_vlc_port_ssh" init="22">SSH-Port</object>
        <object type="28.001" id="raum_vlc_user_ssh" init="xxxNamexxx">Login Benutzername</object>
        <!-- ## Variablen Ende -->
    Folgender Eintrag wird in <services> benötigt, wobei die IP-Adresse und der Port die selben sind wie in den Variablen unter <objects> (RC-Port-Nummer):
    Code:
       <ioports>
          <ioport id="raum.vlc" type="tcp" host="xxx.xxx.xxx.xxx" port="6010" permanent="true" />
        </ioports>
    Und die Regeln in <rules>:
    Code:
        <!-- #################################################################################################################################
             ## Rules VLC Raum xyz                                                                                                           ##
             ################################################################################################################################# -->
        <rule id="VLC_Raum_ein">
    	  <condition type="and">
    	    <condition type="object" id="raum_play" trigger="true" />
    	    <condition type="object" id="raum_play_status" value="off" />
    	  </condition>
          <actionlist type="if-true">
            <action type="script">
              cmd = [[echo 'is_playing' | nc -w 1 ']]..obj("raum_vlc_ip")..[[' ']]..obj("raum_vlc_port_rc")..[[' | sed -n '/> [0|1]/p' | sed 's/>\s//;s/.$//' | tr -d '\n\r']];
              handle = io.popen(cmd);
              result = handle:read("*a");
              handle:close();
              if result ~= "1" then
                 volume = math.floor(obj("raum_vlc_default_volume") * 255 / 100);
                 cmd = [[ssh ]]..obj("raum_vlc_user_ssh")..[[@]]..obj("raum_vlc_ip")..[[ -p]]..obj("raum_vlc_port_ssh")..[[ 
                         "vlc --intf luarc --lua-config \"cli={host='*:]]..obj("raum_vlc_port_rc")..[[',
                         welcome=']]..obj("raum_vlc_room")..[[',
                         flatplaylist=1}\" --novideo --extraintf http --http-port ]]..obj("raum_vlc_port_web")..[[
                         --aout alsa --alsa-audio-device ]]..obj("raum_vlc_alsa_device")..[[ 
                         --volume ]]..volume..[[
                         --loop ]]..obj("raum_vlc_options")..[[ ]]..obj("raum_vlc_playlist")..[[ 
                         >/dev/null 2>]]..'\0381 \038"';
                 os.execute(cmd);
              end;
              set("raum_play_status", "on");
            </action>
          </actionlist>
        </rule>
    
        <rule id="VLC_Raum_aus">
          <condition type="and">
            <condition type="object" id="raum_play" trigger="true" />
            <condition type="object" id="raum_play_status" value="on" />
          </condition>
          <actionlist type="if-true">
            <action type="script">
              cmd = [[ssh ]]..obj("raum_vlc_user_ssh")..[[@]]..obj("raum_vlc_ip")..[[ -p]]..obj("raum_vlc_port_ssh")..[[ "kill \$(ps x | grep vlc | grep ']]..obj("raum_vlc_port_rc")..[[' | sed 's# ? .*##')"]];
              os.execute(cmd);
              set("raum_play_status", "off");
            </action>
          </actionlist>
        </rule>
    
        <rule id="VLC_Raum_Lautstaerke">
          <condition type="object" id="raum_lautstaerke" trigger="true" />
          <actionlist type="if-true">
    		<action type="script">
    		  cmd = "volume "..math.floor(obj("raum_lautstaerke") * 255 / 100).."\n\r";
    		  iosend("Raum.vlc", cmd);
    		  set("raum_lautstaerke_status", obj("raum_lautstaerke"));
    		</action>
          </actionlist>
        </rule>
    
        <rule id="VLC_Raum_Pause">
          <condition type="object" id="raum_pause" trigger="true" />
          <actionlist type="if-true">
            <action type="ioport-tx" ioport="Raum.vlc" hex="true" data="70617573650d0a" />
            <action type="set-value" id="raum_play_status" value="on" />
          </actionlist>
        </rule>-->
    
        <rule id="VLC_Raum_Mute">
          <condition type="object" id="raum_mute" trigger="true" />
          <actionlist type="if-true">
    		<action type="script">
    		  cmd = "volume "..math.floor(obj("raum_vlc_mute_volume") * 255 / 100).."\n\r";
    		  iosend("Raum.vlc", cmd);
    		  set("raum_lautstaerke_status", obj("raum_vlc_mute_volume"));
    		</action>
          </actionlist>
        </rule>
        
        <rule id="VLC_Raum_Vor-Zurueck">
          <condition type="object" id="raum_vor-zurueck" value="on" trigger="true" />
          <actionlist type="if-true">
            <action type="ioport-tx" ioport="Raum.vlc" hex="true" data="6e6578740d0a" />
          </actionlist>
          <actionlist type="if-false">
    		<action type="ioport-tx" ioport="Raum.vlc" hex="true" data="707265760d0a" />
          </actionlist>
        </rule>
        
        <rule id="VLC_Raum_Get_Title">
    	  <condition type="and">
     	    <condition type="object" id="raum_play_status" value="on" trigger="true" />
                <!-- Weitere Bedingungen ergaenzen z.B. ein regelmaessiges Abfragen -->
    	  </condition>
    	  <actionlist type="if-true">
            <action type="script">
              cmd = [[echo 'get_title' | nc -w 1 ']]..obj("raum_vlc_ip")..[[' ']]..obj("raum_vlc_port_rc")..[[' | sed -n '/>\s.*/p' | sed 's/>\s//;s/.$//;' | tr -d '\n\r' | cut -c1-14]];
              handle = io.popen(cmd);
              result = handle:read("*a");
              handle:close();
              set("raum_title", result);
            </action>
          </actionlist>
        </rule>

    #2
    Die Ansteuerung von VLC über KNX mit linKNX habe ich in den vergangenen Monaten etwas optimiert.
    Seit ca. einem halben Jahr habe ich für jeden Raum, den ich zentral mit Musik versorge, eine VLC-Instanz als Dienst laufen. Bisher ohne einen Absturz oder Hänger, daher stelle ich euch die neue Lösung vor.

    Ich starte VLC auf meinem kleinen Linux-Atom-Server mit diesem Aufruf:

    vlc --config room.vlcrc ~/playlist.m3u

    Als Beispiel (vlc-start.zip) habe ich für Linux eine Konfiguration (room.vlcrc) angehängt, außerdem auch ein Mini-Skript, was für jede Konfigurationsdatei eine VLC-Instanz beim Aufruf startet. Zum Testen kann VLC auch mit grafischer Oberfläche gestartet und das http-Interface muss als extra Interface ausgewählt werden.
    Für jeden Raum müssen andere Portnummern gewählt werden.

    Zusätzlich findet ihr im Anhang eine Beispiel linknx-Konfiguration für den VLC Zugriff. Die Objekte und Rules könnt ihr in eure linknx-Konfiguration kopieren, ggf. mit Suchen und Ersetzten "room" und "Room" durch den tatsächlichen Raum-Namen ersetzen (ohne Umlaute), sowie die Ports und IPs anpassen.

    Der Vorteil dieser neuen Lösung ist, dass VLC auch über die guten Android oder iOS Apps gesteuert werden kann. Das Objekt "music_play_status" verwende ich u.a., um den zugehörigen Verstärker ein- und auszuschalten, d.h. starte ich in der App die Wiedergabe, dann geht der Verstärker automatisch an.

    Perfekt ist die Lösung allerdings nicht. Ich verwende VLC hauptsächlich um Streams abzuspielen d.h. als besseres Radio. Wenn ich die Streams in einer Instanz lösche, weil ich z.B. ein Musik-Album abspiele und nicht aufpasse, dann muss ich wieder von Hand die Defaultplaylist mit den Streams laden, sonst funktioniert das Radio nicht mehr. Mit linknx habe ich es noch nicht hinbekommen eine Playlist in VLC zu laden (ich kann nur die Playlist löschen und die Streams einzeln hinzufügen).
    Angehängte Dateien

    Kommentar


      #3
      Nach längerer Pause mal wieder eine neue Version, auch diese läuft bei mir jetzt schon einige Monate ohne Probleme.

      Die ältere Version hat das Problem, dass es bei der Steuerung zu längeren Pausen bei der Ausführung von Steuerbefehlen kommen kann.

      Ich lasse für jeden Raum (bisher vier) eine eigene Instanz von linknx laufen (siehe diesen Thread), das funktioniert super.

      Hier die XML-Datei (zum Download auch im Anhang):
      Code:
      <?xml version="1.0"?>
        <!-- ####################################################################################################################################
             ##                                                                                                                                ##
             ##  Zusaetzlich benoetigte Pakete installieren:                                                                                   ##
             ##  (Install the following packages to use this script (lua 5.1):                                                                 ##
             ##  apt-get install liblua5.1-socket2                                                                                             ##
             ##                                                                                                                                ##
             #################################################################################################################################### -->
      
      <config>
        <!-- ####################################################################################################################################
             ## Objects                                                                                                                        ##
             #################################################################################################################################### -->
        <objects>
      
          <!-- #################################################################################################################################
               ## Objects VLC                                                                                                                 ##
               ################################################################################################################################# -->
          <object type="5.001" id="volume" gad="1/1/4" init="persist" flags="cwrtu">Lautstaerke</object>
          <object type="5.001" id="volume_status" flags="crwtu" gad="1/1/5">Lautstaerke Status</object>
          <object type="1.001" id="play" flags="cwus" gad="1/1/1">Play</object>
          <object type="1.001" id="pause" flags="cwus" gad="1/1/2">Pause</object>
          <object type="1.001" id="play_status" flags="crwtu" gad="1/1/3">Play Status</object>
          <object type="1.001" id="stopp" flags="cwus" gad="1/1/4"></object>
          <object type="1.001" id="mute" flags="cwus" gad="1/1/5">Mute</object>
          <object type="1.001" id="next_prev" flags="cwtus" gad="1/1/6">Vor-Zurueck</object>
          <object type="16.001" id="title" gad="1/1/7" init="persist">Title</object>
          <object type="16.001" id="artist" gad="1/1/8" init="persist">Artist</object>
          <object type="1.001" id="forward_rewind" flags="cwus" gad="1/1/9">Vor-, Zurueckspulen</object>
          <object type="5.001" id="position" gad="1/1/10">Position</object>
          <object type="5.001" id="position_status" gad="1/1/11" flags="crwtu">Position Status</object>
          <object type="1.001" id="repeat" flags="cwus" gad="1/1/12">Repeat</object>
          <object type="1.001" id="repeat_status" gad="1/1/13" flags="crwtu">Repeat Status</object>
          <object type="1.001" id="random" flags="cwus" gad="1/1/14">Random</object>
          <object type="1.001" id="random_status" flags="crwtu" gad="1/1/15">Random Status</object>
          <object type="1.001" id="load_playlist" flags="cwus" gad="1/1/16">Load Playlist</object>
         <!-- Parameter von VLC -->
          <object type="28.001" id="vlc_ip-port" init="127.0.0.1:8080">IP-Adresse und Port des VLC-Web-Interface</object>
          <object type="28.001" id="vlc_alsa_device" init="softvol1">VLC Alsa Soundkarte</object>
          <object type="5.001" id="vlc_default_volume" init="20">Einschaltlautstärke</object>
          <object type="5.001" id="vlc_mute_volume" init="10">Mute-Lautstaerke</object>
          <object type="28.001" id="vlc_playlist" init="file:~/Music.xspf">Playlist zum Abspielen</object>
          <object type="16.001" id="vlc_room" init="<Name of room">Identifizierung des VLC</object>
          <!-- VLC Extra Parameter
                   Equalizer mit folgenden mögliche Voreinstellungen:
                   flat, classical, club, dance, fullbass, fullbasstreble, fulltreble, headphones,
                   largehall, live, party, pop, reggae, rock, ska, soft, softrock, techno -->
          <object type="28.001" id="vlc_options" init="--equalizer-preset largehall">VLC extra Options</object>
        </objects>
      
        <!-- ####################################################################################################################################
             ## Rules                                                                                                                          ##
             #################################################################################################################################### -->
        <rules>
      
          <!-- #################################################################################################################################
               ## Rules controlling VLC                                                                                                       ##
               ################################################################################################################################# -->
          <rule id="Music_play">
            <condition type="and">
              <!-- manuell -->
              <condition type="object" id="play" trigger="true" />
            </condition>
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <!-- Play first Track of Playlist
                   Get First ID with this URL: http://IP-Adresse:Port/requests/playlist.xml -->
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml")
                  -- Get playing status --
                  state = string.match(result, "<state>(.-)</state>")
                  if state == "playing" then
                     result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_stop")
                  elseif state == "stopped" then
                     result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_play&id=1")
                  elseif state == "paused" then
                     result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_forceresume")
                  end
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" delay="1s" />
            </actionlist>
          </rule>
      
          <rule id="Music_stop">
            <condition type="or">
              <condition type="object" id="stopp" trigger="true" />
            </condition>
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_stop")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=volume&val="..math.floor(obj("vlc_default_volume") * 255 / 100))
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" delay="1s" />
            </actionlist>
          </rule>
      
          <rule id="Music_volume">
            <condition type="object" id="volume" trigger="true" />
            <actionlist type="if-true">
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=volume&val="..math.floor(obj("volume") * 255 / 100))
                  set("volume_status", obj("volume"))
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_pause">
            <condition type="object" id="pause" value="false" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_forcepause")
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" />
            </actionlist>
            <actionlist type="if-false">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml")
                  -- Get playing status --
                  state = string.match(result, "<state>(.-)</state>")
                  if state == "stopped" then
                     result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_play&id=1")
                  elseif state == "paused" then
                     result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_forceresume")
                  end
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" delay="1s" />
            </actionlist>
          </rule>
      
          <rule id="Music_repeat">
            <condition type="object" id="repeat" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_loop")
                  loop = string.match(result, "<loop>(.-)</loop>")
                  if loop == "true" then
                     set("repeat_status", 1)
                  else
                     set("repeat_status", 0)
                  end
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_random">
            <condition type="object" id="random" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_random")
                  random = string.match(result, "<random>(.-)</random>")
                  if random == "true" then
                     set("random_status", 1)
                  else
                     set("random_status", 0)
                  end
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_mute">
            <condition type="object" id="mute" trigger="true" />
            <actionlist type="if-true">
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=volume&val="..math.floor(obj("vlc_mute_volume") * 255 / 100))
                  set("volume_status", obj("vlc_mute_volume"))
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_next_and_prev">
            <condition type="object" id="next_prev" value="on" trigger="true" />
            <actionlist type="if-true">
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_next")
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" delay="1s" />
            </actionlist>
            <actionlist type="if-false">
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_previous")
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" delay="1s" />
            </actionlist>
          </rule>
      
          <rule id="Music_ff_and_rew">
            <condition type="object" id="forward_rewind" value="on" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=seek&val=%2B10%25")
                  -- Get position
                  position = string.match(result, "<position>(.-)</position>")
                  position = math.ceil(position * 100)
                  set("position_status", position)
                ]]>
              </action>
            </actionlist>
            <actionlist type="if-false">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=seek&val=-10%25")
                  -- Get position
                  position = string.match(result, "<position>(.-)</position>")
                  position = math.ceil(position * 100)
                  set("position_status", position)
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_position">
            <condition type="object" id="position" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=seek&val="..obj("position").."%25")
                  position = string.match(result, "<position>(.-)</position>")
                  position = math.ceil(position * 100)
                  set("position_status", position)
                ]]>
              </action>
            </actionlist>
          </rule>
      
          <rule id="Music_load_default_playlist">
            <condition type="object" id="load_playlist" trigger="true" />
            <actionlist type="if-true">
              <action type="cancel" rule-id="Music_Status" />
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  -- Clear playlist
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=pl_empty")
                  -- Load default playlist
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml?command=in_play&input="..obj("vlc_playlist"))
                ]]>
              </action>
              <action type="start-actionlist" rule-id="Music_Status" />
            </actionlist>
          </rule>
      
          <rule id="Music_status">
            <condition type="timer" trigger="true">
              <every>10</every>
            </condition>
            <actionlist>
              <action type="script">
                <![CDATA[
                  http = require("socket.http")
                  result, statuscode, content = http.request("http://"..obj("vlc_ip-port").."/requests/status.xml")
      
                  -- Get playing status --
                  state = string.match(result, "<state>(.-)</state>")
                  if state == "playing" then
                     set("play_status", 1)
                  elseif state == "stopped" then
                     set("play_status", 0)
                  elseif state == "paused" then
                     set("play_status", 0)
                  end
      
                  -- Get artist --
                  artist = string.match(result, "<info name='artist'>(.-)</info>")
                  if artist == nil then
                     set("artist", " ")
                  else
                     artist = string.sub(artist, 1 ,14)
                     set("artist", artist)
                  end
      
                  -- Get title --
                  title = string.match(result, "<info name='title'>(.-)</info>")
                  if title == nil then
                     set("title", " ")
                  else
                     title = string.sub(title, 1 ,14)
                     set("title", title)
                  end
      
                  -- Get position
                  position = string.match(result, "<position>(.-)</position>")
                  position = math.ceil(position * 100)
                  set("position_status", position)
      
                  -- Get repeat (VLC: loop) status --
                  loop = string.match(result, "<loop>(.-)</loop>")
                  if loop == "true" then
                     set("repeat_status", 1)
                  else
                     set("repeat_status", 0)
                  end
      
                  -- Get random status --
                  random = string.match(result, "<random>(.-)</random>")
                  if random == "true" then
                     set("random_status", 1)
                  else
                     set("random_status", 0)
                  end
      
                  -- Get volume
                  volume = string.match(result, "<volume>(.-)</volume>")
                  volume = math.ceil(volume * 100 / 255)
                  set("volume_status", volume)
                ]]>
              </action>
            </actionlist>
          </rule>
      
        </rules>
        <!-- ###################################################################################################################################
             ## Services                                                                                                                      ##
             ################################################################################################################################### -->
        <services>
          <xmlserver type="inet" port="1028" />
          <persistence type="file" path="/etc/linknx/persist" />
          <knxconnection url="ip:127.0.0.1" />
        </services>
        <logging output="/var/log/linknx-multiroom-vlc.log" format="%d{%Y-%m-%d %H:%M:%S,%l} %5p > %c %x - %m%n" level="INFO" maxfilesize="1000" maxfileindex="2" />
      </config>
      Angehängte Dateien

      Kommentar

      Lädt...
      X