Rule engine: Set color: Set color by numerical value

What DTH are you using in smartthings and what do the logs there say?

Hi @Techno_Vol ā€“ I just noticed youā€™re part of our Next Gen Samsung SmartThings beta. You might try sending the hue value in the range of 0-100. This is one of those oddities that we handle automatically for you when you use the color picker ā€“ the SmartThings COLOR_MAP range for hue is 0-100, so you have to scale the value to match that. 240 is roughly 67 (240/360 * 100 = 66.66)

1 Like

Thanks @josh, Iā€™ll give that a try.

1 Like

@Chris_C Osram Lightify RGBW A19/BR30 US version (HA) DTH rev 01/19/2018
by gkl_sf

1 Like

@josh That worked for Hue and Saturation, thanks! Can Luminance be set??

If you mean the brightness level, you can include a level attribute in the COLOR_MAP:

{"hue":67,"saturation":100,"level":100}

Thanks @josh What Iā€™m trying to get is a darker blue.

From this:
image

To this:
image

Oh my. I just finally figured out how to generate random color names (red, green, etc) and how to create a rule that loops until an end condition is met. But now I see I canā€™t use setColor with the randomly generated color name I have.

Still noodling over all this but so far not sure how to get from A to B on this.

That depends on your device handler / driver.

Some devices do accept a named color, but itā€™s not required as part of the standard which is why we send over the hue/saturation by default (since that is required as part of the COLOR_MAP standard).

If your device does accept a named color, you can flip the Advanced toggle on and customize the data type and value that gets sent across in the command.

Right. In webCoRe I send a name and it works. Iā€™ve tried sending the color name as text in SharpTools and the command executes according to the logs but it doesnā€™t actually register on the SmartThings side. Perhaps WC does some stuff in the background?

UPDATE:

I thought I was sending the color name as a string but maybe not. Each time I go to edit the action it looks like it has changed back to { }. Is this just a UI ā€˜errorā€™ or is this because my color name is actually a context variable? Is it possible that the context variable is null when the rule has not triggered yet and thus the rule engine editor is not seeing a valid string value to save?

Can you share a screenshot of what you did in webCoRE and what you are trying to do in SharpTools?

What type of device handler or driver are you using for the devices in question?

Josh, itā€™s the second image in this post:

Hereā€™s the SharpTools Rule (WIP).

Log snippit:

The DTH in use is ZigBee RGBW Bulb.

WebCoRE appears have some sort of named color translation layer as it looks like the stock Zigbee RGBW Bulb DTH does not accept named colors.

From a quick bit of digging, it appears to be part of the SmartThings Groovy Color Utilities but literally the only reference I can find to it is in WebCoRE. Iā€™ve asked my SmartThings contacts if they have and documentation on it. :thinking:

As a workaround, you could get your random color in the COLOR_MAP format that SmartThings devices expect:

{'hue': 0, 'saturation': 100}

You should be able to pass that directly to the setColor method. Alternatively, if youā€™re only varying the hue, you could randomize just the numerical hues that you need and then only inject that as part of the setColor command:

Send Command: setColor({'hue': $yourColor, 'saturation': 100})

Edit: One thing to keep in mind is SmartThings has a weird format for the hue value. In color theory, hue is 0-360, but in the SmartThings commands you have to translate that to 0-100.

1 Like

Thanks Josh. Iā€™ll have a go with that workaround a little later tonight.

Okay Josh, Iā€™m sorry but I need more help.

How exactly should I be forming the argument in the HTTP Action? As JSON, a string? And exactly in what syntax?

I have tried both above with:

{'hue': $context.response.data.result, 'saturation': 100, 'level': 50}

and

{'hue': {$context.response.data.result}, 'saturation': 100, 'level': 50}

From what I can tell Iā€™m not getting the actual result sent, rather the literal $context.response.data.result.

Can you share a screenshot of the full rule so I can better understand the context? Feel free to PM me if you prefer.

PMā€™ing you now. Thank you.

For anyone else who finds this in the future and was curious how this would workā€¦

Iā€™m using the ā€˜stringā€™ data type (Aa) and then formatted it like a JSON string:

When your cursor is in the input for editing, youā€™ll notice the expressions (for the variable reference) are wrapped in double squigglys. And when youā€™re tabbed out of the input field, they should show as parsed expression fields with the small grey pill button style shown in the above screenshot. And make sure to use straight double quotes " for the quotes.

1 Like

Yep, thanks Josh. Working like a charm for me now.

1 Like

I am now trying to get a similar rule setup to generate random colors for a Z-Wave RGBW Controller (Fibaro). I am using a custom driver.

I cannot seem to get it to work like I have for Zigbee devices I did before. When I try to send a string (formatted as a JSON formatted argument):

{"hue": {{$context.response.data.result}}, "saturation": 100, "level": 50}

I get the following in the logs:

In another test I submitted the argument as a JSON (versus string) without the random number context variable and it works.

However, in the JSON I canā€™t seem to format the context variable correctly. Is it even possible?

To summarize:

  1. Driver does not appear to accept the string (formatted as JSON) argument.
  2. I cannot get context variable in to a JSON argument.