Use value of different IDX in custom.js

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
Ierlandfan
Posts: 89
Joined: Friday 09 October 2015 17:40
Target OS: Linux
Domoticz version:
Contact:

Use value of different IDX in custom.js

Post by Ierlandfan »

How to get the variables of different idx:

How I now use it is like this but it scews up the probed block:

Code: Select all

var deviceState='';

function getBlock_123(device, idx){ 
$('.block_'+idx);
if (device['Level']= 0) deviceState='Off';
else if (device['Lev[code]el']= 10) deviceState='CV';
else if (device['Level']= 20) deviceState='WW';
else window.deviceState='Error';
console.log("DeviceState inside function", deviceState); //It works
return deviceState;
}

function getBlock_456(device, idx){
console.log("DeviceState inside another function", deviceState); //It works
}
I will make it a feature request
Ierlandfan
Posts: 89
Joined: Friday 09 October 2015 17:40
Target OS: Linux
Domoticz version:
Contact:

Re: Use value of different IDX in custom.js

Post by Ierlandfan »

Thanx to Lokonli, i changed the code. No more block screw ups.
Example:

Code: Select all

 var _idxvalues_238;

function getStatus_238(idx,value,device){
$('.block_'+idx);
_idxvalues_238 = Object(device);
console.log("Debug block 238:", _idxvalues_238);
return _idxvalues_238;
}
Now you do can things like:

Code: Select all

function getBlock_239(device,idx){
console.log("Block 239 but text value from 238 =", _idxvalues_238);
}
I will post my full Toon thermostat example tomorrow.
Lokonli
Posts: 2287
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Use value of different IDX in custom.js

Post by Lokonli »

Ierlandfan wrote: Tuesday 26 November 2019 0:18 Thanx to Lokonli, i changed the code. No more block screw ups.
Example:

Code: Select all

 var _idxvalues_238;

function getStatus_238(idx,value,device){
$('.block_'+idx);
_idxvalues_238 = Object(device);
console.log("Debug block 238:", _idxvalues_238);
return _idxvalues_238;
}
Now you do can things like:

Code: Select all

function getBlock_239(device,idx){
console.log("Block 239 but text value from 238 =", _idxvalues_238);
}
I will post my full Toon thermostat example tomorrow.
The device information is stored in a global variable 'alldevices'.
You can get specific device info via alldevices[idx]

You can access blocks[idx] as well.
Ierlandfan
Posts: 89
Joined: Friday 09 October 2015 17:40
Target OS: Linux
Domoticz version:
Contact:

Re: Use value of different IDX in custom.js

Post by Ierlandfan »

[Can you spot the logical or grammatical error in this line of codes?
Brackets, if, else without or within brackets is not my strength (Any programing language)

Code: Select all

if (levelNamesEncoded === true) names =  window.atob(_idxvalues_236['LevelNames']).split('|'); //Show the text level of idx236
        else names = _idxvalues_236['LevelNames'].split('|');

//Untill here it's working, vars are also tested and working

 /* Here is where the grammar and/or logic is not in sync, lots of code changes to try to make dashticz start so I lost track */
  
     for (a in names){
     if (a == parseFloat(device['Level'] ) // I use all the values
            if (_idxvalues_238['Level'] =='50' && _idxvalues_236['Level'] =='30'); //If this compare is true
                                html += '<div class="col-xs-6 col-data-thermostat">'; 
                                html += '<strong class="Title">' + Handmatig + _SetPoint +symbol_temp+'</strong><br />'; //Display this
                                        else if (_idxvalues_236['Level'] =='30');  //Else if this is true
                                html += '<strong class="title">' + Tijdelijk +names[a] +'</strong><br />'; //Display this
                                        else if (_idxvalues_236['Level'] =='20'); // Else if this is true
                                html += '<strong class="title">'+Scene_value+'</strong><br />'; //Display this
                                  else  console.log("Not defined"); //Catch all error, do we really need the "else" statement to close" ?
                                  // switch statement could also work here I guess
                        }
                }
                
Last edited by Ierlandfan on Tuesday 26 November 2019 18:12, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Use value of different IDX in custom.js

Post by waaren »

Ierlandfan wrote: Tuesday 26 November 2019 2:01 Brackets, if, else without or within brackets is not my strength (Any programing language)
not hindered by any js knowledge whatsoever but can you try this ?

Code: Select all

  if (levelNamesEncoded === true) names =  window.atob(_idxvalues_236['LevelNames']).split('|'); //Show the text level of idx236
        else names = _idxvalues_236['LevelNames'].split('|');

//Untill here it's working, vars are also tested and working

 /* Here is where the grammar and/or logic is not in sync, lots of code changes to try to make dashticz start so I lost track */
  
     for (a in names)
     {
        if (a == parseFloat(device['Level'] ) // I use all the values
        {
            if (_idxvalues_238['Level'] =='50' && _idxvalues_236['Level'] =='30'); //If this compare is true
            {
                html += '<div class="col-xs-6 col-data-thermostat">'; 
                html += '<strong class="Title">' + Handmatig + _SetPoint +symbol_temp+'</strong><br />'; //Display this
            }
            else if (_idxvalues_236['Level'] =='30');  //Else if this is true
            {
                html += '<strong class="title">' + Tijdelijk +names[a] +'</strong><br />'; //Display this
            }
            else if (_idxvalues_236['Level'] =='20'); // Else if this is true
            {
                html += '<strong class="title">'+Scene_value+'</strong><br />'; //Display this
            }
            else  console.log("Not defined"); //Catch all error, do we really need the "else" statement to close" ?
            {
                // switch statement could also work here I guess
            }    
        }
    }
                              
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
clinkadink
Posts: 417
Joined: Tuesday 31 December 2019 1:15
Target OS: Linux
Domoticz version: 2020.2
Location: Swindon, UK
Contact:

Re: Use value of different IDX in custom.js

Post by clinkadink »

There were quite a few errors; missing parenthesis, if statements not closed, etc. This is now valid JS, I will leave it to you to check the variable names, ids, etc. Cheers ;)

Code: Select all

if (levelNamesEncoded === true) {
    names = window.atob(_idxvalues_236['LevelNames']).split('|');
} else {
    names = _idxvalues_236['LevelNames'].split('|');
}
  
for (a in names){
    if (a == parseFloat(device['Level'] ) ) { 
        if (_idxvalues_238['Level'] == '50' && _idxvalues_236['Level'] == '30') { 
            html += '<div class="col-xs-6 col-data-thermostat">'; 
            html += '<strong class="Title">' + Handmatig + _SetPoint +symbol_temp+'</strong><br />'; 
        } else if (_idxvalues_236['Level'] == '30') { 
            html += '<strong class="title">' + Tijdelijk +names[a] +'</strong><br />';
        } else if (_idxvalues_236['Level'] == '20') { 
            html += '<strong class="title">'+Scene_value+'</strong><br />'; 
        } else {
	    console.log("Not defined");                                 
        }
   }
}
"UI is the saddle, the stirrups, & the reins. UX is the feeling you get being able to ride the horse."
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest