Hello,
This is my second attempt at making some rules for openhab.
I first did this rule using the item names. But of course you quickly consider the hassle that doing it that way would cause. So I looked into how to better manage items that need the same treatment. and of course I came across Groups.
Now to keep this simple and practical I started with a rule for a doorbell. I have some IOboards that a bound thru SNMP. I grouped some of those items as door-buttons and some as ringers. Of course there a more fancy ways to get notified about some one at your door but this is a start.
Unfortunately my rule does not appear to be executed as there is nothing apearing in the logs when the button is pushed. Though I can see that openhab registers the pressing of the button in the sitemap.
I get the following error in the openhab.log
2018-04-17 22:33:08.265 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test.rules' has errors, therefore ignoring it: [9,5]: no viable alternative at input 'DoorButtons'
I figure I have a mistake in the syntax but i have thus-far not found an example of triggering on a group.
What I did manage to find was a comment that “since a group is an item it can trigger a rule the same way an item does”.
But when I did “Item DoorButtons changed” it pruduces the following error.
2018-04-17 22:56:40.468 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'test.rules', using it anyway:
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.
What am I missing in my rule?
items
// Functional perspective
Group:Number Sensors
Group:Switch Actuators
Group:Switch Ringers (actuators)
Group:Number Temperatures (Sensors)
Group:Number DoorButtons (Sensors)
Switch DO1 "DO1" (Ringers) {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.1:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.1:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.1:0]"}
Switch DO2 "DO2" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.2:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.2:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.2:0]"}
Switch DO3 "DO3" (Ringers) {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.3:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.3:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.3:0]"}
Switch DO4 "DO4" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.4:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.4:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.4:0]"}
Switch DO5 "DO5" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.5:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.5:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.5:0]"}
Switch DO6 "DO6" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.6:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.6:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.6:0]"}
Switch DO7 "DO7" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.7:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.7:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.7:0]"}
Switch DO8 "DO8" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.8:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.8:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.1.2.8:0]"}
Switch DO9 "DO9" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.1:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.1:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.1:0]"}
Switch DO10 "DO10" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.2:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.2:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.2:0]"}
Switch DO11 "DO11" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.3:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.3:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.3:0]"}
Switch DO12 "DO12" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.4:1000:MAP(daenetip4.map)] >[OFF:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.4:1] >[ON:172.16.0.122:glados:.1.3.6.1.4.1.32111.1.4.2.4:0]"}
Number AI1 "AI1" (DoorButtons) {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.1:1000]"}
Number AI2 "AI2" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.2:1000]"}
Number AI3 "AI3" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.3:1000]"}
Number AI4 "AI4" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.4:1000]"}
Number AI5 "AI5" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.5:1000]"}
Number AI6 "AI6" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.6:1000]"}
Number AI7 "AI7" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.7:1000]"}
Number AI8 "AI8" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.8:1000]"}
//snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.5.1.1]"
Number DI1 "DI1" (DoorButtons) {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.1:1000]"}
Number DI2 "DI2" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.2:1000]"}
Number DI3 "DI3" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.3:1000]"}
Number DI4 "DI4" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.4:1000]"}
Number DI5 "DI5" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.5:1000]"}
Number DI6 "DI6" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.6:1000]"}
Number DI7 "DI7" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.7:1000]"}
Number DI8 "DI8" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.6.5.8:1000]"}
Number BOARDTEMPPERATURE "SystemTemp" {snmp="<[172.16.0.122:glados:.1.3.6.1.4.1.32111.1.3.4.10:1000]"}
rules
// Imports
// Global Variables
var Boolean ringersactive = false
var Boolean commandsent = false
rule "test doorbel"
when
Item group DoorButtons received update
then
commandsent = false
logInfo("a door button changed", "a door button changed")
DoorButtons.forEach[ doorbutton |
logInfo(doorbutton.name, doorbutton.name)
if ((!ringersactive && doorbutton.state > 10)) {
logInfo(doorbutton.name + " received update" + doorbutton.state, doorbutton.name + " received update " + doorbutton.state)
logInfo("turning on Ringers", "turning on Ringers")
gRingers.members.sendCommand("ON")
ringersactive = true
commandsent = true
}
else if((ringersactive && doorbutton.state < 10)) {
logInfo(doorbutton.name + " received update" + doorbutton.state, doorbutton.name + " received update " + doorbutton.state)
logInfo("turning off Ringers", "turning off Ringers")
gRingers.members.sendCommand("OFF")
ringersactive = false
commandsent = true
}
]
end
// Imports
rule "DIState"
when
Item DI received update
then
if((DI.state as DecimalType).intValue.bitwiseAnd(0x01)==0x01) DI1.postUpdate(ON) else DI1.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x02)==0x02) DI2.postUpdate(ON) else DI2.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x04)==0x04) DI3.postUpdate(ON) else DI3.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x08)==0x08) DI4.postUpdate(ON) else DI4.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x10)==0x10) DI5.postUpdate(ON) else DI5.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x20)==0x20) DI6.postUpdate(ON) else DI6.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x40)==0x40) DI7.postUpdate(ON) else DI7.postUpdate(OFF)
if((DI.state as DecimalType).intValue.bitwiseAnd(0x80)==0x80) DI8.postUpdate(ON) else DI8.postUpdate(OFF)
end
rule "AIState"
when
Item AI received update
then
if((AI.state as DecimalType).intValue.bitwiseAnd(0x01)==0x01) AI1.postUpdate("ON") else AI1.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x02)==0x02) AI2.postUpdate("ON") else AI2.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x04)==0x04) AI3.postUpdate("ON") else AI3.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x08)==0x08) AI4.postUpdate("ON") else AI4.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x10)==0x10) AI5.postUpdate("ON") else AI5.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x20)==0x20) AI6.postUpdate("ON") else AI6.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x40)==0x40) AI7.postUpdate("ON") else AI7.postUpdate("OFF")
if((AI.state as DecimalType).intValue.bitwiseAnd(0x80)==0x80) AI8.postUpdate("ON") else AI8.postUpdate("OFF")
end
rule "DOState"
when
Item DO received update
then
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0001)==0x0001) DO1.postUpdate(ON) else DO1.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0002)==0x0002) DO2.postUpdate(ON) else DO2.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0004)==0x0004) DO3.postUpdate(ON) else DO3.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0008)==0x0008) DO4.postUpdate(ON) else DO4.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0010)==0x0010) DO5.postUpdate(ON) else DO5.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0020)==0x0020) DO6.postUpdate(ON) else DO6.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0040)==0x0040) DO7.postUpdate(ON) else DO7.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0080)==0x0080) DO8.postUpdate(ON) else DO8.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0100)==0x0100) DO9.postUpdate(ON) else DO9.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0200)==0x0200) DO10.postUpdate(ON) else DO10.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0200)==0x0400) DO11.postUpdate(ON) else DO11.postUpdate(OFF)
if((DO.state as DecimalType).intValue.bitwiseAnd(0x0200)==0x0800) DO12.postUpdate(ON) else DO12.postUpdate(OFF)
end
rule "TempState"
when
Item BOARDTEMPPERATURE received update
then
BOARDTEMPPERATURE.postUpdate(ON)
end