Concat 2 values in dash?

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
magicduck
Posts: 36
Joined: Sunday 11 February 2018 13:25
Target OS: -
Domoticz version:
Location: Longwy, France
Contact:

Concat 2 values in dash?

Post by magicduck »

Hello,

I have 2 PV counters on Domoticz, and I would like to concat the power generated into 1 values.

Code: Select all

var CPV        = 3934;
var CPV2       = 6022;
// ...
blocks[CPV] = {
        title: 'PV',
        idx: CPV+'_1',
        icon: 'fas fa-solar-panel',
        unit: ' Watts',
};

blocks[CPV2] = {
        title: 'PV Mur',
        idx: CPV2+'_1',
        icon: 'fas fa-solar-panel',
        unit: ' Watts',
};
I really would like to have "one" block for the 2 blocks... is this possible ?
Regards
Lokonli
Posts: 2260
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Concat 2 values in dash?

Post by Lokonli »

For a dial it's supported. See: https://dashticz.readthedocs.io/en/mast ... ial-values

For a regular block it's not supported. Maybe I'll add it in the future.

You could create a text device in Domoticz. With a small (dzVents) script, you can combine the data of the two devices.
magicduck
Posts: 36
Joined: Sunday 11 February 2018 13:25
Target OS: -
Domoticz version:
Location: Longwy, France
Contact:

Re: Concat 2 values in dash?

Post by magicduck »

Well... This is not really what I was looking for... But... mostly (on my example) something like :

Code: Select all

blocks['PV] = {
  title: 'PV',
  icon: 'fas fa-solar-panel',
  unit: ' Watts',
  values:[
      {
      idx: CPV+'_1',
      },
      { 
      idx: CPV2+'_2',
      },
     ],
   mathvalues: 'sum',
In this case is we have in CPV_1 = 300 (Watts), and CPV2_1 = 1000 (Watts), the block will display 1300 Watts.
Lokonli
Posts: 2260
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Concat 2 values in dash?

Post by Lokonli »

If you want to show the sum of 2 values you can do it as follows:

Define a block. Something like:

Code: Select all

blocks['combined'] = {
    title: 'combined',
    idx: '3934_1',
    value: 'test',
    unit:''
}
Then in custom.js add the following:

Code: Select all

var val1=0;
var val2=0;

function updateBlock() {
 //   console.log(val1, val2);
    Dashticz.setBlock('combined', {          
        value: ''+(val1+val2)+' kWh'
    });
}

function deviceHook(device) {
   if (device.idx==3934) {
      val1=parseFloat(device.Data0);
      updateBlock();
   }
   if (device.idx==6022) {
        val2=parseFloat(device.Data0);
        updateBlock();
   }    
}
If you want to show both values (on one line), change custom.js to:

Code: Select all

var val1=0;
var val2=0;

function updateBlock() {
    Dashticz.setBlock('combined', {          //Example how to redefine another block
        value: val1+' '+val2+' kWh'
    });
}

function deviceHook(device) {
   if (device.idx==3934) {
      val1=device.Data0;
      updateBlock();
   }
   if (device.idx==6022) {
        val2=device.Data0;
        updateBlock();
   } 
}
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests