Openhab 4 - Hue Binding - fadingLightCommand

I installed OpenHab 4.0.0.M5 after my Openhab 3 crashed (had a recent backup)

In my rules I use the fadinglightcommand which worked with version 3 of Openhab and the Hue binding.

This does not work with version 4.

Will the fadinglightcommand be added to the latest Hue binding ?

Thanks

Question is: Do you have the Hue API v1 or v2?
If Hue API v1, the action fadinglightcommand should work as it did in openHAB3
If Hue API v2, the action noe is named dynamicCommand.

See

for reference.

Please also see

Thanks Udo

I’m using API v2 and have updated my rules .

Next issue.

when I define the hueactions as below:
hueActions.dynamicCommand(“brightness”, new PercentType(0), new Long(900000))

I get the following error in VSCode and the openhab logfile.

The constructor Long(long) is deprecated

What do I use instead ?

Thanks

all good , I’ve sorted it out with a bit of help from Google

I had to change the new Long to Long.valueOf

Should the api v2 doco be updated to reflect this change ?

Regards

Hi,

Could you post the code of how you got this to work. I was initially getting issues with the PercentType but solved that from Rich Koshak post PercentType in JavaScript (ECMAScript 2021+) doesn't work.

My next issue was the Long problem you were having (ReferenceError: “Long” is not defined). I tried Long.valueOf but still get the same error. The code I am using is:

var runtime = require(‘@runtime’);
hueActions.dynamicCommand(“brightness”, new runtime.PercentType(50), new Long.valueOf(10000))

Richard

Hi

Here’s the code that I got to work:

hueActions.dynamicCommand(“brightness”, new PercentType(100), Long.valueOf(900000))

Cheers

Thank you for taking the time to post. I’m still receiving the same error “ReferenceError: “Long” is not defined”. Perhaps because i’m using “ECMAScript (ECMAScript 262 Edition 11)”. I’ll investigate further.

Oh this is good, as I’m stuck at the same LONG problem.
I recently upgraded from Openhab 3.4 to 4 and hue api v2.
Now I’m trying to get this blockly library from here https://community.openhab.org/t/how-to-convert-dsl-in-javascript-for-hue-dimmer-via-blockly/131090 to work with GraalJS.

I updated it with the new ‘dynamicCommand’ and the tip from Rich Koshak regarding the PercentType.

slots:
  code:
    - component: BlockCodeTemplate
      config:
        template: >
          var runtime = require('@runtime');
                
                {{utility:things}}.getActions('hue',{{input:THING_ID}}).dynamicCommand('brightness', new runtime.PercentType({{input:BRIGHTNESS}}), Long.valueOf({{input:FADING_TIME}}));               

It’s the same error:

2023-08-29 23:41:05.913 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '3aa6c5980f' failed: org.graalvm.polyglot.PolyglotException: ReferenceError: "Long" is not defined

Hi

I solved the ““Long” is not defined” by using ‘Number’ instead of Long:

var runtime = require(‘@runtime’);
var hueActions = actions.get(“hue”, “hue:zone:HueHub1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”);
hueActions.dynamicCommand(“brightness”, new runtime.PercentType(100), Number(20000))

Yes. I will do that. @bratmanii can you confirm that Long.valueOf() definitely does work for you? And/or @Wtfgw can you confirm that Number() does also (and/or) work? And if both do work, which do you suggest is the most preferable form for ease of user understanding?

@AndrewFG

I can confirm that Long.valueOf() works for me in my setup.

I am using this in a standard DSL rule setup.

Thanks

Hi,

Yes the Number() does work for me. Looks like Matthew is using DSL rules which is why Long.valueOf() is working for him, while I am using ECMAScript (ECMAScript 262 Edition 11), so I guess it is what you are most comfortable with.

@Wtfgw / @bratmanii thanks for your inputs; so I will add both forms to the Read Me…

This looks like it is part of a widget? Any chance yiu could share a working example?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.