Es gibt in der if-Anweisung drei Bedingungen, welche in Frage kommen,
nElevation < nElevationMin
nAzimut < nAzimutMin
nIntens < nIntensityMin
Eigentlich sollte ide Formatierung keine Rolle spielen, aber zum Testen:
Code: Alles auswählen
val nElevationMin = 0 // 10
val nElevationMax = 300 // 45
val nAzimutMin = 0 // 130
val nAzimutMax = 210 // 210
val nIntensityMin = 0 // 80
val nCloudynessMax = 110 // 40
rule "Beschattung"
when
Item LokaleSonnendaten_Position_Elevation changed
then
if(!(LokaleSonnendaten_Position_Elevation.state instanceof Number)) {
logWarn("shade","Elevation ungültig! Abbruch!")
return;
}
if(!(LokaleSonnendaten_Azimut.state instanceof Number)) {
logWarn("shade","Azimut ungültig! Abbruch!")
return;
}
val nElevation = (LokaleSonnendaten_Position_Elevation.state as Number).floatValue
val nAzimut = (LokaleSonnendaten_Azimut.state as Number).floatValue
var nIntens = 100
if(LokaleSonnendaten_DirekteStrahlung.state instanceof Number)
nIntens = (LokaleSonnendaten_DirekteStrahlung.state as Number).floatValue
var nCloud = 0
if(LokaleWettervorhersage_Bewolkung.state instanceof Number)
nCloud = (LokaleWettervorhersage_Bewolkung.state as Number).intValue
logInfo("shade","Elevation: Min({}) Max({}) aktuell:{}",nElevationMin,nElevationMax,nElevation)
logInfo("shade"," Azimut: Min({}) Max({}) aktuell:{}",nAzimutMin,nAzimutMax,nAzimut)
logInfo("shade","Intensity: Min({}) aktuell:{}",nIntensityMin,nIntens)
logInfo("shade"," Cloud: Max({}) aktuell:{}",nCloudynessMax,nCloud)
if(nElevation < nElevationMin || nElevation > nElevationMax || nAzimut < nAzimutMin || nAzimut > nAzimutMax || nIntens < nIntensityMin || nCloud > nCloudynessMax) {
logInfo("shade","Rolladen Büro und Kinderzimmer Beschattung aus!")
} else {
logInfo("shade","Rolladen Büro und Kinderzimmer Beschattung an!")
DGBuero.sendCommand(50)
DGKind.sendCommand(50)
}
end
Falls das immer noch zu eine Fehlermeldung führt, nehmen wir die if- Anweisung auseinander:
Code: Alles auswählen
val nElevationMin = 0 // 10
val nElevationMax = 300 // 45
val nAzimutMin = 0 // 130
val nAzimutMax = 210 // 210
val nIntensityMin = 0 // 80
val nCloudynessMax = 110 // 40
rule "Beschattung"
when
Item LokaleSonnendaten_Position_Elevation changed
then
if(!(LokaleSonnendaten_Position_Elevation.state instanceof Number)) {
logWarn("shade","Elevation ungültig! Abbruch!")
return;
}
if(!(LokaleSonnendaten_Azimut.state instanceof Number)) {
logWarn("shade","Azimut ungültig! Abbruch!")
return;
}
val nElevation = (LokaleSonnendaten_Position_Elevation.state as Number).floatValue
val nAzimut = (LokaleSonnendaten_Azimut.state as Number).floatValue
var nIntens = 100
if(LokaleSonnendaten_DirekteStrahlung.state instanceof Number)
nIntens = (LokaleSonnendaten_DirekteStrahlung.state as Number).floatValue
var nCloud = 0
if(LokaleWettervorhersage_Bewolkung.state instanceof Number)
nCloud = (LokaleWettervorhersage_Bewolkung.state as Number).intValue
logInfo("shade","Elevation: Min({}) Max({}) aktuell:{}",nElevationMin,nElevationMax,nElevation)
logInfo("shade"," Azimut: Min({}) Max({}) aktuell:{}",nAzimutMin,nAzimutMax,nAzimut)
logInfo("shade","Intensity: Min({}) aktuell:{}",nIntensityMin,nIntens)
logInfo("shade"," Cloud: Max({}) aktuell:{}",nCloudynessMax,nCloud)
var Boolean bSchatten = true
logInfo("shade","Vergleich Minimum Elevation")
if(nElevation < nElevationMin)
bSchatten = false
logInfo("shade","Vergleich Maximum Elevation")
if(nElevation > nElevationMax)
bSchatten = false
logInfo("shade","Vergleich Minimum Azimut")
if(nAzimut < nAzimutMin)
bSchatten = false
logInfo("shade","Vergleich Maximum Azimut")
if(nAzimut > nAzimutMax)
bSchatten = false
logInfo("shade","Vergleich Minimum Intensity")
if(nIntens < nIntensityMin
bSchatten = false
logInfo("shade","Vergleich Maximum Bewölkung")
if(nCloud > nCloudynessMax)
bSchatten = false
if(!bSchatten)
logInfo("shade","Rolladen Büro und Kinderzimmer Beschattung aus!")
} else {
logInfo("shade","Rolladen Büro und Kinderzimmer Beschattung an!")
DGBuero.sendCommand(50)
DGKind.sendCommand(50)
}
end
Hier geht es aber nur um die Eingrenzung des Fehlers. openHAB ist durchaus in der Lage, beliebig komplexe Bool'sche Operationen durchzuführen.
wenn der Fehler auftritt, kann man an dem vorhergehenden logeintrag ablesen, wo es geknallt hat.
openHAB4.1.2 stable in einem Debian-Container (bookworm) (Proxmox 8.1.5, LXC), mit openHABian eingerichtet