Page 1 of 1

Trying to let virtual dimmer change background color

Posted: Thursday 12 August 2021 11:01
by Maikel76
Guys I need some help, I'm trying for a week now but cannot get this to work
I have two philips huelights as RGBWW devices *idx 42 and 43). I have a script that calculates the colortemperature according to time-of-day and set it every minute.
Then i read the colortemperature t and calculate that back to Kelvin (0-100) and put that value to set a virtual device: Dimmer (idx 44). So that dimmer will slowly 'walk' from 0 to 100
Now i already have some blocks in Dashticz change color according to values and using addClass
What i would like to do now is let the block (preferable the slider) to change to the color in Dashticz that the light has in real.
I saw this script in custom.js:

Code: Select all

function getStatus_44(block){
	var color = JSON.parse(block.device.Color);
	if (block.device.Data!='Off') {
		var yellow=255;
		var blue=255;
		if (color.ww>128) //very warm, so reduce blue
			blue = 255 - color.ww/2+64;
		if (color.cw>128) //very cold, so reduce yellow
			yellow = 255 - color.cw/2+64;
		var colorStr = `rgb(${yellow},${yellow},${blue})`;
		$(block.mountPoint + ' > div').css('background-color', colorStr)
	}
	else
		$(block.mountPoint + ' > div').css('background-color', '')
}
Unfortunately its not working
Than I reprogrammed to this (also custom.js):

Code: Select all

    //function getStatus_42(block){
         var devices = Domoticz.getAllDevices();
         var couch = devices[42];
         var kleur = parseInt(couch.Color);
         if (couch.State=='Set Color') {
                 var yellow=255;
                 var blue=255;
                 if (kleur.ww>128) //very warm, so reduce blue
                         blue = 255 - kleur.ww/2+64;
                 if (kleur.cw>128) //very cold, so reduce yellow
                         yellow = 255 - kleur.cw/2+64;
                 var colorStr = `rgb(${yellow},${yellow},${blue})`;
                 $(block.mountPoint + ' > div').css('background-color', colorStr);
         }
         //else {
         //      $(block.mountPoint + ' > div').css('background-color', '');
         //}
    //}
with and without the else staement and else with and witout curly brackets
Didnt work
Than i tried this custom.js:

Code: Select all

  3   function getStatus_44(block){
  4         var Data = Domoticz.getAllDevices()[44].Data.Level
  5         var addClass;
  6         if(parseFloat(Data) >90){
  7           addClass='bovennegentig';
  8         }
  9         else if(parseFloat(Data) >80){
 10           addClass='boventachtig';
 11         }
 12         else if(parseFloat(Data) >70){
 13           addClass='bovenzeventig';
 14         }
 15         else if(parseFloat(Data) >60){
 16           addClass='bovenzestig';
 17         }
 18         else if(parseFloat(Data) >50){
 19           addClass='bovenfijvtig';
 20         }
 21         else if(parseFloat(Data) >40){
 22           addClass='bovenveertig';
 23         }
 24         else if(parseFloat(Data) >30){
 25           addClass='bovendertig';
 26         }
 27         else if(parseFloat(Data) >20){
 28           addClass='boventwintig';
 29         }
 30         else if(parseFloat(Data) >10){
 31           addClass='boventien';
 32         }
 33         else if(parseFloat(Data) >0){
 34           addClass='bovennul';
 35         }
 36    else {
 37      addClass='none';
 38    }
 39    block.addClass = addClass;
 40    }
together with this custom.css:

Code: Select all

/*   classes for hanging color on kelvin color slider */
 37 .bovennegentig {
 38     background: #FF9F46
 39 }
 40 .boventachtig {
 41     background: #FFAC63
 42 }
 43 .bovenzeventig {
 44     background: #FFB87B
 45 }
 46 .bovenzestig {
 47     background: #FFC18D
 48 }
 49 .bovenfijvtig {
 50     background: #FFCEA6
 51 }
 52 .bovenveertig {
 53     background: #FFDABB
 54 }
 55 .bovendertig {
 56     background: #FFE4CE
 57 }
 58 .boventwintig {
 59     background: #FFEDDE
 60 }
 61 .boventien {
 62     background: #FFF6ED
 63 }
 64 .bovennul {
 65     background: #FFFEFA
 66 }
Where the hex codes are calculated as to be approximates of the color that moment
This also doesnt change anything at all. Also tried
Domoticz.getAllDevices()[44].Data
Domoticz.getAllDevices()[44].Level
Domoticz.getAllDevices()[44].level

What am i doing wrong??