[SOLVED] JS Transformation Error

Raspbian GNU/Linux 9 (stretch)
Linux 4.14.79-v7+
Raspberry Pi 3 Model B Rev 1.2
openjdk version "1.8.0_152"
OpenJDK Runtime Environment (Zulu Embedded (build 1.8.0_152-b76)
OpenJDK Client VM (Zulu Embedded (build 25.152-b76, mixed mode, Evaluation)
openHAB 2.4.0-1 (Release Build)

Logged error

[WARN ] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while loading script.

Content of MQTT message

shellies/<denSensor>/sensor/temperature 74.75

Item definition

Number      den_Temperature
            "Temperature - Den [%.2f F]"
            { mqtt="<[broker:shellies/<denSensor>/sensor/temperature:state:JS(tempSensor.js)]" }


Javascript transform function to adjust the value received from the den sensor

(function(i) {
    if (i == 'NULL') { return i; }
    if (i == '-') { return 'Undefined'; }
    return (parseFloat(i) - 1.0);

I want the value that ends up being stored in the Item to be 1.0 less than the value received. For this example 73.75

The Community topics I was able to find didn’t shed light on my issue.

Does the tempSensor.js file have to have the execute permission? I didn’t want to just try this without reason and I didn’t find anything to answer this question elsewhere.

Thanks for your help.


I would try a test rule that invokes your js transform

Works in a rule.

Switch testRule "Test Switch"
rule "Test Rule"
        Item testRule changed
        logInfo("myLog", "Test Rule - {}", transform("JS","tempSensor.js", "72.45"))


Test Rule - 71.45

Reboot cleared up the issue

Won’t fix the problem, but take value UNDEF into account as well

Reboot seems to have cleared its mind.

Thanks for the recommendation. I have updated the script:

(function(i) {
    if (i == 'NULL') { return i; }
    if ((i == '-') || (i == 'UNDEF')) { return 'Undefined'; }
    return (parseFloat(i) - 1.0);