[SOLVED] Script Errors - HSBType fails

Hello all!

Recently ran across comments where it talked about placing common routines in scripts to streamline/reuse commands same as you would with a Function when programming. Part of what I read said you couldn’t pass variables back and forth and that is fine, but I’m having trouble with what I tried.

Here’s a set of lights that I control with a scene that I had set up previously as a rule triggered from a switch. And because this scene is triggered from multiple rules it made sense to place the code in a script and call the script, which forks fine, mostly…

The group of GE Lights work fine, but the Hue Lights do not.

What am I doing wrong?


//GE Lights

//Hue Lights
//master bedroom lamp
var DecimalType hue = new DecimalType(240)
var PercentType sat = new PercentType(100) // 0-100
var PercentType bright = new PercentType(10) // 0-100
var HSBType light = new HSBType(hue,sat,bright)

//dining room corner
hue = new DecimalType(100)
sat = new PercentType(100) // 0-100
bright = new PercentType(40) // 0-100
light = new HSBType(hue,sat,bright)

Anyone have an idea here?

It fails as soon as it hits this line:

var DecimalType hue = new DecimalType(240)


Cant U simply use

= 240

Thanks for the reply, but no that doesn’t work.

I’ve tried to shorten it to just the following, and it still fails on the first line:
> var HSBType light = new HSBType(240,100,10)
> sendCommand(LT_MstrLamp,light)

All three parameters are needed to set the hue, saturation and brightness of the hue bulb.

Unless there’s another way to change that?

Can you provide some log entries

When I click the switch this appears in the events log:

2016-02-19 05:31:56 - TestSW received command ON

And then this in the openhab log:

2016-02-19 05:31:56.191 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Test’: An error occured during the script execution: null

This is the rule:

rule "Test"
Item TestSW received update
if (TestSW.state == ON) {
//turn switch off
sendCommand(TestSW, OFF)

And the trimmed down script:

var HSBType light = new HSBType(240,100,10)


After much reading I’ve rewritten the script and have all but one line working…

Here’s the script with comments as to what is/isn’t working:

// following lines ok - script continues
var DecimalType hue = 360
var PercentType sat = 100
var PercentType bright = 100

// if the following line isn’t commented out - the script stops here
// no errors - but the light changes below don’t get executed
//var HSBType light = (hue,sat,bright)

// this line commented out because the light line above doesn’t work

// the following work if HSBType above is commented out

As you can see I’ve added some light changes at the bottom to see if the script continues to execute.

Is there some way to declare the HSBType in a script and use it?


Can u provide your sitemap items?

Any chance that

import org.openhab.core.library.types.HSBType

isn’t imported?

@Mpower and @watou, thanks for the follow-up but this is resolved and I’ll update it as such.

I had started a second thread here and was able to come up with a the solution.