How to use JS Transformation in Jython Scripting

I work with Openhab 3.4.3 and Jython scripting.

My goal is to assign a previously defined colour to a colour item in the script.
I have the colour in HEX format (FFFFFF).

The direct assignment via (core.utils) sendCommandCheckFirst(itemRegistry.getItem(“MyColorItem”), “FFFFFF”) does not work.
→ ‘FFFFFF’ is not an accepted command type for ‘MyColorItem’.

Even if I change the format to #FFFFFF I get the same error.

I found out that I have to set the colour as HSB value.

sendCommandCheckFirst(itemRegistry.getItem(“MyColorItem”), “18.529411764705856, 80.95238095238095, 98.82352941176471”)
→ Works.

I have already written a hex2hsb.js transformation. However, I do not know how to integrate it correctly.

myrule.log.info(Transformation.transform(“JS”, “transform/hex2rgb.js”, “#FFFFFF”)) gives me #FFFFFF as result. Of course, I have installed the JS transformation as a plug-in.

Can anyone tell me what I am doing wrong?

Translated with DeepL Translate: The world's most accurate translator (free version)

You don’t need a transform for this. The HSBType class has a fromRGB(int, int, int) method so if you split the hex and convert them to numbers you could use that.

Assuming you are using the helper library, see the Helper Library docs. Actions — openHAB Helper Libraries documentation

Notice the call in the example is preceded by an import. You can’t use it without importing it.

from core.actions import Transformation
Transformation.transform("JSONPATH", "$.test", test)