Rules are not performed after some uptime

It’s me again. Issue reoccoured.
This is my log:

21:05:33.151 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'sz_r_sw ' received command 1
21:05:33.161 [INFO ] [smarthome.event.ItemStateChangedEvent] - sz_r_sw  changed from 3 to 1

21:05:37.766 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'sz_r_sw ' received command 2
21:05:37.773 [INFO ] [smarthome.event.ItemStateChangedEvent] - sz_r_sw  changed from 1 to 2

and my rule:

then
logInfo("sz_r.rules", "begin")
        if (sz_r_sw .state == "0") {
                logInfo("sz_r.rules", "0")
                sz_r.sendCommand(0)  }
        else if (sz_r_sw .state == "1") {
                logInfo("sz_r.rules", "1")
                sz_r.sendCommand(65)  }
        else if (sz_r_sw .state == "2") {
                logInfo("sz_r.rules", "2")
                sz_r.sendCommand(80)  }
        else if (sz_r_sw .state == "3") {
                logInfo("sz_r.rules", "3")
                sz_r.sendCommand(100)  }
        else
        logInfo("sz_r.rules", "nothing")
end

so the rule is NOT executed. strange.
Wil now try @rlkoshak s rule format

There are TWO logs. The contents of the logInfo go to openhab.log, not events.log. What is in openhab.log?

Double check that your rule name is unique.
I experienced trouble with duplicated rule names.

nothing in oh.log

Try changing the rule trigger and use the receivedCommand implicit variable

rule "sz_r"
when
    Item sz_r_sw received command
then
    logInfo("sz_r.rules", "begin")
    val String swState = receivedCommand
    if (swState == "0") {
        logInfo("sz_r.rules", "0")
        sz_r.sendCommand(0)
    }
    else if (swState == "1") {
        logInfo("sz_r.rules", "1")
        sz_r.sendCommand(65)
    }
    else if (swState == "2") {
        logInfo("sz_r.rules", "2")
        sz_r.sendCommand(80)
    }
    else if (swState == "3") {
        logInfo("sz_r.rules", "3")
        sz_r.sendCommand(100)
    }
    else logInfo("sz_r.rules", "nothing")
end

The name ‘recievedCommand’ cannot be resolved to an item

same problem with your better readable rule

stupid question: did you correct spelling error in your file? Needs to read receivedCommand (above ei are reversed in receive)

another question, not sure if relevant:
are you using VS Code (if not please do for syntax validation)?
your rule files has some spaces where I would not expect them and where they might create problems:
For example:
else if (sz_r_sw .state == "2")
not sure whether the space in front of .state might cause you grief…but maybe just a copy/paste problem?

yes of course your correct spelling works a lot better.
I use VS code ^^ “receivedCommand” is marked as wrong anyways in VS
(the spaces are not in my rule. this must happend because i copied to my Texteditor

Well lets see how long this rule will be executed

This is why when I copy a code snippet because I like it and I want to make use of it, I COPY it, line by linee, word by word, symbol by symbol. So this way I can learn it at the same time.
Copying and pasting code leads to no end of trouble. As you just found out.

Your last code worked since a week - thank you. (thoe one with “Item sz_r_sw received command”)

I appreciate all help!

But it would be interesting to know why the other rule does not work after some time.
Isn’t there any traceprofile for the rule engine?

Which one?

the one I began with in the initial post

I was too fast… rules are again not performed…

no clue why…

Is there no chance to bebug the rules with logentries inside the rules`?
I am alwasy wondering if the is a chance to enable special logging profile

something like:

log:set DEBUG org.openhab.ruleengine

Do you have long running rules like rules with Thread::sleep or calls to long running actions like sendHttp*Request or execute Command Line? If so see Why have my Rules stopped running? Why Thread::sleep is a bad idea.

I don’t know if what the base package is for the rules engine or whether there is anything useful in debug or trace.

no longtime rules or sleep :confused:

Have you tried clearing the cache and tmp files to see if that will help?

You can use the following commands (for apt-get install):

sudo systemctl stop openhab2

sudo openhab-cli clean-cache

sudo systemctl start openhab2

No guarantee it will work but its worth trying.:crossed_fingers:

but sadly not solved the issue:(

I had the same in the past
out of blue sky rule engine does not run any rule until restart.

I got away by itself with new OH builds … but just happens now again on the current build to me.