//Kontakt: s-nolte@htp-tel.de, uweklatt@aol.com //ioBroker Forum: Lucky, uweklatt var net = require('net'); // System createState('javascript.0.Denon.System.UPDATE', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.System.Power_System', false,{type: "boolean", role: "Power System"}); createState('javascript.0.Denon.System.System_Ready', false,{type: "boolean", role: "System Ready",write:false}); createState('javascript.0.Denon.System.IP_Adresse', '192.168.178.11',{type: "string", role: "AVR IP Adresse"}); createState('javascript.0.Denon.System.Trigger_1', false,{type: "boolean", role: "Trigger 1"}); createState('javascript.0.Denon.System.Trigger_2', false,{type: "boolean", role: "Trigger 2"}); createState('javascript.0.Denon.System.Command', '',{type: "string", role: "Command to AVR"}); createState('javascript.0.Denon.System.Display_Dimmer',0,{type: "number", role: "FL Display Dimmer",states: "0:BRI;1:DIM;2:DAR;3:OFF"}); createState('javascript.0.Denon.System.Verbunden',false,{type: "boolean", role: "Verbindung hergestellt",write:false}); createState('javascript.0.Denon.System.Name',{type: "string", role: "Netzwerk-Name",write:false}); //OSD createState('javascript.0.Denon.OSD.OSD_Info_List0', 'init',{type: "string", role: "Onscreen Display Info List00",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List1', 'init',{type: "string", role: "Onscreen Display Info List01",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List2', 'init',{type: "string", role: "Onscreen Display Info List02",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List3', 'init',{type: "string", role: "Onscreen Display Info List03",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List4', 'init',{type: "string", role: "Onscreen Display Info List04",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List5', 'init',{type: "string", role: "Onscreen Display Info List05",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List6', 'init',{type: "string", role: "Onscreen Display Info List06",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List7', 'init',{type: "string", role: "Onscreen Display Info List07",write:false}); createState('javascript.0.Denon.OSD.OSD_Info_List8', 'init',{type: "string", role: "Onscreen Display Info List08",write:false}); //Controls createState('javascript.0.Denon.Control.Play', false,{type:"boolean", role: "button"}); createState('javascript.0.Denon.Control.Stop', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Control.Pause', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Control.Skip_Plus', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Control.Skip_Minus', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Control.Page_Next', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Control.Page_Previous', false,{type: "boolean", role: "button"}); //Tuner Control createState('javascript.0.Denon.Tuner_Control.Frequency_UP', false,{type:"boolean", role: "button"}); createState('javascript.0.Denon.Tuner_Control.Frequency_DOWN', false,{type:"boolean", role: "button"}); createState('javascript.0.Denon.Tuner_Control.Preset_UP', false,{type:"boolean", role: "button"}); createState('javascript.0.Denon.Tuner_Control.Preset_DOWN', false,{type:"boolean", role: "button"}); createState('javascript.0.Denon.Tuner_Control.RDS_Station_Name', 'init',{type:"string", role: "RDS Station Name",write:false}); //Zone_Main createState('javascript.0.Denon.Zone_Main.Power', false,{type: "boolean", role: "Power Status Zone Main"}); createState('javascript.0.Denon.Zone_Main.Mute', false,{type: "boolean", role: "Mute Status"}); createState('javascript.0.Denon.Zone_Main.Master_Volume', 0,{type: "number", role: "Master Volume"}); createState('javascript.0.Denon.Zone_Main.Master_Volume_UP', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_Main.Master_Volume_DOWN', false,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_Main.Master_Volume_Max', 0,{type: "number", role: "Master Volume Max",write:false}); createState('javascript.0.Denon.Zone_Main.Video_Input', 1,{type: "number", role: "Selected Video Input", states:"0:DVD;1:BD;2:TV;3:SAT/CBL;4:MPLAY;5:GAME;6:AUX1;7:AUX2;8:AUX3;9:AUX4;10:AUX5;11:AUX6;12:AUX7;13:CD"}); createState('javascript.0.Denon.Zone_Main.Video_State', false,{type: "boolean", role: "Video ON/OFF"}); createState('javascript.0.Denon.Zone_Main.Select_Input',5,{type: "number", role: "Select Input", states: "0:PHONO;1:CD;2:TUNER;3:DVD;4:BD;5:TV;6:SAT/CBL;7:MPLAY;8:GAME;9:NET;10:SPATIFY;11:LASTFM;12:IRADIO;13:SERVER;14:FAVORITES;15:AUX1;16:AUX2;17:AUX3;18:AUX4;19:AUX5;20:AUX6;21:AUX7"}); createState('javascript.0.Denon.Zone_Main.Surround_Mode', 'init',{type: "string", role: "Surround Modus",write:false}); createState('javascript.0.Denon.Zone_Main.Ratio_Mode', 'init',{type: "string", role: "Ratio Modus",write:false}); createState('javascript.0.Denon.Zone_Main.Resolution', 'init',{type: "string", role: "Video Resolution",write:false}); createState('javascript.0.Denon.Zone_Main.Sound_Parameter', 'init',{type: "string", role: "Sound_Parameter",write:false}); createState('javascript.0.Denon.Zone_Main.HDMI_Monitor',0,{type: "number", role: "HDMI Monitor Out",states: "0:MONIAUTO;1:MONI1;2:MONI2"}); //Zone 2 createState('javascript.0.Denon.Zone_2.Power_Zone2', false,{type: "boolean", role: "Power Status Zone 2"}); createState('javascript.0.Denon.Zone_2.Mute', false,{type: "boolean", role: "Mute Status Zone 2"}); createState('javascript.0.Denon.Zone_2.Volume', 0,{type: "number", role: "Zone 2 Volume"}); createState('javascript.0.Denon.Zone_2.Volume_UP', 0,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_2.Volume_DOWN', 0,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_2.Select_Input',5,{type: "number", role: "Select Input", states: "0:PHONO;1:CD;2:TUNER;3:DVD;4:BD;5:TV;6:SAT/CBL;7:MPLAY;8:GAME;9:NET;10:SPATIFY;11:LASTFM;12:IRADIO;13:SERVER;14:FAVORITES;15:AUX1;16:AUX2;17:AUX3;18:AUX4;19:AUX5;20:AUX6;21:AUX7"}); //Zone 3 createState('javascript.0.Denon.Zone_3.Power_Zone3', false,{type: "boolean", role: "Power Status Zone 3"}); createState('javascript.0.Denon.Zone_3.Mute', false,{type: "boolean", role: "Mute Status Zone 3"}); createState('javascript.0.Denon.Zone_3.Volume', 0,{type: "number", role: "Zone 3 Volume"}); createState('javascript.0.Denon.Zone_3.Volume_UP', 0,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_3.Volume_DOWN', 0,{type: "boolean", role: "button"}); createState('javascript.0.Denon.Zone_3.Select_Input',5,{type: "number", role: "Select Input", states: "0:PHONO;1:CD;2:TUNER;3:DVD;4:BD;5:TV;6:SAT/CBL;7:MPLAY;8:GAME;9:NET;10:SPATIFY;11:LASTFM;12:IRADIO;13:SERVER;14:FAVORITES;15:AUX1;16:AUX2;17:AUX3;18:AUX4;19:AUX5;20:AUX6;21:AUX7"}); // Variablen------------------------------------------------------------------------- var AVR_Command =['PW','MVMAX','MV','CV','MU','SI','ZM','SD','DC','SV','SLP','STBY','ECO','MS','VS','PS','PV','Z2','Z2MU','Z2CS','Z2CV','Z2HPF', 'Z2PS','Z2HDS','Z2SLP','Z2STBY','Z3','Z3MU','Z3CS','Z3CV','Z3HPF','Z3PS','Z3SLP','Z3STBY','TFANNAME','NSET1','NSE','TR','DIM','NSFRN']; // räume den mist später auf ;-) var t_request = 100; //beim ersten Start Funktion update aufrufen mit 100ms zwischen den Anfragen, maximal 50ms ! var client; var PW_Request =0; setState('javascript.0.Denon.System.Verbunden',val=false,akt=false); checkIP(getState('javascript.0.Denon.System.IP_Adresse').val); function checkIP(IP){ //IP Adresse prüfen if(net.isIPv4(IP)){ setTimeout(function () { client=Connect(IP); },2000); } else{console.error('ungültige IP Adresse')} } function Connect(IP){ // zu Server Verbinden var client = net.connect({host:IP, port:23}); client.setKeepAlive(true,5000); console.log('Connectig...'); client.on('error',function(error) { console.error(error); killClient(client); }); client.on('connect', function () { //Verbindung hergestellt console.log('Verbunden mit Denon AVR !'); {setState('javascript.0.Denon.System.Verbunden',val=true,akt=true)} update(t_request); }); client.on('end', function () { //die Gegenseite hat die Verbindung geschlossen {setState('javascript.0.Denon.System.Verbunden',val=false,akt=true)} console.warn('Denon AVR hat die Verbindung geschlossen !'); killClient(client); }); client.on('data', function (data) { // Empfangene Daten zeilenweise auswerten data = data.toString().replace(/[\n\r]/g, '|'); var data2 = data.split('|'); var n=0; do { if(data2[n].length < 6) // Zusmmenfügen von zerstückeltem Response { data2[n+1] = data2[n]+data2[n+1]; n++; } console.log('Antwort:'+data2[n]); response(data2[n]); }while(data2[++n]); }); return client; }//end of Function Connect function killClient(client){ {setState('javascript.0.Denon.System.Verbunden',val=false,akt=true)} client.destroy(); client.unref(); console.log('Connection closed !'); } // Funktion Nachricht Senden---------------------------------------------------------- function sendMessage(message) { if(getState('javascript.0.Denon.System.Verbunden').val===true){ client.write(message+'\r'); if (message=='PWON'||'ZMON'||'Z2ON'||'Z3ON'){PW_Request=1} console.log('Anfrage: '+ message ); } } //Daten anfordern-------------------------------------------------------------------- function update(Time){ console.log('Update Start'); var i_Pollen=0; var Request =['NSET1 ?','NSFRN ?','ZM?','MU?','PW?','SI?','SV?','MS?','MV?','Z2?','Z2MU?','Z3?','Z3MU?','NSE','VSSC ?','VSASP ?','VSMONI ?','TR?','DIM ?']; Intervall = setInterval(function () { sendMessage(Request[i_Pollen]); i_Pollen++; if (i_Pollen==Request.length){ i_Pollen=0; clearInterval(Intervall); } }, Time); return true; } //Daten anfordern-------------------------------------------------------------------- function update2(Time){ console.log('Update2 Start'); var i_Pollen=0; var Request =['NSE']; Intervall = setInterval(function () { sendMessage(Request[i_Pollen]); i_Pollen++; if (i_Pollen==Request.length){ i_Pollen=0; clearInterval(Intervall); } }, Time); return true; } function StateText_toArray (StateNames){ var StateName = StateNames.split(';'); var StateArr=[]; for(var i = 0; i < StateName.length; i++) { var ele = StateName[i].split(':'); StateArr[ele[0]] = ele[1]; } return StateArr; } // Daten empfangen------------------------------------------------------------------ function response (AVR_Response) { for (i = 0; i < AVR_Command.length; i++) { var search_index=AVR_Response.search(AVR_Command[i]); if (search_index===0){ break; } } var id,val; switch(AVR_Command[i]){ case 'MU': // to Request MU? if (AVR_Response=='MUOFF'){setState("javascript.0.Denon.Zone_Main.Mute",false,akt=true)} if (AVR_Response=='MUON'){setState("javascript.0.Denon.Zone_Main.Mute",true,akt=true)} break; case 'PW': // to Request PW? if (AVR_Response=='PWSTANDBY'){ setState('javascript.0.Denon.System.Power_System',false,akt=true); setState('javascript.0.Denon.System.System_Ready',false,akt=true); } if (AVR_Response=='PWON'){ if(PW_Request==1){ setState('javascript.0.Denon.System.Power_System',true,akt=true); PW_Request++; } else if(PW_Request==2){ setState('javascript.0.Denon.System.System_Ready',true,akt=true); PW_Request=0; } } break; case'Z2': if (AVR_Response=='Z2OFF'){setState('javascript.0.Denon.Zone_2.Power_Zone2',false,akt=true)} else if (AVR_Response=='Z2ON'){setState('javascript.0.Denon.Zone_2.Power_Zone2',true,akt=true)} else if (AVR_Response=='Z2MUON'){setState('javascript.0.Denon.Zone_2.Mute',true,akt=true)} else if (AVR_Response=='Z2MUOFF'){setState('javascript.0.Denon.Zone_2.Mute',true,akt=true)} else if (true !==isNaN(parseInt(AVR_Response.slice(2,4)))){ setState("javascript.0.Denon.Zone_2.Volume",parseFloat(AVR_Response.slice(2,4)),akt=true)} else { AVR_Response=AVR_Response.slice(2,AVR_Response.length); id='javascript.0.Denon.Zone_2.Select_Input'; val=StateText_toArray(getObject(id).common.states).indexOf(AVR_Response); if (val>=0){setState(id,val,akt=true);} } break; case'Z3': if (AVR_Response=='Z3OFF'){setState('javascript.0.Denon.Zone_3.Power_Zone3',false,akt=true)} else if (AVR_Response=='Z3ON'){setState('javascript.0.Denon.Zone_3.Power_Zone3',true,akt=true)} else if (AVR_Response=='Z3MUON'){setState('javascript.0.Denon.Zone_3.Mute',true,akt=true)} else if (AVR_Response=='Z3MUOFF'){setState('javascript.0.Denon.Zone_3.Mute',true,akt=true)} else if (true !==isNaN(parseInt(AVR_Response.slice(2,4)))){ setState("javascript.0.Denon.Zone_3.Volume",parseFloat(AVR_Response.slice(2,4)),akt=true)} else { AVR_Response=AVR_Response.slice(2,AVR_Response.length); id='javascript.0.Denon.Zone_3.Select_Input'; val=StateText_toArray(getObject(id).common.states).indexOf(AVR_Response); if (val>=0){setState(id,val,akt=true);} } break; case 'MV': // to Request MV? AVR_Response=AVR_Response.slice(2,AVR_Response.length); if (AVR_Response.length<3){AVR_Response=AVR_Response+'0'} AVR_Response=AVR_Response.slice(0, 2)+'.'+AVR_Response.slice(2, 3); setState("javascript.0.Denon.Zone_Main.Master_Volume",parseFloat(AVR_Response),akt=true); break; case 'MVMAX': AVR_Response=AVR_Response.slice(6,AVR_Response.length); AVR_Response=AVR_Response.slice(0, 2)+'.'+AVR_Response.slice(2, 3); setState("javascript.0.Denon.Zone_Main.Master_Volume_Max",parseFloat(AVR_Response),akt=true); break; case 'SV': // to Request SV? if (AVR_Response=='SVOFF'){setState("javascript.0.Denon.Zone_Main.Video_State",false,akt=true)} else if (AVR_Response=='SVON'){setState("javascript.0.Denon.Zone_Main.Video_State",true,akt=true)} else { AVR_Response=AVR_Response.slice(2,AVR_Response.length); id = 'javascript.0.Denon.Zone_Main.Video_Input'; val=StateText_toArray(getObject(id).common.states).indexOf(AVR_Response); //suche in array nach element setState(id,val,akt=true); } break; case 'SI': // to Request SI? AVR_Response=AVR_Response.slice(2,AVR_Response.length); id='javascript.0.Denon.Zone_Main.Select_Input'; val=StateText_toArray(getObject(id).common.states).indexOf(AVR_Response); setState(id,val,akt=true); break; case 'ZM': // to Request ZM? if (AVR_Response=='ZMOFF'){setState('javascript.0.Denon.Zone_Main.Power',false,akt=true)} if (AVR_Response=='ZMON'){setState('javascript.0.Denon.Zone_Main.Power',true,akt=true)} break; case 'MS': // to Request MS? AVR_Response=AVR_Response.slice(2,AVR_Response.length); setState("javascript.0.Denon.Zone_Main.Surround_Mode",AVR_Response,akt=true); break; case 'VS': // to Request VSASP ? id = "javascript.0.Denon.Zone_Main.Ratio_Mode"; if (AVR_Response=='VSASPFUL'){setState(id,'16:9',akt=true)} else if (AVR_Response=='VSASPNRM'){setState(id,'4:3',akt=true)} // to Request VSSC ? id = "javascript.0.Denon.Zone_Main.Resolution"; if (AVR_Response=='VSSC48P'){setState(id,'480p/576p',akt=true)} else if (AVR_Response=='VSSC10I'){setState(id,'1080i',akt=true)} else if (AVR_Response=='VSSC72P'){setState(id,'720p',akt=true)} else if (AVR_Response=='VSSC10P'){setState(id,'1080p',akt=true)} else if (AVR_Response=='VSSC10P24'){setState(id,'1080p:24Hz',akt=true)} else if (AVR_Response=='VSSC4K'){setState(id,'4K',akt=true)} else if (AVR_Response=='VSSC4KF'){setState(id,'4K 60/50Hz',akt=true)} else if (AVR_Response=='VSSCAUTO'){setState(id,'AUTO',akt=true)} //to Request MONI ? id='javascript.0.Denon.Zone_Main.HDMI_Monitor'; if (AVR_Response=='VSMONIAUTO'){setState(id,0,akt=true)} else if (AVR_Response=='VSMONI1'){setState(id,1,akt=true)} else if (AVR_Response=='VSMONI2'){setState(id,2,akt=true)} break; case 'PS': // to Request PSMODE: ? setState("javascript.0.Denon.Zone_Main.Sound_Parameter",AVR_Response.slice(7,AVR_Response.length),akt=true); break; case 'NSE': id='javascript.0.Denon.OSD.OSD_Info_List'+AVR_Response.slice(3, 4); if (getState(id)) { //prüfen ob State vorhanden ist setState (id,AVR_Response.slice(4,AVR_Response.length),akt=true); } break; case 'TR': if (AVR_Response=='TR1 OFF'){setState('javascript.0.Denon.System.Trigger_1',false,akt=true)} else if (AVR_Response=='TR1 ON'){setState('javascript.0.Denon.System.Trigger_1',true,akt=true)} else if (AVR_Response=='TR2 OFF'){setState('javascript.0.Denon.System.Trigger_2',false,akt=true)} else if (AVR_Response=='TR2 ON'){setState('javascript.0.Denon.System.Trigger_2',true,akt=true)} break; case 'DIM': AVR_Response=AVR_Response.slice(4,AVR_Response.length); id='javascript.0.Denon.System.Display_Dimmer'; val=StateText_toArray(getObject(id).common.states).indexOf(AVR_Response); setState(id,val,akt=true); break; case 'TFANNAME': setState('javascript.0.Denon.Tuner_Control.RDS_Station_Name',val=AVR_Response.slice(8,AVR_Response.length),akt=true); break; /* case 'NSET1': if (AVR_Response.slice(5,8)=='IPA'){ var IPstring=AVR_Response.slice(9,AVR_Response.length); if(IPstring[12]=='0'){ IPstring=IPstring.substr(0, 12) + '' + IPstring.substr(13,14); } setState('javascript.0.Denon.System.IP_Adresse',val=IPstring,akt=true); } break; */ case 'NSFRN': setState('javascript.0.Denon.System.Name',val=AVR_Response.slice(5,AVR_Response.length),akt=true); break; default: //console.log('häääää????'); } } //-------------------------------------------------------------------------------------- on('javascript.0.Denon.System.IP_Adresse', function (obj){ if(getState('javascript.0.Denon.System.Verbunden').val===true){ killClient(client); checkIP(obj.state.val); } else{checkIP(obj.state.val)} }); on({id:'javascript.0.Denon.System.UPDATE',val:true}, function (obj){ update(t_request); }); on({id:"javascript.0.Denon.System.Command",change:"any"}, function (obj){sendMessage(obj.state.val+'')}); on("javascript.0.Denon.System.Power_System", function (obj){ if (!obj.state.ack) { if (obj.state.val){ sendMessage('PWON'); } else{sendMessage('PWOFF')} } }); on('javascript.0.Denon.Zone_Main.Power', function (obj){ if (!obj.state.ack) { if (obj.state.val){ sendMessage('ZMON'); } else{sendMessage('ZMOFF')} } }); on('javascript.0.Denon.Zone_2.Power_Zone2', function (obj){ if (!obj.state.ack) { if (obj.state.val){sendMessage('Z2ON')} else{sendMessage('Z2OFF')} } }); on('javascript.0.Denon.Zone_3.Power_Zone3', function (obj){ if (!obj.state.ack) { if (obj.state.val){sendMessage('Z3ON')} else{sendMessage('Z3OFF')} } }); on("javascript.0.Denon.Zone_Main.Mute", function (obj){ if (!obj.state.ack) { if (obj.state.val){sendMessage('MUON')} else{sendMessage('MUOFF')} } }); on("javascript.0.Denon.Zone_2.Mute", function (obj){ if (!obj.state.ack) { if (obj.state.val){sendMessage('Z2MUON')} else{sendMessage('Z2MUOFF')} } }); on("javascript.0.Denon.Zone_3.Mute", function (obj){ if (!obj.state.ack) { if (obj.state.val){sendMessage('Z3MUON')} else{sendMessage('Z3MUOFF')} } }); on("javascript.0.Denon.Zone_Main.Master_Volume", function (obj){ if (!obj.state.ack) { sendMessage('MV'+obj.state.val+''); } }); on({id:"javascript.0.Denon.Zone_Main.Master_Volume_UP",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('MVUP'+''); } }); on({id:"javascript.0.Denon.Zone_Main.Master_Volume_DOWN",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('MVDOWN'+''); } }); on("javascript.0.Denon.Zone_2.Volume", function (obj){ if (!obj.state.ack) { sendMessage('Z2'+obj.state.val+''); } }); on({id:"javascript.0.Denon.Zone_2.Volume_UP",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('Z2UP'+''); } }); on({id:"javascript.0.Denon.Zone_2.Volume_DOWN",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('Z2DOWN'+''); } }); on("javascript.0.Denon.Zone_3.Volume", function (obj){ if (!obj.state.ack) { sendMessage('Z3'+obj.state.val+''); } }); on({id:"javascript.0.Denon.Zone_3.Volume_UP",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('Z3UP'+''); } }); on({id:"javascript.0.Denon.Zone_3.Volume_DOWN",val:true}, function (obj){ if (!obj.state.ack) { sendMessage('Z3DOWN'+''); } }); on({id:"javascript.0.Denon.Control.Play",vla:true}, function (obj){ if (obj.state.val===true){sendMessage('NS9A')} }); on({id:"javascript.0.Denon.Control.Stop",val:true}, function (obj){ sendMessage('NS9C') }); on({id:"javascript.0.Denon.Control.Pause",val:true}, function (obj){ //if (obj.state.val===true){sendMessage('NS9B')} sendMessage('NS9B'); }); on({id:"javascript.0.Denon.Control.Skip_Plus",val:true}, function (obj){ sendMessage('NS9D') }); on({id:"javascript.0.Denon.Control.Skip_Minus",val:true}, function (obj){ sendMessage('NS9E') }); on({id:"javascript.0.Denon.Control.Page_Next",val:true}, function (obj){ sendMessage('NS9X') }); on({id:"javascript.0.Denon.Control.Page_Previous",val:true}, function (obj){ sendMessage('NS9Y') }); on('javascript.0.Denon.Zone_Main.Select_Input', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('SI'+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on('javascript.0.Denon.Zone_2.Select_Input', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('Z2'+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on('javascript.0.Denon.Zone_3.Select_Input', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('Z3'+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on('javascript.0.Denon.Zone_Main.Video_Input', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('SV'+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on('javascript.0.Denon.Zone_Main.Video_State', function (obj){ if (!obj.state.ack) { if (obj.state.val===true){sendMessage('SVON')} else{sendMessage('SVOFF')} } }); on('javascript.0.Denon.Zone_Main.HDMI_Monitor', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('VS'+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on("javascript.0.Denon.System.Trigger_1", function (obj){ if (!obj.state.ack) { if (obj.state.val===true){sendMessage('TR1 ON')} else{sendMessage('TR1 OFF')} } }); on("javascript.0.Denon.System.Trigger_2", function (obj){ if (!obj.state.ack) { if (obj.state.val===true){sendMessage('TR2 ON')} else{sendMessage('TR2 OFF')} } }); on('javascript.0.Denon.System.Display_Dimmer', function (obj){ if (!obj.state.ack) { if(obj.state.val>=0){ sendMessage('DIM '+ StateText_toArray(obj.common.states)[obj.state.val].toUpperCase() ); } } }); on({id:'javascript.0.Denon.Tuner_Control.Frequency_UP',val:true}, function (obj){sendMessage('TFANUP')}); on({id:'javascript.0.Denon.Tuner_Control.Frequency_DOWN',val:true}, function (obj){sendMessage('TFANDOWN')}); on({id:'javascript.0.Denon.Tuner_Control.Preset_UP',val:true}, function (obj){sendMessage('TPANUP')}); on({id:'javascript.0.Denon.Tuner_Control.Preset_DOWN',val:true}, function (obj){sendMessage('TPANDOWN')}); //--------------------------------------------------------------------------------------- // close connection if script stopped------------------------------------------------- onStop(function () { if(getState('javascript.0.Denon.System.Verbunden').val===true){killClient(client)}; }, 2000 /*ms*/); schedule("*/15 * * * * *", function() { update2(1000);});