Issue of the topic:
Hi, I have to problem that I get errors anytime I want to run a Javascript Transformation (yes, I installed the Javascript Transformation Add-In). I have defined the Transformation in the Item but independently from the Javascript Scripts I receive errors, that happens even with very simple scripts.
I have set up zigbee2mqtt and want to use the mccgq11lm - Model as a Contact in OpenHab. All Transformations with the JSON-Addon work well. In this scenario I want to transform the contact-value in the JSON to “OPEN” or “CLOSED”, means into an contact conform format.
Here are the Configs, Files and Logs:
mqtt.cfg (rest commented):
(function(jsonString) {
var data = JSON.parse(jsonString);
var value = data.contact;
var output = "NULL";
if (value == true) {
output = "CLOSED";
} else if (value == false) {
output = "OPEN";
}
return output;
})(input)
and even this one doesn’t work
(function(jsonString) {
return "OPEN";
})(input)
this is how the mqtt msg looks like: Aug 19 18:53:23 openHABianPi npm[551]: zigbee2mqtt:info 2018-8-19 18:53:23 MQTT publish, topic: 'zigbee2mqtt/WDS', payload: '{"contact":true,"linkquality":99,"battery":"100.00","voltage":3135}'
This is the Error Message I get all the time:
2018-08-19 19:26:12.102 [ERROR] [.mqtt.internal.MqttMessageSubscriber] - Error processing MQTT message.
org.openhab.core.transform.TransformationException: An error occurred while loading script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [198:org.openhab.core.compat1x:2.3.0]
at org.openhab.binding.mqtt.internal.MqttMessageSubscriber.processMessage(MqttMessageSubscriber.java:138) [197:org.openhab.binding.mqtt:1.12.0]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.messageArrived(MqttBrokerConnection.java:574) [199:org.openhab.io.transport.mqtt:1.12.0]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:475) [199:org.openhab.io.transport.mqtt:1.12.0]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:379) [199:org.openhab.io.transport.mqtt:1.12.0]
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:183) [199:org.openhab.io.transport.mqtt:1.12.0]
at java.lang.Thread.run(Thread.java:748) [?:?]
Thank you very much in advance and kind regards,
Sandmann
2018-08-19 20:32:35.757 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '{"contact":false,"linkquality":107,"battery":"100.00","voltage":3125}' with the file 'bool_to_openclosed.map' : Target value not found in map for '{"contact":false,"linkquality":107,"battery":"100.00","voltage":3125}'
Furthermore with this approach wouldn’t I still have to specify via the JSON-Addon which value exactly is meant?
Looking at your item this is a bedroom door switch (physical switch), this is what I was asking for you to change. If the door is open, close it and vise versa. The NULL is because OH does not know anything about the door yet. With you opening/ closing the door then NULL should change to a value of ???
Change the item back to default…change CLOSED to default as before then see what the log says after you open/close the door.
Thanks for the hint! I just stopped the OH service and removed the specified folders and restarted the OH service and could see the following in the log:
2018-08-19 22:19:32.080 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-transformation-js': Error restarting bundles:
Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="0.10.0.oh230"; osgi.identity="org.eclipse.smarthome.io.transport.mdns" [id=124] STARTED [STOPPED]
which should be related to the occuring error. I will try to resolve the issue and provide and update!
I finally got the error! Hopefully this is going to help someone else to avoid this mistake.
Without thinking I have put the js-file into the /etc/openhab2/scripts folder.
The script has to remain in the /etc/openhab2/transform folder in order to work properly!
Sorry to bother you guys with such a mistake and thanks for your help!