Page 1 of 1

Value from user variable as block title (SOLVED)

Posted: Thursday 08 December 2022 15:29
by Maikel76
Hi,

I cannot get this code to work, could anyone please help me?
I would like the value of an user variable v3 (value is 'Jan' as String) as the title of a block 161, which is a virtual switch
(code based on solution in viewtopic.php?t=34903)
v3 and block 161 are defined in CONFIG.js
custom.js:

Code: Select all

function getStatus_v3(block) {                                       //guest1
  var idx = block.idx;
  var device = block.device;
  if (parseString(device['Value']) != '') {
      Dashticz.setBlock(161, {
         title: 'test', //guest1
         icon: 'fas fa-walking'
      });
  } // end if
} // end function
What am I missing?

Re: Value from user variable as block title

Posted: Thursday 08 December 2022 18:07
by Lokonli
Did you add v3 to a column? If not, the getStatus function will not be called.

Verstuurd vanaf mijn SM-A526B met Tapatalk


Re: Value from user variable as block title

Posted: Friday 09 December 2022 3:27
by Maikel76
Lokonli wrote: Thursday 08 December 2022 18:07 Did you add v3 to a column? If not, the getStatus function will not be called.

Verstuurd vanaf mijn SM-A526B met Tapatalk
Yep I did;
CONFIG.js:

Code: Select all

blocks['g1'] = {title: 'Guest1', idx: 'v3', width: 4}
...
//Other
columns[6] = {}
columns[6]['blocks'] = [17,23,136,31,133,142,161,24,162,94,18,104,159,92,71,21,frames.player,96,32,'s1',60,12,141,'g1','g2','graphLifePO']
columns[6]['width'] = 12;
i cannot use

Code: Select all

blocks['v3'] = {title: 'Guest1', width: 4}
without specifying idx, because then the page wont load properly
also tried on column[3] on the main page because [6] is a seperate page, also the title doesnt change
just updated Dasticz to the latest version, still no title
Any other suggestions? I generate a different title for the AC block, only difference that I can see is that in this case this is a user-variable, so theoretically not a 'device'
I tried this without result too;

Code: Select all

function getStatus_v3(variable) {                                       //guest1
  var idx = variable.idx;
  var variable = variable.device;					//here device looks like a property of the domoticz unit
  if (parseString(variable['Value']) != '') {
      Dashticz.setBlock(161, {
         title: 'test', //guest1
         icon: 'fas fa-walking'
      });
  } // end if
} // end function
I'm still running domoticz 2022.1
These are my user-variables in domoticz;
Screenshot 2022-12-09 at 09-14-40 Domoticz.png
Screenshot 2022-12-09 at 09-14-40 Domoticz.png (15.49 KiB) Viewed 1333 times

Re: Value from user variable as block title

Posted: Friday 09 December 2022 6:52
by Lokonli
If you have:

Code: Select all

blocks['g1'] = ...
then in custom.js you should use:

Code: Select all

function getStatus_g1
So the last part of the function name should be the same as the key you used for the block.

Did you try that already?

Re: Value from user variable as block title

Posted: Friday 09 December 2022 7:39
by Maikel76
Lokonli wrote: Friday 09 December 2022 6:52 If you have:

Code: Select all

blocks['g1'] = ...
then in custom.js you should use:

Code: Select all

function getStatus_g1
So the last part of the function name should be the same as the key you used for the block.

Did you try that already?
tried that, strange thing is that id i change it to g1, the dashboard is not (fully) loading; background not correct, i see a switch that is hiding according to its status and tabs are not working, i have to scroll to the specific page and there the title is still not changed
Do i change that back to v3 then its working again
I do use buttons functionality for menu buttons like this;

Code: Select all

buttons.pg1bedroom = {
  width:2,
  title:'Bedroom',
  slide:5,
  key:'pg1bedr'
};
buttons.pg1roon = {
  width:12,
  title:'Click to browse music on Roon',
  slide:6,
  key:'pg1roon'
};
buttons.pg2home = {
  width:11,
  title:'This is the Climate page, click to go back to the Homescreen',
  slide:1,
  key:'pg2home'
};
buttons.pg3home = {
  width:8,
  title:'This is the Lights page, click to go back to the Homescreen',
  slide:1,
  key:'pg3home'
};
i dont use the g1 variable anywhere else (doublechecked)

Re: Value from user variable as block title

Posted: Saturday 10 December 2022 20:01
by Lokonli
parseString is not a javascript function, so you have to remove that.

Try the following:

Code: Select all

function getStatus_g1(block) {
  var device = block.device;
  if (device['Value'] != '') {
      Dashticz.setBlock(161, {
         title: 'test', //guest1
         icon: 'fas fa-walking'
      });
  } // end if
} // end function
This assumes you have defined blocks['g1'] in your CONFIG.js, and have added 'g1' to a column. 161 must also have been added to column.

Re: Value from user variable as block title

Posted: Monday 12 December 2022 7:16
by Maikel76
Excellent, thanks a lot Sander, this is the final code;

Code: Select all

function getStatus_g1(block) {                                       //guest1
  var device = block.device;
  if (device['Value'] != '') {
      Dashticz.setBlock(161, {
         title: device['Value'],
         icon: 'fas fa-walking',
         textOn: device['Value'] + ' is Home',
         textOff: device['Value'] + ' is out'
      });
  } // end if
} // end function