Remember that the transform only applies to the label not the actual value of the group
rule "Hardware Warning"
when
Group gFANS received update
then
if (gFANS.state.toString == "2") {
sendBroadcastNotification("Router Fan Warning!")
}
end
(function(i) {
if (i == 'NULL') { return i; }
if (i == '-') { return 'Undefined'; }
var val = parseInt(i); // The value sent by OH is a string so we parse into an integer
val = val/60; //Divide by 60 to get a minutes value
var days = 0; // Initialise variables
var hours = 0;
var minutes = 0;
I’m pretty sure MAX will work with Strings and that will handle all the possible states, not just OK and WARNING.
Of course, if I’m wrong about MAX being able to handle String then that won’t work. Though since these states are Numbers, unless the binding doesn’t support it, I’d use Number Items for the fans and the Group and the MAP in the labels.
Because the transform is only on the label, it will only show the transformed state on your sitemap or HABPanel. Everywhere else the “true” state of the Item is shown as you are seeing in the logs.
No, the state of the Item is 1-6. Only the label is showing “Warning” because it is only the label you are transforming. So you would need to use
if(gFANS.state.toString == "2")
I’d still recommend using Number type Items. Then you can do something like
if(gFANS.state >=3) sendBroadcastNotification("Router Fan Failure!")
Otherwise you need to test 3, 4, 5, and 6 individually.
Hi Rich, that was exaclty the issue in the rule, I’d need to test for each and every number. Ill make your suggested changes and report back!
I made the changes and they were accepted but I saw this:
06:40:12.146 [ERROR] [ipse.smarthome.core.items.GenericItem] - Tried to set invalid state 1 (StringType) on item gFANS of type NumberItem, ignoring it
06:40:12.161 [INFO ] [smarthome.event.ItemUpdatedEvent ] - Item 'gFANS' has been updated.
ITEMS:
/*SNNP Devices */
Group gSNMP
Group:Number:MAX gFANS "[MAP(3945snbmp.map):%s]"
String C3945_UpTime "C3945 UpTime [JS(time.js):%s]" (gSNMP) { snmp="<[192.168.0.254:LAN:1.3.6.1.2.1.1.3.0:500000]" }
wNumber C3945_CPU5Min (gSNMP) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.2.1.58.0:10000]" }
Number C3945_CPUTemp (gSNMP) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.3.1.3.1:500000]" }
Number C3945_PSUTemp (gSNMP) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.3.1.3.6:500000]" }
Number C3945_FAN1 "[MAP(3945snmp.map):%s]" (gFANS) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000]" }
Number C3945_FAN2 "[MAP(3945snmp.map):%s]" (gFANS) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.3:500000]" }
Number C3945_FAN3 "[MAP(3945snmp.map):%s]" (gFANS) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.4:500000]" }
Number C3945_FAN4 "[MAP(3945snmp.map):%s]" (gFANS) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.5:500000]" }
Number C3945_FAN5 "[MAP(3945snmp.map):%s]" (gFANS) { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.6:500000]" }
After stuffing around with the rule using your design pattern post rikoshak, I ended up with this rule:
rule "Hardware Warning"
when
Member of gFANS changed
then
if (gFANS.state = "2") {
sendBroadcastNotification("Router Fan Warning!")
}
if (gFANS.state >=3) {
sendBroadcastNotification("Router Fan Failure!")
}
end
You have a typo on CP3845_CPU5Min. That’s not relevant to your error, just something that I noticed.
As for the Rule, since gFANS is a Number Item, it’s state will be a Number so you need to compare it to a Number instead of “2”.
= is the assignment operator. It means save the result of the stuff on the right to the variable on the left. You want to use the comparison operator ==.
I highly highly recommend using VSCode with the OH extension. It will catching these errors even before you save the file.
if (gFANS.state == 2) {
What state is gFANS in your sitemap?
Just to make sure that the Group is being populated correctly restart your OH. I don’t know if this is still the case, but it used to be a problem that sometimes OH wouldn’t pick up changes to Groups every time.
rule "Hardware Warning"
when
Member of gFANS changed
then
if (gFANS.state = 2) {
sendBroadcastNotification("Router Fan Warning!")
}
if (gFANS.state >=3) {
sendBroadcastNotification("Router Fan Failure!")
}
end
rule "Hardware Warning"
when
Member of gFANS changed
then
if (gFANS.state = 2) {
sendBroadcastNotification("Router Fan Warning!")
}
if (gFANS.state >=3) {
sendBroadcastNotification("Router Fan Failure!")
}
end
You need to use “comparison operators” they are ==, >, <, >=, <= and != (There are others…)
When you use a single = it is an assignement operator like when you give a value to a variable
thisVariable = 0 makes the variable value 0
thisVariable == 0 is a test if the variable is equal to 0