# (HSV) coloring a lamp in script?

**URL:** https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679
**Category:** Questions & Help
**Tags:** homey-pro
**Created:** [August 1, 2023, 9:08am UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679 "2023-08-01T09:08:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Lacobo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lacobo/32/154741_2.png) [@Lacobo](https://community.homey.app/u/Lacobo)
#### Post date: [August 1, 2023, 9:08am UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/1 "2023-08-01T09:08:40Z")

</div>

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](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/3/637ced05ca5b4423127f82cc93e8dff7690ed26c.png)

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

---

<div class="post-metadata">

### Author: ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)
#### Post date: [August 1, 2023, 9:39am UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/2 "2023-08-01T09:39:23Z")

</div>

> **[Lights](https://apps.developer.homey.app/the-basics/devices/best-practices/lights#color-and-temperature-capabilities)**
>
> Best practices for lights.

---

<div class="post-metadata">

### Author: ![Lacobo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lacobo/32/154741_2.png) [@Lacobo](https://community.homey.app/u/Lacobo)
#### Post date: [August 1, 2023, 12:05pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/3 "2023-08-01T12:05:23Z")

</div>

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](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/d/ed47ed27ec05ad1f5c7b368cecdd6dede1e40fc7.png)

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.

---

<div class="post-metadata">

### Author: ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)
#### Post date: [August 1, 2023, 12:13pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/4 "2023-08-01T12:13:11Z")

</div>

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

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.

> [@](#):
>
> It shouldn’t be rocket science

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

---

<div class="post-metadata">

### Author: ![Lacobo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lacobo/32/154741_2.png) [@Lacobo](https://community.homey.app/u/Lacobo)
#### Post date: [August 1, 2023, 2:47pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/5 "2023-08-01T14:47:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)
#### Post date: [August 1, 2023, 2:52pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/6 "2023-08-01T14:52:56Z")

</div>

> [@Lacobo](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [August 1, 2023, 2:58pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/7 "2023-08-01T14:58:38Z")

</div>

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

 ![Screenshot_20230801-165554_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/9/a94fc65dd7c591b871a0bf7e0f4ab30b1f574402.jpeg)

---

<div class="post-metadata">

### Author: ![Lacobo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lacobo/32/154741_2.png) [@Lacobo](https://community.homey.app/u/Lacobo)
#### Post date: [August 1, 2023, 3:44pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/8 "2023-08-01T15:44:33Z")

</div>

Thanks Peter and Robert. All working fine now.

---

<div class="post-metadata">

### Author: ![Lacobo](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lacobo/32/154741_2.png) [@Lacobo](https://community.homey.app/u/Lacobo)
#### Post date: [August 3, 2023, 4:02pm UTC](https://community.homey.app/t/hsv-coloring-a-lamp-in-script/85679/9 "2023-08-03T16:02:50Z")

</div>

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):

```auto
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:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/c/8c8082468025551910d97d182777ae7c4d09a2da.png)
