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.
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.
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?
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?