Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		Hello  
I have RGBW light and I want to change the icon color based on the RGBW feedback color. 
Icon could be like this:
     
best regards,
	  
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		Set Additional classes to  rgbw and add this to Custom JS:
 Code: $(function(){ 
  $('.rgbw').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      var value = object.value; 
      var r = ((value >> 24) & 0xFF) / 255; 
      var g = ((value >> 16) & 0xFF) / 255; 
      var b = ((value >> 8) & 0xFF) / 255; 
      var w = (value & 0xFF) / 255;       
      var a = 0.6 * (1 - (1 - w) * (1 - w)); 
      var rgb = [ 
        Math.round(((1 - a) * r + a) * 255), 
        Math.round(((1 - a) * g + a) * 255), 
        Math.round(((1 - a) * b + a) * 255) 
      ]; 
 
      $el.css('background', 'rgb(' + rgb.join(',') + ')'); 
    }); 
  }); 
});
 
Icon will be hidden, the square size will be the same as the icon size. RGBW value is converted to RGB.
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
		
		
		11.04.2022, 08:34 
(This post was last modified: 11.04.2022, 08:36 by khalil.)
		
	 
	
		Thanks Admin  
But how to deal with different RGB, RGBW  data type: objects 3byte RGB, 4byte RGBW, 6byte DALI RGBW. 
Also Could we change the background of a circle and other shapes?
	 
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		This will work both 4 and 6 byte RGBW as well as RGB (use  rgb class for it):
 Code: $(function(){ 
  $('.rgbw').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      var value = object.value; 
      var r, g, b, w; 
       
      if (typeof value == 'object') { 
        r = (value.red || 0) / 255; 
        g = (value.green || 0) / 255; 
        b = (value.blue || 0) / 255; 
        w = (value.white || 0) / 255; 
      } 
      else { 
          r = ((value >> 24) & 0xFF) / 255; 
          g = ((value >> 16) & 0xFF) / 255; 
          b = ((value >> 8) & 0xFF) / 255; 
          w = (value & 0xFF) / 255;   
      } 
           
      var a = 0.6 * (1 - (1 - w) * (1 - w)); 
      var rgb = [ 
        Math.round(((1 - a) * r + a) * 255), 
        Math.round(((1 - a) * g + a) * 255), 
        Math.round(((1 - a) * b + a) * 255) 
      ]; 
 
      $el.css('background', 'rgb(' + rgb.join(',') + ')'); 
    }); 
  }); 
 
  $('.rgb').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      $el.css('background', Scada.getRgbHex(object.value)); 
    }); 
  }); 
});
 
Shape can be changed via CSS (this will produce a circle):
 Code: .rgbw { 
  border-radius: 50%; 
}
 
A more complex shape can be done via clip-path:  https://developer.mozilla.org/en-US/docs.../clip-path
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		Hello Admin 
Is it possible to link the background color with Also the on/off Feedback? 
While the DALI RGBW status color stay on its last value even when the unit is off. 
 
BR,
	 
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		This can be implemented via a separate virtual object and event script.
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		 (11.05.2022, 10:31)admin Wrote:  This can be implemented via a separate virtual object and event script. 
Thanks Admin 
If you could share an example I will be thankful.
 
BR,
	  
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		You will need two event scripts. When lamp status (1/1/1) is off then the color status (32/1/1) is black, otherwise color control (1/1/2) value is used. 
1. DALI RGBW color object:
 Code: on = grp.getvalue('1/1/1') 
 
if on then 
  value = event.getvalue() 
else 
  value = { red = 0, green = 0, blue = 0, white = 0 } 
end 
 
grp.checkupdate('32/1/1', value)
 
2. Lamp on/off object:
 Code: on = event.getvalue() 
 
if on then 
  value = grp.getvalue('1/1/2') 
else 
  value = { red = 0, green = 0, blue = 0, white = 0 } 
end 
 
grp.checkupdate('32/1/1', value)
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		Thanks admin for the hint 
I will do it in one script using TAG. 
But I noticed that grp.checkupdate/write doesn't work on DT8 color objects, I used that in a resident script and its keep updating each cycle. 
 
BR,
	 
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		Yes, there is a bug in checkwrite for complex data types that use table values. Only date and time types are checked correctly.
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		 (11.04.2022, 08:53)admin Wrote:  This will work both 4 and 6 byte RGBW as well as RGB (use rgb class for it): 
Code: $(function(){ 
  $('.rgbw').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      var value = object.value; 
      var r, g, b, w; 
       
      if (typeof value == 'object') { 
        r = (value.red || 0) / 255; 
        g = (value.green || 0) / 255; 
        b = (value.blue || 0) / 255; 
        w = (value.white || 0) / 255; 
      } 
      else { 
          r = ((value >> 24) & 0xFF) / 255; 
          g = ((value >> 16) & 0xFF) / 255; 
          b = ((value >> 8) & 0xFF) / 255; 
          w = (value & 0xFF) / 255;   
      } 
           
      var a = 0.6 * (1 - (1 - w) * (1 - w)); 
      var rgb = [ 
        Math.round(((1 - a) * r + a) * 255), 
        Math.round(((1 - a) * g + a) * 255), 
        Math.round(((1 - a) * b + a) * 255) 
      ]; 
 
      $el.css('background', 'rgb(' + rgb.join(',') + ')'); 
    }); 
  }); 
 
  $('.rgb').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      $el.css('background', Scada.getRgbHex(object.value)); 
    }); 
  }); 
});
  
Shape can be changed via CSS (this will produce a circle): 
Code: .rgbw { 
  border-radius: 50%; 
}
  
A more complex shape can be done via clip-path: https://developer.mozilla.org/en-US/docs.../clip-path 
Hello Admin  
I try to add box-shadow to make the color glow, but how to make it right (depend on the color feedback)?
	  
	
	
Best Regards,
 
	
		
	 
 
 
	
	
	
		
	Posts: 8422 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		Use this, blur/spread radius (10px 10px) can be changed if needed: 
Code: $(function(){ 
  $('.rgbw').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      var value = object.value; 
      var r, g, b, w; 
 
      if (typeof value == 'object') { 
        r = (value.red || 0) / 255; 
        g = (value.green || 0) / 255; 
        b = (value.blue || 0) / 255; 
        w = (value.white || 0) / 255; 
      } 
      else { 
          r = ((value >> 24) & 0xFF) / 255; 
          g = ((value >> 16) & 0xFF) / 255; 
          b = ((value >> 8) & 0xFF) / 255; 
          w = (value & 0xFF) / 255;   
      } 
           
      var a = 0.6 * (1 - (1 - w) * (1 - w)); 
      var rgb = [ 
        Math.round(((1 - a) * r + a) * 255), 
        Math.round(((1 - a) * g + a) * 255), 
        Math.round(((1 - a) * b + a) * 255) 
      ]; 
 
      var bg = 'rgb(' + rgb.join(',') + ')'; 
 
      $el 
        .css('background', bg) 
        .css('box-shadow', '0 0 10px 10px ' + bg); 
    }); 
  }); 
 
  $('.rgb').each(function(index, el) { 
    var $el = $(el); 
    var addr = $el.data('status-object'); 
     
    $el.find('img').css('visibility', 'hidden'); 
     
    grp.listen(addr, function(object) { 
      var bg = Scada.getRgbHex(object.value); 
      $el 
        .css('background', bg) 
        .css('box-shadow', '0 0 10px 10px ' + bg); 
    }); 
  }); 
});
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 347 
	Threads: 79 
	Joined: Jan 2021
	
 Reputation: 
 0
	 
 
	
	
		Great  
Thank you very much
	 
	
	
Best Regards,
 
	
		
	 
 
 
	 
 |