Dashticz - V3.8.9 beta - linear-gradient in custom.js
Posted: Wednesday 02 March 2022 12:54
Hi,
I would like to change the background with linear-gradient of one block according to the value of another block;
block 76 holds a number between 56 and 150 and is a custom sensor. Value 56 means slightly unhealthy, 150 means unhealthy. These are pm values. I would like to make block 79 that holds the value Unhealthy (it's a text device) have a background: linear-gradient. If i put this straight in custom.css it will show the gradient, but I cannot seem to find the exact code to add the css value in custom.js. I tried this with mountPoint and also with $('.block_79') but I'm clearly missing something.
Could you please sent me in the right direction?
This is my custom.js
this is my CONFIG.js
I'm running Domoticz 2022.1
If you need any more info please let me know
Thanks a lot in advance
I would like to change the background with linear-gradient of one block according to the value of another block;
block 76 holds a number between 56 and 150 and is a custom sensor. Value 56 means slightly unhealthy, 150 means unhealthy. These are pm values. I would like to make block 79 that holds the value Unhealthy (it's a text device) have a background: linear-gradient. If i put this straight in custom.css it will show the gradient, but I cannot seem to find the exact code to add the css value in custom.js. I tried this with mountPoint and also with $('.block_79') but I'm clearly missing something.
Could you please sent me in the right direction?
This is my custom.js
Code: Select all
function getStatus_76(block) { //airqualitypm25us
var device = block.device;
if (Domoticz.getAllDevices()[79].Data == 'Unhealthy') {
var ug = parseFloat(device['Data']); //pm value in ug
var bereik = 150 - 56; //max - min //precentage unhealthy
var perc = ( bereik / ug ) * 100;
var percstr = perc.toFixed(0).toString();
var slightlyunhealthy = 'rgba(255,140,0,0.8)'; //oranje
var unhealthy = 'rgba(220,20,60,0.9)'; //rood
// example background: linear-gradient(to right, rgba(255,140,0,0.8), rgba(220,20,60,0.9) 70%) !important;
//var grad = `background: linear-gradient(to right, ${slightlyunhealthy}, ${unhealthy} ${percstr}) !important;`;
//$('.block_79').css(`background: linear-gradient(to right, ${slightlyunhealthy}, ${unhealthy} ${percstr}) !important`);
$(block.mountPoint).css(`background: linear-gradient(to right, ${slightlyunhealthy}, ${unhealthy} ${percstr}) !important`);
//$('.block_79').css(`background: linear-gradient(to right, rgba(255,140,0,0.8), rgba(220,20,60,0.9) 70%) !important`);
//example $(block.mountPoint + ' .ui-slider-horizontal').css('background-color', colorStr);
} //end if
}
Code: Select all
blocks[76] = {title: 'Pm2.5', width: 4, icon: 'fas fa-smog', last_update: false}
blocks[79] = {title: 'Level Pm', width: 4, hide_data: true, last_update: false, protected: true}
If you need any more info please let me know
Thanks a lot in advance