Comparison in Main UI Rule not working?

I was working on a rule that checks for open windows when a room turns to “empty.” In the main UI I have a condition set, “But only if BackYard_TemperatureSensor < 10 ºC” the rule ignores this and runs every time a room has changed to empty. If I, instead, us an inline script to test for this same condition, it works. I have tried this condition with and without the UoM with the same result - the rule runs regardless of the test condition.

Here is the code from the rule:

configuration: {}
triggers:
  - id: "1"
    configuration:
      groupName: gRoomOccupancy
      state: OFF
    type: core.GroupStateChangeTrigger
  - id: "5"
    configuration:
      groupName: Room_Presence_Sensors
      state: OFF
    type: core.GroupStateChangeTrigger
conditions:
  - inputs: {}
    id: "4"
    configuration:
      itemName: BackYard_TemperatureSensor
      state: 10 ºC
      operator: <
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript;version=ECMAScript-2021
      script: >-
        var triggerItem = items.getItem(event.itemName)

        var itemRoom =
        actions.Semantics.getLocation(triggerItem.rawItem).name.toString()

        var openWindow = items.getItem(itemRoom).members.filter(i => i.tags ==
        "Window" && i.state == "OPEN")

        var iterations = 0;

        console.log("Open Window Rule Triggered")

        var noticeInterval = setInterval(()=>
                {if(iterations > 5){
                  clearInterval(noticeInterval);
                }else if(itemRoom.state == "OFF" && !openWindow.length) {
                    actions.NotificationAction.sendBroadcastNotification(`The ${openWindow.name} is still open. Can you close it please.`)
                    noticeIterations++
                    }
                }, 1000*60*5)
    type: script.ScriptAction

I’m happy using the inline script condition, but I thought I should point out this anomaly to be on the safe side. and support the developers.

  • Platform information:
    • Hardware: Gigabyte Brix MiniPC model GB-BXI7-5775R/MBHM87P-00 BIOS F2. 8GB RAM, 228GB HDD.
    • OS: Ubuntu 22.04.4 LTS
    • Java Runtime Environment: Zulu17.50+19-CA (build 17.0.11+9-LTS)
    • openHAB version: 4.2.0

Does BackYard_TemperatureSensor have a Unit of measurement?
If so then you are comparing a string and not a number as far as I know.
There is lots of discussions about this in the forum.
Hope that helps?
Personally I don’t use the UOM I just have numbers to make it easier for myself. :grinning:

But it’s even not complicated with a UOM. It just has to be put into square brackets within the comparison, e.g.:
15 [℃]

1 Like

I tried with and without UoM, neither worked, but I never tried buting the UoM in brackets, I don’t remember seeing that anywhere in the documentation.

Soooo, I just tried putting the UoM in brackets. The rule worked. Then I tried leaving the UoM out, just putting the number ( > 10), and that also worked. Then I tried including the UoM without brackets ( > 10 ºC) and that worked also. So I really don’t know what was going on 2 days ago and what changed today.

Once again, two rules with a conditions have stopped working. Once I removed the condition, the rules worked again. When I put the condition back into the rule (all via the Main UI) it works. Whatever this problem is, it only manifests itself after a number of days. I’m not sure what triggers this failure. I have not touched either rule since modifying the conditions. It runs fine, then suddenly doesn’t run at all anymore. I’m not sure what logging event I should modify in order to get more info about this.

Could it be that the item state is undefined when you are comparing? It could be that you restarted the system and the item state is not persisted across restarts?

I have RRD4J and MapDB for persistance and have restore on restart defined in the persistence strategies.

This same problem has cropped up on a different rule. the items specified in the conditions are in a defined state, everything looks fine. It was running without problems for several months. Now, suddenly a rule is running in spite of a condition not being met. Could this be a bug?

This problem has once again shown up on a different rule. One of the conditions were not met, but the rule ran anyway.

configuration: {}
triggers:
  - id: "4"
    configuration:
      itemName: LivingroomSensor_Temperature
    type: core.ItemStateChangeTrigger
conditions:
  - inputs: {}
    id: "1"
    configuration:
      itemName: LivingroomSensor_Temperature
      state: 24 ºC
      operator: ">"
    type: core.ItemStateCondition
  - inputs: {}
    id: "2"
    configuration:
      itemName: Sun_Position
      state: "180"
      operator: ">"
    type: core.ItemStateCondition
  - inputs: {}
    id: "5"
    configuration:
      itemName: Sun_Position
      state: "185"
      operator: <
    type: core.ItemStateCondition
  - inputs: {}
    id: "6"
    configuration:
      itemName: Current_Cloudiness
      state: ".50"
      operator: <
    type: core.ItemStateCondition
  - inputs: {}
    id: "7"
    configuration:
      itemName: WarmSeason
      state: ON
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript;version=ECMAScript-2021
      script: >-
        items.getItem("Bedroom_Shutters").sendCommandIfDifferent("20");

        items.getItem("Big_Window").sendCommandIfDifferent(100)

        setTimeout(()=> {items.getItem("BigWindow_Stop").sendCommand("ON");},
        21000)


        actions.notificationBuilder("Temperature Control rule triggered. The
        living room temp is " + items.LivingroomSensor_Temperature.state + ".
        Sun Position is " +
                                    items.Sun_Position.state + "Current_Cloudiness is " + items.Current_Cloudiness.state).addUserId('kchest@gmail.com').send()

        console.log("Temperature Control rule triggered. The living room temp
        is" + items.Livingroomsensor_Temperature.state + ". Sun Position is " +
                    Sun_Position.state + "Current_Cloudiness is " + Current_Cloudiness.state)
    type: script.ScriptAction

The temperature was 20.4º, well below the threshold of 24º defined in the rule.

I think the units still need brackets to work properly like:

conditions:
  - inputs: {}
    id: "1"
    configuration:
      itemName: OpenWeather_temp
      state: 20 [℃]
      operator: ">"
    type: core.ItemStateCondition

my other suggestion would be to make a copy of the rule without condition that logs the values and the result of the comparison within an action.

Brackets added. Now its a matter of waiting. Thanks for the suggestion.