Execution of if-expressions in a rule

Dear all,

i’ve been struggling with my if-expression in a rule for already a couple of days without any hint, why it has not been working. See the code below. I would be grateful for any help.

  • Platform information:

    • openHAB version: 2
  • Issue of the topic: My if-expression in the rule is not executed even the condition is true

Rules code related to the issue

when
Switch1 changed or
Switch2 changed

then
if(switch1 == ON || switch2 == ON) {
createTimer(now.plusSeconds(10)), [| Temp = 5]
}

There are no errors in the log. But the if-expression is not executed.

Thanks

So many errors:

  • No rule title
  • Item Swith1 changed
  • switch1 instead of Switch1
  • If you change the state of an item use .state
  • check your brackets for the sreateTimer action
  • What is Temp?
  • No end of rule

There must be. Did you check both logs?
And did you read: https://www.openhab.org/docs/tutorial/rules.html and Rules | openHAB

rule "My Rule"
when
    Item Switch1 changed or
    Item Switch2 changed
then
    if (Switch1.state == ON || Switch2.state == ON) {
        createTimer(now.plusSeconds((10), [ Temp = 5 ])
    }
end
1 Like

I am sorry.

I hadn’t the original code, when I described the problem. Actually my program code is almost exactly like in your example.

Switch1 and 2 and Temp are existing items from the .items file.

Is it a must to use state in the if-expression? I thought if switch is a binary variable it is not required using the state parameter.

Switch I assume is an Item.
Events can only trigger on item and channel events
Not on variables

Yes, it is an Item. But it is a binary Item (correct me if I’am wrong). As I wrote bevor, the trigger itself has been working properly. It is just the if-expression that hasn’t worked. The program has not entered it. Without if with just the timer and command everything is fine.

Is using of Item.state == ON for exemple a must? Or can I use for a switch Item Item == ON as well?

Yes

If Temp is also an item, trying to set it to new state doesn’t work the way you tried.
Use it like:

Temp.postUpdate (5)

1 Like

Temp is an item as well. It is a set point for the temperature control. It has ben working as it should.

Thank you very much for the prompt help.

If it works now, please mark this thread as resolved by selecting the solution (checkmark) icon on any post.