Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zorg ervoor dat links niet extern worden geopend in WebApp
- (function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")
- function lightbox_open(){
- window.scrollTo(0,0);
- $('#light').fadeIn('fast');
- $('#fade').fadeIn('fast');
- return setTimeout(function() {
- // run close function on completion of timeout0-9p
- lightbox_close();
- }, 2000);
- }
- //Create popup
- function lightbox_open(id, timeout, txt){
- window.scrollTo(0,0);
- if (typeof txt != 'undefined') {
- $('#popup_'+id).html('<div>'+txt+'</div>'); }
- $('#popup_'+id).fadeIn('fast');
- $('#fade').fadeIn('fast');
- return setTimeout(function() {
- lightbox_close(id);
- }, timeout);
- }
- //Close popup
- function lightbox_close(id){
- $('#popup_'+id).fadeOut('fast');
- $('#fade').fadeOut('fast');
- }
- function RefreshData()
- {
- clearInterval($.refreshTimer);
- var jurl=$.domoticzurl+"/json.htm?type=devices&plan="+$.roomplan+"&jsoncallback=?";
- $.getJSON(jurl,
- {
- format: "json"
- },
- function(data) {
- if (typeof data.result != 'undefined') {
- $.each(data.result, function(i,item){
- for( var ii = 0, len = $.PageArray.length; ii < len; ii++ ) {
- if( $.PageArray[ii][0] === item.idx ) { // Domoticz idx number
- var vtype= $.PageArray[ii][1]; // Domoticz type (like Temp, Humidity)
- var vlabel= $.PageArray[ii][2]; // cell number from HTML layout
- var vdesc= $.PageArray[ii][3]; // description
- var vattr= $.PageArray[ii][4]; // extra css attributes
- var valarm= $.PageArray[ii][5]; // alarm value to turn text to red
- var vdata= item[vtype]; // current value
- if (typeof vdata == 'undefined') {
- vdata="??";
- } else {
- // remove too much text
- vdata=new String(vdata).split("Lux",1)[0];
- vdata=new String(vdata).split("Watt",1)[0];
- vdata=new String(vdata).split("kWh",1)[0];
- vdata=new String(vdata).split("m3",1)[0];
- vdata=new String(vdata).split(" Level:",1)[0];
- vdata=new String(vdata).replace("Set","On");
- vdata=new String(vdata).replace("true","protected");
- //If IDX matches '' (RAM usage) or '' (CPU usage), then strip off the '%' and round the numbers
- if(item.idx == '101' || item.idx == '99'){
- vdata=new String(vdata).split("%",1)[0];
- vdata=Math.round(vdata);
- }
- }
- // replace forecast (text) with an image
- if (vdata == 'Sunny' && item.idx == '32' && vdata == 'On') {
- vdata=new String(vdata).replace( "Sunny","<img src=images/weer-iconen/zonnig.png width=104 height=104>");
- }
- if (vdata == 'Partly Cloudy' ) {
- vdata=new String(vdata).replace( "Partly Cloudy","<img src=images/weer-iconen/deels-bewolkt-zon.png width=104 height=104>");
- }
- if (vdata == 'Cloudy' ) {
- vdata=new String(vdata).replace( "Cloudy","<img src=images/weer-iconen/bewolkt.png width=104 height=104>");
- }
- if (vdata == 'Clear' ) {
- vdata=new String(vdata).replace( "Clear","<img src=images/weer-iconen/helder.png width=104 height=104>");
- }
- if (vdata == 'Rain' ) {
- vdata=new String(vdata).replace( "Rain","<img src=images/weer-iconen/regen.png width=104 height=104>");
- }
- if (vdata == 'Snow' ) {
- vdata=new String(vdata).replace( "Snow","<img src=images/weer-iconen/sneeuw.png width=104 height=104>");
- }
- if (vdata == 'Fog' ) {
- vdata=new String(vdata).replace( "Fog","<img src=images/weer-iconen/mistig-zon.png width=104 height=104>");
- }
- if (vdata == 'Hail' ) {
- vdata=new String(vdata).replace( "Hail","<img src=images/weer-iconen/hagel.png width=104 height=104>");
- }
- if (vdata == 'Thunderstom' ) {
- vdata=new String(vdata).replace( "Thunderstorm","<img src=images/weer-iconen/onweer.png width=104 height=104>");
- }
- if (vdata == 'Sleet' ) {
- vdata=new String(vdata).replace( "Sleet","<img src=images/weer-iconen/ijzel.png width=104 height=104>");
- }
- // change background color, depending on sunset and sunrise using idx 32: virtual switch named DonkerBuiten knop (vir)
- if(item.idx == '32' && vdata == 'On'){
- document.body.style.backgroundColor="#3B3B3B" // night
- }
- if(item.idx == '32' && vdata == 'Off'){
- document.body.style.backgroundColor="#BFBFBF" // day
- }
- //If IDX matches '48' (Electricity today) or '90' (Gas today), then round the numbers with 1 decimal
- if(item.idx == '48' || item.idx == '90'){
- vdata=new String(vdata).split("kWh",1)[0];
- vdata=new String(vdata).split("m3",1)[0];
- vdata=Math.round(vdata * 10) / 10;
- }
- //If IDX matches '380' (Water) covert m3 to liters
- if(item.idx == '380'){
- vdata=new String(vdata).split("m3",1)[0];
- vdata=Math.round(vdata * 1000);
- }
- // create switchable value when item is switch
- switchclick='';
- if (vdata == 'Off' ) {
- switchclick = 'onclick="SwitchToggle('+item.idx+', \'On\');"';
- }
- if (vdata == 'On' ) {
- switchclick = 'onclick="SwitchToggle('+item.idx+', \'Off\');"';
- }
- // if alarm threshold is defined, make value red
- //alarmcss='';
- //if (typeof valarm != 'undefined') {
- // if ( eval(vdata + valarm)) { // note orig: vdata > alarm
- // alarmcss=';color:red;';
- // }
- //}
- // if switch is on, make green, if off, make red. Apply background when switch is not protected.
- alarmcss='';
- if (item.Protected == true) {
- if (vdata == 'On') {
- alarmcss=';color:#1B9772;';
- vdata = 'Aan';
- }
- if (vdata == 'Off') {
- alarmcss=';color:#E24E2A;';
- vdata = 'Uit';
- }
- } else {
- if (vdata == 'On') {
- alarmcss=';color:#1B9772;';
- vdata = 'Aan';
- }
- if (vdata == 'Off') {
- alarmcss=';color:#E24E2A;';
- vdata = 'Uit';
- }
- }
- // if extra css attributes. Make switch not switchable when it is protected.
- if (typeof vattr == 'undefined') {
- if (item.Protected == true) {
- $('#'+vlabel).html('<div onClick="lightbox_open();" style='+alarmcss+'>'+vdata+'</div>');
- } else {
- $('#'+vlabel).html('<div '+switchclick+' style='+alarmcss+'>'+vdata+'</div>');
- }
- }
- if (item.Protected == true) {
- $('#'+vlabel).html( '<div onClick="lightbox_open();" style='+vattr+alarmcss+'>'+vdata+'</div>');
- } else {
- $('#'+vlabel).html( '<div '+switchclick+' style='+vattr+alarmcss+'>'+vdata+'</div>');
- }
- $('#desc_'+vlabel).html(vdesc);
- }
- }
- });
- }
- });
- // PageArray voor scenes
- var jurl=$.domoticzurl+"/json.htm?type=scenes&plan="+$.roomplan+"&jsoncallback=?";
- $.getJSON(jurl,
- {
- format: "json"
- },
- function(data) {
- if (typeof data.result != 'undefined') {
- $.each(data.result, function(i,item){
- for( var ii = 0, len = $.PageArray_Scenes.length; ii < len; ii++ ) {
- if( $.PageArray_Scenes[ii][0] === item.idx ) { // Domoticz idx number
- var vtype= $.PageArray_Scenes[ii][1]; // Domoticz type (like Temp, Humidity)
- var vlabel= $.PageArray_Scenes[ii][2]; // cell number from HTML layout
- var vdesc= $.PageArray_Scenes[ii][3]; // description
- var vattr= $.PageArray_Scenes[ii][4]; // extra css attributes
- var valarm= $.PageArray_Scenes[ii][5]; // alarm value to turn text to red
- var vdata= item[vtype]; // current value
- if (typeof vdata == 'undefined') {
- vdata="?!";
- } else {
- // remove too much text
- vdata=new String(vdata).split("Watt",1)[0];
- vdata=new String(vdata).split("kWh",1)[0];
- }
- // create switchable value when item is scene
- switchclick='';
- alarmcss='';
- if (vdata == 'Off' || vdata == 'Mixed' ) {
- switchclick = 'onclick="SceneToggle('+item.idx+', \'On\');lightbox_open(\'switch\', '+switch_on_timeout+', '+txt_switch_on+')"';
- alarmcss=';color:#E24E2A;';
- vdata = 'Uit';
- }
- if (vdata == 'On' ) {
- switchclick = 'onclick="SceneToggle('+item.idx+', \'Off\');lightbox_open(\'switch\', '+switch_off_timeout+', '+txt_switch_off+')"';
- alarmcss=';color:#1B9772;';
- vdata = 'Aan';
- }
- // if alarm threshold is defined, make value red
- if (typeof valarm != 'undefined') {
- alarmcss='';
- if ( eval(vdata + valarm)) { // note orig: vdata > alarm
- alarmcss=';color:red;';
- }
- }
- // if extra css attributes
- if (typeof vattr == 'undefined') {
- $('#'+vlabel).html('<div '+switchclick+' style='+alarmcss+'>'+vdata+'</div>');
- } else {
- $('#'+vlabel).html( '<div '+switchclick+' style='+vattr+alarmcss+'>'+vdata+'</div>');
- }
- $('#desc_'+vlabel).html(vdesc);
- }
- }
- });
- }
- });
- $.refreshTimer = setInterval(RefreshData, 8000);
- }
- // ############################################################################################################
- // #### vvvvv USER VALUES below vvvvv #######
- // ############################################################################################################
- $(document).ready(function() {
- $.roomplan=0; // define roomplan in Domoticz and create items below.
- $.domoticzurl="http://192.168.2.9:8090";
- //format: idx, value, label, description, [override css], [alarm value]
- $.PageArray = [
- //Page 1
- ['11', 'Data', 'cell1', 'CPU verbruik RPI',],
- ['27', 'Temp', 'cell2', 'Temperatuur trappengat (°C)'],
- ['26', 'Data', 'cell3', 'Trap lichtintensiteit (Lux)',],
- ['50', 'Temp', 'cell4', 'Buitentemperatuur (°C)',],
- ['29', 'Data', 'cell5', 'Tot. verbr. LED trap (kWh)',],
- ['51', 'Chill', 'cell6', 'Buiten gevoelstemp. (°C)',],
- ['50', 'ForecastStr', 'cell8b', 'Voorspelling',],
- ['51', 'Speed', 'cell7', 'Windsnelheid (m/s)'],
- ['52', 'Rain', 'cell9', 'Regen (mm/uur)'],
- ['50', 'Humidity', 'cell13', 'Luchtv. buiten (%)'],
- ['38', 'Status', 'cell14', 'Verlichting bank'],
- ['49', 'Status', 'cell15', 'Verlichting draaitafel',],
- ['39', 'Status', 'cell16', 'Licht eettafel muur',],
- ['40', 'Status', 'cell17', 'Licht eettafel keuken',],
- ['37', 'Status', 'cell18', 'Verlichting achterraam'],
- //Page 2
- ['32', 'Status', 'cell2-1', 'DonkerBuiten knop (vir)'],
- ['IDX', 'Status', 'cell2-2', 'Verlichting achterraam'],
- ['45', 'Status', 'cell2-3', 'Bewegingssensor trap'],
- ['IDX', 'Status', 'cell2-4', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-5', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-6', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-7', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-8', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-9', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-10', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-11', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-12', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-13', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-14', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-15', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-16', 'Verlichting achterraam'],
- ['IDX', 'Status', 'cell2-17', 'Verlichting achterraam'],
- ];
- $.PageArray_Scenes = [
- ['1', 'Status', 'cell10', 'Verlichting lage stand'],
- ['2', 'Status', 'cell11', 'Verlichting middelstand'],
- ['3', 'Status', 'cell12', 'Verlichting hoge stand'],
- ];
- // ###########################################################################################################
- // #### ^^^^^ USER VALUES above ^^^^^ #######
- // ############################################################################################################
- RefreshData();
- });
- function SceneToggle(idx, switchcmd)
- {
- $.ajax({
- url: "json.htm?type=command¶m=switchscene" + "&idx=" + idx + "&switchcmd=" + switchcmd + "&level=0",
- async: false,
- dataType: 'json',
- success: function(){
- console.log('SUCCES');
- },
- error: function(){
- console.log('ERROR');
- }
- });
- RefreshData();
- }
- function SwitchToggle(idx, switchcmd)
- {
- console.log('function called');
- $.ajax({
- url: "json.htm?type=command¶m=switchlight" + "&idx=" + idx + "&switchcmd=" + switchcmd + "&level=0",
- async: false,
- dataType: 'json',
- success: function(){
- console.log('SUCCES');
- },
- error: function(){
- console.log('ERROR');
- }
- });
- RefreshData();
- }
Advertisement
Add Comment
Please, Sign In to add comment