Cant make this rule work

This rule just doesent work it makes all my rules stop working…

rule "PCSTATE1"
when
	Item PCSTATE1 changed to ON
then if (PCSTATE.state == "Online") {
	createTimer(now.plusSeconds(5)) [
		if (PCSTATE.state == "Online") {
		PC.sendCommand(ON)}]
		createTimer(now.plusSeconds(2)) [
		PCSTATE2.sendCommand(0N)]}
else if (PCSTATE.state == "Offline") {
	createTimer(now.plusSeconds(5)) [
		if (PCSTATE.state =="Offline") {
		PCSTATE4.sendCommand(ON)}]}
end

But when i remove the second timer on the rule it works but i need that second timer.

rule "PCSTATE1"
when
	Item PCSTATE1 changed to ON
then if (PCSTATE.state == "Online") {
	createTimer(now.plusSeconds(5)) [
		if (PCSTATE.state == "Online") {
		PC.sendCommand(ON)}]}
else if (PCSTATE.state == "Offline") {
	createTimer(now.plusSeconds(5)) [
		if (PCSTATE.state =="Offline") {
		PCSTATE4.sendCommand(ON)}]}
end

I am doing something wrong but i dont know how to make it work damit.

Use

Thread::sleep(2000)

for that.

One obvious thing… You have a 0 (zero) here. Should be ON, not 0N.

You might want to consider using VS Code with the openHAB extension. Makes it easy to find these types of errors.

2 Likes

Just be mindful that by default the rule engine has 5 threads available to execute rules. Sleeping for 2 seconds will block one of those threads for 2 seconds. Depending on how many other rules you have, how frequently those rules execute, and how often you use sleep in your other rules, you easily could exhaust the 5 available threads.

Wait what you are right it really has a 0 in there that is probably the problem omfg i was looking at this for hours and the problem was a 0… thanks man xD