Rule has stopped working?

Hi guys,

This rule was working fine but I’m now getting this error?

Script execution of rule with UID ‘backdoor-2’ failed: null in backdoor

val actions = getActions("mqtt", "mqtt:broker:mosquitto")

rule "back door open"

when
Item Back_Door changed
then
if(Back_Door.state ==OPEN)
actions.publishMQTT("comfort2/input17/set","1")
else
actions.publishMQTT("comfort2/input17/set","0") 
end

I think this might be something to do with OH2 - OH3?

First, get the reference to the action inside the rule. If the Broker Thing goes offline or other stuff goes wrong with the Broker Thing your reference to the Action will become stale. Also, if your .rules file happens to be loaded before the MQTT Broker Thing has initialized and become ONLINE the call to getActions will return null and your rule won’t be able to call publsihMQTT.

The error is complaining about the second rule in the file backdoor.rules. Please confirm that the shown rule is in fact the second one.

Add some logging to the rule to see it executing, see what state Back_Door is in, etc.

1 Like

thanks Rich,

there was indeed a second rule, I’ve now separated them into different files

this was the old rule

val actions = getActions("mqtt", "mqtt:broker:mosquitto")

rule "back door open"

when
Item Back_Door changed
then
if(Back_Door.state ==OPEN)
actions.publishMQTT("comfort2/input17/set","1")
else
actions.publishMQTT("comfort2/input17/set","0") 
end



rule "Fridge lights Motion"

when
Item Fridge_PIR_Occupancy changed
then
if(Fridge_PIR_Occupancy.state ==OPEN)
actions.publishMQTT("comfort2/input18/set","1")
else
actions.publishMQTT("comfort2/input18/set","0") 
end

Out of interest what did I do wrong?

thanks
matt

As I said, get the reference to the mqtt Action inside the rules, not at the top of the .rules file.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.