Hi,
Strange problem. If I clear the cache of openHab and start openHab I get the error below. The only way I have fond to fix it is to just save the rule and then it works again.
I have no idea why.
If I just restart openHab it works fine.
I am running openHab version 5.0 (just upgraded today to 5.0.1) the issue is still there.
2025-08-20 09:00:00.256 [ERROR] [omation.script.javascript.4c2d784197] - Failed to execute script: TypeError: Cannot read property "publishMQTT" from null
at <js>.:program(<eval>:32)
at org.graalvm.polyglot.Context.eval(Context.java:416)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:490)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262)
... 22 more
2025-08-20 09:00:00.258 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID '4c2d784197' failed: TypeError: Cannot read property "publishMQTT" from null in <eval> at line number 32 at column number 3
Here is the rule etc:
configuration: {}
triggers:
- id: "1"
configuration:
cronExpression: 0 0/2 * * * ? *
type: timer.GenericCronTrigger
- id: "3"
configuration:
itemName: Zigbee_Temperature_xxxx
type: core.ItemStateUpdateTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
//Because the zigbee only sends the temperature and humidity at random
times this
//makes the graphs and data on the weather web page doesn't work
properly
//so I will send the latest data every 2 minutes so hopefully that will
fix that issue.
//I had to change the USB console for the weather station and use SDR to
get the data but it didn't send
// the inside temperature, humidity and pressure. I am getting the
pressure from a BME280 device in the shed
var TOPIC="weewx"
var PAYLOAD = ""
//Below is using the xioami sensor in xxxx bedroom
//Have to change the weewx.conf file as well
//temperature=(items.getItem("Zigbee_temperature_bedroom_xiaomi_xxxx").state)
//humidity=(items.getItem("Zigbee_humidity_bedroom_xiaomi_xxxx").state)
//var PAYLOAD=(JSON.stringify({"humidity": humidity, "temperature":
temperature}))
//Below is using the aquara sensor in xxxx room
var temperature=(items.getItem("Zigbee_Temperature_xxxx").state)
var humidity=(items.getItem("Zigbee_humidity_xxxx").state)
var pressure=(items.getItem("Zigbee_xxxx_pressure_sensor").state)
var PAYLOAD=(JSON.stringify({"humidity": humidity, "temperature":
temperature, "pressure": pressure}))
//Below is using the aquara sensor in xxxxs room
//temperature=(items.getItem("Zigbee_bedroom_xxxx_temperature").state)
//humidity=(items.getItem("Zigbee_bedroom_xxxx_humidity").state)
//pressure=(items.getItem("Zigbee_xxxx_pressure_sensor").state)
//var PAYLOAD=(JSON.stringify({"humidity": humidity, "temperature":
temperature, "pressure": pressure}))
//actions.get("mqtt","mqtt:broker:mqttbroker").publishMQTT(TOPIC,
PAYLOAD, false);
var mqttAction = actions.get("mqtt", "mqtt:broker:mqttbroker");
//For some unknow reason this doesn't work if I clean the cache and I
have to save the rule then it works
//if (mqttAction !== null) {
mqttAction.publishMQTT(TOPIC, PAYLOAD, false);
//} else {
// message = "<H2>Rule 4c2d784197 not working <br>" + "</H2>" + "Just
save the rule and then it works. Only does it after cache clear " ;
// actions.get("mail",
"mail:smtp:a514b96249").sendHtmlMail("user@gmail.com", "Rule
4c2d784197 not working", message );
// console.error("MQTT action could not be retrieved. Check MQTT broker
configuration.");
//}
//actions.Exec.executeCommandLine(time.Duration.ofSeconds(5),
"/usr/bin/mosquitto_pub","\-h","192.168.1.164","\-t","" + TOPIC,"\-m",""
+ PAYLOAD);
//console.log(JSON.stringify({"humidity": humidity, "temperature":
temperature}))
type: script.ScriptAction
This warning comes up as well but I don’t think it is associated with this script:
[WARN ] [e.script.ScriptTransformationService] - Script engine context config:js:6912317660 is already closed, this should not happen. Recreating
script engine.
I have commented out a lot of the script to try lots of things but nothing worked. The only way to get it to work is re-save the rule.
I am not 100% sure but I think this worked fine in openHab 4.0 (I could be wrong though)
Anyone else seeing this?