Units of measurement in javascript script action

My light sensor reports illuminance in lux.

In javascript, these log statements

logger.info("currentIlluminance: {}", currentIlluminance);
logger.info(typeof currentIlluminance);

produce this output

currentIlluminance: 2969.0 lx
object

How can I compare the illuminance to a value in javascipt?
In Rules DSL I had a number defined to compare it to the current illuminance:

val Number OpenCloseThreshold = 50000|lx

Is there something similar in javascript?

rossko57 wrote a good article about QuantityTypes using the example of ‘temperatures’
Working with Number:Temperature Items in rules

2 Likes

After reading that article, I would assume that I have to write

var OpenCloseThreshold = 50000|lx;

in javascript.
But this gives the error

[internal.handler.ScriptActionHandler] - Script execution of rule with UID 'f0e7e83581' failed: ReferenceError: "lx" is not defined in <eval> at line number 5

edit: OK, the original post is about Rules DSL… I have to have a closer look of Rich’s explanation of the javascript stuff there…

edit2:
So I guess it should be

var OpenCloseThreshold = new QuantityType("50000 lx");

This doesn’t cause a compile error; have to wait if the comparison really works…

1 Like
var OpenCloseThreshold = new QuantityType("50000 lx");

Works :slight_smile: