Issue with rule engine condition

Have an issue with rule execution and conditions. Rule has been created using “MainUI”.
The dimmer lamp should be set to 50 if its state is <= 40. But it only fires if its state is = 0 (0% is OFF).
Wonder about the condition operator “\u003c\u003d”. Shoudn’t it be “\u2264”?

For the 1st condition (outdoor luminance) the same condition operator seems to work. This is strange.

Thanks for your help in advance.

Json-file code looks like this:

“878d5ab9-321d-4fb8-9a17-269bc0749537”: {
“class”: “org.openhab.core.automation.dto.RuleDTO”,
“value”: {
“triggers”: [
{
“id”: “1”,
“label”: “Zustandsvariable nach Ausloesen des Bewegungsmelders fuer 120 Sekunden auf "JA" gesetzt wird”,
“description”: “This triggers the rule if an item state has changed.”,
“configuration”: {
“itemName”: “BewegungsmelderZustandbeiAusloesung_Schalter”,
“previousState”: “OFF”,
“state”: “ON”
},
“type”: “core.ItemStateChangeTrigger”
}
],
“conditions”: [
{
“inputs”: {},
“id”: “2”,
“label”: “die Luminanz außen kleiner als 40% ist (es dunkel ist)”,
“description”: “Compares the item state with the given value”,
“configuration”: {
“itemName”: “BewegungsmelderBergreifend_Luminance”,
“operator”: “\u003c\u003d”,
“state”: “40”
},
“type”: “core.ItemStateCondition”
},
{
“inputs”: {},
“id”: “4”,
“label”: “wenn die Lampe auf weniger als 40% Helligkeit steht”,
“description”: “Compares the item state with the given value”,
“configuration”: {
“itemName”: “StehlampeWohnzimmer_Dimmer”,
“operator”: “\u003c\u003d”,
“state”: “40”
},
“type”: “core.ItemStateCondition”
}
],
“actions”: [
{
“inputs”: {},
“id”: “3”,
“label”: “schalte die Stehlampe auf 50% Helligkeit (Ein)”,
“description”: “Sends a command to a specified item.”,
“configuration”: {
“command”: “50.0”,
“itemName”: “StehlampeWohnzimmer_Dimmer”
},
“type”: “core.ItemCommandAction”
},
{
“inputs”: {},
“id”: “5”,
“label”: “schaltet Kandelaber ein”,
“description”: “Sends a command to a specified item.”,
“configuration”: {
“command”: “ON”,
“itemName”: “HMLCSw1FMIEQ0002028_1_State”
},
“type”: “core.ItemCommandAction”
}
],
“configuration”: {},
“configDescriptions”: [],
“uid”: “878d5ab9-321d-4fb8-9a17-269bc0749537”,
“name”: “Stehlampe und Kandelaber nach Auslösen des Bewegungsmelders einschalten”,
“tags”: [],
“visibility”: “VISIBLE”,
“description”: “Schaltet die Stehlampe im Wohnzimmer und den Kandelaber auf der Terrasse fuer 120 Sekunden ein”
}
},

It’s easier to read the YAML and it’s important to use code fences.

```
code goes here
```

Open the rule and click on the “Code” tab and paste that in.

Hope that this is better?

configuration: {}
triggers:
  - id: "1"
    label: Zustandsvariable nach Ausloesen des Bewegungsmelders fuer 120 Sekunden
      auf "JA" gesetzt wird
    description: This triggers the rule if an item state has changed.
    configuration:
      itemName: BewegungsmelderZustandbeiAusloesung_Schalter
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
conditions:
  - inputs: {}
    id: "2"
    label: die Luminanz außen kleiner als 40% ist (es dunkel ist)
    description: Compares the item state with the given value
    configuration:
      itemName: BewegungsmelderBergreifend_Luminance
      state: "40"
      operator: <=
    type: core.ItemStateCondition
  - inputs: {}
    id: "4"
    label: wenn die Lampe auf weniger als 40% Helligkeit steht
    description: Compares the item state with the given value
    configuration:
      itemName: StehlampeWohnzimmer_Dimmer
      state: "40"
      operator: <=
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "3"
    label: schalte die Stehlampe auf 50% Helligkeit (Ein)
    description: Sends a command to a specified item.
    configuration:
      itemName: StehlampeWohnzimmer_Dimmer
      command: "50"
    type: core.ItemCommandAction
  - inputs: {}
    id: "5"
    label: schaltet Kandelaber ein
    description: Sends a command to a specified item.
    configuration:
      itemName: HMLCSw1FMIEQ0002028_1_State
      command: ON
    type: core.ItemCommandAction

This the is second time I’ve see weird behavior with a Dimmer Item in a condition. I’m not sure whether it’s a real bug or if something else is going on. But if you use a Script Condition is should work. I you choose Script Condition and choose Rules DSL use the following code.

(StehlampeWohnzimmer_Dimmer.state as Number) <= 40
1 Like

Thanks Rich for this great support. Is my first script application as rule condition. Works out as you proposed.

(StehlampeWohnzimmer_Dimmer.state as Number) = 50

Applied this script condition in another rule which switches the dimmer lamp off again. This doesn’t work out. But here the item state condition with = 50 works.

Do you have any explanation for this strange behavior?

Not without a ton more information and logs about the state of all the Items involved with this other rule.

Can you please log:set DEBUG org.openhab.core.automation.internal.module.handler.ItemStateConditionHandler and then trigger the rule when the condition is fulfilled and when it is not fulfilled? You can return to “normal” logging by log:set DEFAULT org.openhab.core.automation.internal.module.handler.ItemStateConditionHandler.

You should see a message at DEBUG level which looks like temStateCondition '{}' checking if {} {} {} with the {} replaced by actual values.

1 Like

If this is the condition you used then the problem may be as simple as your test is not correct. One = sets the left-side variable to the right-side value. You want to test if the two are equal, and that uses == instead.

(StehlampeWohnzimmer_Dimmer.state as Number) == 50
2 Likes

Logged this using item state condition for both conditions:

2022-10-27 07:36:30.837 [DEBUG] [le.handler.ItemStateConditionHandler] - ItemStateCondition '2' checking if BewegungsmelderBergreifend_Luminance < 40
2022-10-27 07:36:30.837 [DEBUG] [le.handler.ItemStateConditionHandler] - ItemStateCondition '4' checking if StehlampeWohnzimmer_Dimmer <= 40

The rule doesn’t work out. The dimmer is set only if it is OFF before. If it is preset to e.g. 20, the rule doesn’t work. Could this be a bug?

Logged this using the script condition which Rich proposed:

2022-10-27 07:43:44.542 [DEBUG] [le.handler.ItemStateConditionHandler] - ItemStateCondition '2' checking if BewegungsmelderBergreifend_Luminance < 40

The 2nd one is now a script condition and obviously not logged by the item state handler. Now the rule works out.

If i apply this script condition, the rule works out. Seems to be quite tricky for a standard user like me.
Many thanks for your hint.

Conclusion:
Using item state condition versus script condition makes a big difference w.r.t. the applied operators.

Ok, this looks like a bug. I’ll try to reproduce that.

2 Likes

I don’t think this is bug. My interpretation is that this is a confusion that stems from the fact that the “is equal to” condition uses just “=” as its operator symbol.

A beginner trying to learn can create a “greater than or equal to” item condition and then look at the code and see:

    configuration:
      itemName: some_item_here
      operator: ">="
      state: "250"

Translating that into a script condition just requires copying the operator value directly:

(some_item_here.state as Number) >= 250

However, the yaml for the “is equal to” condition shows

    configuration:
      itemName: some_item_here
      operator: "="
      state: "250"

So the logical conclusion for a user just starting out is that you just copy the operator value again but of course that gets

(some_item_here.state as Number) = 250

which is not the intended result.

1 Like

I think @J-N-K is referring to the behavior with Dimmers as the Item for the condition. This is the second time I’ve seen reported situations where the UI condition is used with a Dimmer Item and it didn’t work. I’ve not had a chance to explorer further or I would have filed an so am glad Jan’s on the case.

In the other thread we explored this a bit, changing the Item type to Number seemed to fix the problem too, but there was so much going on in that thread it wasn’t clear to me that the Dimmer was the original problem.

2 Likes

Definitely a bug. The ItemStateConditionHandler is not able to handle PercentType. I’ll fix that.

4 Likes

FTR: Fixed in Fix ItemStateCondition for PercentType values by J-N-K · Pull Request #3136 · openhab/openhab-core · GitHub

2 Likes

Many thanks Jan. We seem to be a good “team” in identifying bugs :wink:.

The issue really is a clearly reproducible bug. It becomes difficult if it only happens rarely or if the difference between a working and a broken setup can‘t be found.

If the user can show a working and a non-working example which have only minor differences, then it‘s usually not that hard to find the issue.

1 Like

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