A couple of days in to trying to climb the curve of openHAB, and I’ve reached the heady heights of trying my first rule … and failing miserably. I’ve abandoned PaperUI other than as a guide to structure/content of configuration files.
So, as a very simple scenario, I’m looking at the OID codes from my printer via the ‘snmp’ addon, and I want to determine the amount of black toner remaining. That works fine up to a point; I can get the maximum and current toner amounts (so essentially job done), but I wanted to generate a % remaining item, and thought to do so with my simple rule.
Printer.things
Thing snmp:target:Printer "Printer" @ "Study" [ hostname="192.168.2.200", protocol="v2c" ] {
Channels:
Type number : Max_Black "Max. Black:" [ oid=".1.3.6.1.2.1.43.11.1.1.8.1.4", mode="READ",datatype="UINT32" ]
Type number : Cur_Black "Cur. Black" [ oid=".1.3.6.1.2.1.43.11.1.1.9.1.4", mode="READ",datatype="UINT32" ]
}
Printer.items
Number Max_Black "Maximum black:" { channel="snmp:target:Printer:Max_Black" }
Number Cur_Black "Current black:" { channel="snmp:target:Printer:Cur_Black" }
Number Lvl_Black "Black:"
Printer.rules
rule "Printer_test"
when
Item Max_Black received update
then
var Number num1 = Max_Black.state as Number
var Number num2 = Cur_Black.state as Number
var Number num3 = num2 * 100 / num1
Lvl_Black.postUpdate(num3)
end
TheSutherlands.sitemap
sitemap TheSutherlands label="Main Menu"
{
Frame {
Text item=Max_Black
Text item=Cur_Black
Text item=Lvl_Black
}
}
So, trying this in the Simple or ClassicUI, I get the two channel readings ok (Max & current black), but I get an ‘ERR’ or nothing for the calculated black%. I also see from logging within the rule that num3 has a value of the form 40.00000000, which is also throwing me.
My immediate thoughts were type mismatches, but it is difficult to see item/value type in openHAB compared with doing so in python or javascript. I can see that this must be a basic misunderstanding on my part, but I’m getting to the point where I am feeling frustrated. There is plenty of documentation around (and I’ve certainly gone through a lot of it), but it appears to be written almost as a reference guide for people who are already familiar with openHAB.
Any help would be much appreciated