I’ve got an item to set my rollershutter status (1-6)…
Number SYS_Rollo_Status "Rollo Status"
This status is set within a rule…
var Number VAR_Rollo_Status_OLD = 0
var Number VAR_Rollo_Status_NEW = 0
rule "SMARTHOME/Variablensteuerung"
when
Item ASTRO_Azimuth changed or
Item SYS_Rollo_AutoDrive changed from OFF to ON
then
VAR_Rollo_Status_OLD = 0
VAR_Rollo_Status_NEW = 0
// -------------------------------------------------------------------------------- Rollo-Status
// Setzen der Hilfsvariable
VAR_Rollo_Status_OLD = SYS_Rollo_Status.state
// Festlegen des Rollo-Status
if ((ASTRO_Azimuth.state <= 130) && (ASTRO_Elevation.state > -3) && (ASTRO_Elevation.state <= 3)) { VAR_Rollo_Status_NEW = 1 }
else if ((ASTRO_Azimuth.state > 90) && (ASTRO_Azimuth.state <= 180) && (ASTRO_Elevation.state > 3)) { VAR_Rollo_Status_NEW = 2 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Azimuth.state <= 250) && (ASTRO_Elevation.state > 15)) { VAR_Rollo_Status_NEW = 3 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Azimuth.state <= 250) && (ASTRO_Elevation.state > 10) && (ASTRO_Elevation.state <= 15)) { VAR_Rollo_Status_NEW = 4 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Elevation.state <= 3) && (ASTRO_Elevation.state > -3)) { VAR_Rollo_Status_NEW = 5 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Elevation.state <= -3)) { VAR_Rollo_Status_NEW = 6 }
// Setzen der Do-Variable
if (VAR_Rollo_Status_NEW != VAR_Rollo_Status_OLD) { SYS_Rollo_Status.postUpdate(VAR_Rollo_Status_NEW) }
end
Unfortunately every time that rule is triggered it throws an error…
2018-10-27 12:10:25.143 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'SMARTHOME/Variablensteuerung': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_notEquals(java.lang.Number,java.lang.Number) on instance: null
many thanks for your reply. Don’t know what caused the error in the end, but this is now a working version of my rule to help others that may face the same issue.
rule "SMARTHOME/Variablensteuerung"
when
Item ASTRO_Azimuth changed or
Item SYS_Rollo_AutoDrive changed from OFF to ON
then
// Setzen der Hauptvariablen
VAR_Rollo_Status_OLD = 0
VAR_Rollo_Status_NEW = 0
// Setzen der Hilfsvariable
VAR_Rollo_Status_OLD = SYS_Rollo_Status.state as Number
// -------------------------------------------------------------------------------- Rollo-Status
// Festlegen des Rollo-Status
if ((ASTRO_Azimuth.state <= 130) && (ASTRO_Elevation.state > -3) && (ASTRO_Elevation.state <= 3)) { VAR_Rollo_Status_NEW = 1 }
else if ((ASTRO_Azimuth.state > 90) && (ASTRO_Azimuth.state <= 180) && (ASTRO_Elevation.state > 3)) { VAR_Rollo_Status_NEW = 2 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Azimuth.state <= 250) && (ASTRO_Elevation.state > 15)) { VAR_Rollo_Status_NEW = 3 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Azimuth.state <= 250) && (ASTRO_Elevation.state > 3) && (ASTRO_Elevation.state <= 15)) { VAR_Rollo_Status_NEW = 4 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Elevation.state <= 3) && (ASTRO_Elevation.state > -3)) { VAR_Rollo_Status_NEW = 5 }
else if ((ASTRO_Azimuth.state > 180) && (ASTRO_Elevation.state <= -3)) { VAR_Rollo_Status_NEW = 6 }
// ACTION
if (VAR_Rollo_Status_NEW != VAR_Rollo_Status_OLD || SYS_Rollo_AutoDrive.state == ON) {
// Die nächste Zeile triggered die Rollo-Steuerung an
SYS_Rollo_Status.postUpdate(VAR_Rollo_Status_NEW)
}
end
2018-10-27 12:10:25.143 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'SMARTHOME/Variablensteuerung': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_notEquals(java.lang.Number,java.lang.Number) on instance: null
That the only part of the rule where you use !=
What I think happens is that when you do: VAR_Rollo_Status_OLD = SYS_Rollo_Status.state openHAB assign the state object to the variable and not the number value even though you declared he variable as a Number
So we need to force openHAB to assign the Number value of the state by using as Number
I avoid these issues in my rules by changing most of the item states to val or var at the beginning of the rule as well as checking for NULL values to avoid error during restart.
If I am going to use an item state only once then I do:
if ((myItem.state as Number) > 555) { ...
But if I am going to use that item’s state several times then I assign a variable. The code is shorter and easier to follow. Also, if I want to change the item, I only have to do it in one place or if I want to make the rule more generic I can assign anything I want to that variable without changing the rest of the code.