Hi,
Thanks (and apologies, I’m new) in advance for tips. My setup:
- Hardware: Vsphere VM, 2GB Ram, 2 vcpu, 60GB HDD
- OS: Ubuntu 16.04
- Java Runtime Environment: Java 1.8.0_181
- openHAB version: 2.3.0
Here is my rule file:
rule Office_Total
when
Item HVAC_LVB_Total received update or
Item LVB_UPSB_Input_Active_Power received update
then
if (HVAC_LVB_Total.state instanceof DecimalType && LVB_UPSB_Input_Active_Power.state instanceof DecimalType) {
Office_Total.postUpdate((LVB_UPSB_Input_Active_Power.state as DecimalType) - (HVAC_LVB_Total.state as DecimalType))
} else {
Office_Total.postUpdate(UNDEF) // or UNDEF on OH2
}
end
The rule works. Unfortunately the data gathered in HVAC_LVB_Total and LVB_UPSB_Input_Active_Power vary, and so when subtracting one value from the other, the result is sometimes negative.
I want to accept whatever the result from the calculation is as a positive number.
I have read that using a Math function could help specifically Math::abs but I dont know how to write the code to achieve it. MOdifying the rule as follows, the rule works, but makes no difference to the resulting number (I still get a negative), playing with various other positions then the rule doesn’t work at all.
rule Office_Total
when
Item HVAC_LVB_Total received update or
Item LVB_UPSB_Input_Active_Power received update
then
if (HVAC_LVB_Total.state instanceof DecimalType && LVB_UPSB_Input_Active_Power.state instanceof DecimalType) {
Math::abs( Office_Total.postUpdate((LVB_UPSB_Input_Active_Power.state as DecimalType) - (HVAC_LVB_Total.state as DecimalType)))
} else {
Office_Total.postUpdate(UNDEF) // or UNDEF on OH2
}
end
Any guidance is much appreciated.
Alex