(HSV) coloring a lamp in script?

Using text/script for +30 years I’m more of a text person. To convert at least a part of my flows (Just started a month ago with Homey Pro’23 ) to text I’ve started creating my first scripts.

What I can’t figure out is how to set the color of a light. A similar topic pointed to the Color Tools, but I have less than a clue how to use these. My guess was that it would use Hex codes, but I see in the MQTT explorer that my lamp likes hsv format. Can anyone answer my simple question how the formatting works for color and thus how to fix line 10?

image

I have two lights in the example, because I kept running to the bathroom to check the light :slight_smile: The Mobilamp is clamping next to me on the desk.

Thanks Robert for your quick hint, but that article doesn’t seem to answer my question, and it’s not for an App. What do I need to fill in?
The lamp in question can handle: light-mode, color, dim and onoff. The last two are working quite nice.

image

It shouldn’t be rocket science, but I get the feeling it is. I work at a helpdesk and have become ‘master of searching’, but no luck in this adventure.

If you work at a helpdesk you should know you should provide all relevant information :stuck_out_tongue:

What does this MQTT data have to do with setting a lamp color from a script?

There is no such thing as a color capability, so if your lamp has this capability, it’s a custom capability that is “made up” by the developer of the app that handles the lamp, and without more information (which app? where is it’s source? how is the color capability defined?) nobody will be able to help you.

Well, you chose to take the hard road by wanting to use scripts instead of normal flow cards.

Thank you Master for your valuable lesson :clap:
Its an Innr lamp, running on a Hue Bridge.
Edit: Found it! (‘light_hue’, 0.8) gives Purple for instance.

Which is why I linked to the “Best practices” page, which describes the capabilities used to set colors.

Another way of ‘discovering’ things is to lookup a color light here https://tools.developer.homey.app/tools/devices , and view / play with the capabilities
Example:

Thanks Peter and Robert. All working fine now.

1 Like

My first complete bedroom-lights Homeyscript, with two KaKu duo-switches, a 2-lamp armature and a bed-light, having much fun (edit: Had forgotten to ‘break’ the switch-cases, more of a VB programmer, there you won’t need them):

let Bedlamp = '<unique Homey Bedlamp-hex code>';
let SlaapA = '<unique Homey SlaapA-hex code>';
let SlaapB = '<unique Homey SlaapB-hex code>';
var Lampx = await Homey.devices.getDevice({id:SlaapA});
var Lampy = await Homey.devices.getDevice({id:SlaapB});
var Lampz = await Homey.devices.getDevice({id:Bedlamp});

if (args[0].startsWith('B')) {
  if (Lampz.capabilitiesObj.onoff.value) {
    Cappy(1,'onoff', false); }
  else {
    switch (args[0]) {
    case 'BedOp':
      Cappy(1,'light_mode','temperature');
      Cappy(1,'light_temperature',0.60);
      Cappy(1,'light_saturation',0.56);
      Cappy(1,'light_hue', 0.10);
      Cappy(1,'dim', 0.80); break;
    case 'BedNeer':
      Cappy(1,'light_mode','color');
      Cappy(1,'light_temperature',1.00);
      Cappy(1,'light_saturation',1.00);
      Cappy(1,'light_hue',0.10);
      Cappy(1,'dim',0.30); break;
    default:
      Cappy(1,'onoff', false); } } }

if (args[0].startsWith('S')) {
  if (Lampx.capabilitiesObj.onoff.value) {  
    Cappy(2,'onoff', false); }
  else {
    switch (args[0]) {
    case 'SLOp':
      Cappy(2,'light_mode','temperature');
      Cappy(2,'light_temperature',0.60);
      Cappy(2,'light_saturation',0.56);
      Cappy(2,'light_hue', 0.10);
      Cappy(2,'dim', 0.80); break;
    case 'SLNeer':
      Cappy(2,'light_mode','color');
      Cappy(2,'light_temperature',1.00);
      Cappy(2,'light_saturation',1.00);
      Cappy(2,'light_hue',0.10);
      Cappy(2,'dim',0.30); break;
    default:
      Cappy(2,'onoff', false); } } }

function Cappy(Type, Cmnd, Val) {
  if (Type === 1){
    Lampz.setCapabilityValue(Cmnd, Val); }
  if (Type === 2){ 
    Lampx.setCapabilityValue(Cmnd, Val);
    Lampy.setCapabilityValue(Cmnd, Val); } }

The flow now looks like this: