I’m using the SNMP binding to read String items (digital switches connected to a router):
Group gVGStatus
String vg_403_sw_1 "VG 403 [%s]" (gVGStatus) { snmp="<[192.164.3.1:public:1.3.6.1.4.1.30140.2.3.1.0:10000]" }
String vg_403_sw_2 "VG 403 [%s]" (gVGStatus) { snmp="<[192.164.3.1:public:1.3.6.1.4.1.30140.2.3.2.0:10000]" }
String vg_403_status "VG 403 Status [%s]"
String vg_404_sw_1 "VG 404 [%s]" (gVGStatus) { snmp="<[192.164.4.1:public:1.3.6.1.4.1.30140.2.3.1.0:10000]" }
String vg_404_sw_2 "VG 404 [%s]" (gVGStatus) { snmp="<[192.164.4.1:public:1.3.6.1.4.1.30140.2.3.2.0:10000]" }
String vg_404_status "VG 404 Status [%s]"
...
In a rule I need to evaluate both of these states (*_sw_1 and *_sw_2) to decide on the actual status of the device behind those two digital inputs. As I have to read data from a lot of routers I would like to have a generic rule, so decided to put them in groups and use the Member of trigger:
rule "VG Status"
when
Member of gVGStatus changed
then
val split = triggeringItem.name.split("_") // split the name of the item
val vgstatusname0=split.get(0)
val vgstatusname1=split.get(1)
val vgstatusname2=split.get(2)
val vgstatusname3=split.get(3)
val newSw1=vgstatusname0.toString+"_"+vgstatusname1.toString+"_"+vgstatusname2.toString+"_1" //put the splitted parts together for first new item, for example vg_403_sw_1
val newSw2=vgstatusname0.toString+"_"+vgstatusname1.toString+"_"+vgstatusname2.toString+"_2" //put the splitted parts together for second new item, for example vg_403_sw_2
val newStatus=vgstatusname0.toString+"_"+vgstatusname1.toString+"_status" //put the splitted parts together for a status item, for example vg_403_status
if ((newSw1.state.toString=="0") && (newSw2.state.toString=="0")) {
newStatus.postUpdate("status1")
}
else if ((newSw1.state.toString=="1") && (newSw2.state.toString=="0")) {
newStatus.postUpdate("status2")
}
else if ((newSw1.state.toString=="0") && (newSw2.state.toString=="1")) {
newStatus.postUpdate("status3")
}
else if ((newSw1.state.toString=="1") && (newSw2.state.toString=="1")) {
newStatus.postUpdate("status4")
}
end
When one of the items gets triggered (*_sw_X)
I need to know the state of the corresponding second item (*_sw_Y)
.
Unfortunately as soon as I type the “state” to any of the newSwX.state.toString=="X"
I get an error:
Rule ‘VG Status’: ‘state’ is not a member of ‘java.lang.String’; line 19, column 14, length 12
and in VSC:
The method or field state is undefined for the type String (org.eclipse.xtest.diagnostics.Diagnostic.linking [19,21]
I made sure all items are having a state. I’m on openHAB 2.5 Milestone1 on Win 10 for testing.
Thx for any hints.