30-08-2015, 21:18:20
Hallo zusammen,
für Rollershutter und Dimmer habe ich zu vollständigen Funktionalität des Webinterfaces noch zwei Rules angekündigt - hier sind sie:
Die eigentlichen Rules findet ihr weiter unten und dort müsst ihr "TestRollershutter" und "TestDimmer" durch eure Itemnamen ersetzen. Oben werden die eigentlichen Funktionen definiert. Da ich leider weder Dimmer noch Rollershutter habe, kann ich persönlich nicht testen. Falls jemand einen Fehler in den Rules findet und einen Verbesserungstipp hat - immer gerne.
Gruß
Ollie
für Rollershutter und Dimmer habe ich zu vollständigen Funktionalität des Webinterfaces noch zwei Rules angekündigt - hier sind sie:
Code:
import org.openhab.core.library.types.*
// lambda expression that can be used as a function (here: with 2 parameters)
val org.eclipse.xtext.xbase.lib.Functions$Function2 DimmerIncreaseDecreaseHandler = [
org.openhab.core.library.items.DimmerItem dimmerItem,
receivedCommand |
var currentLevel = if(dimmerItem.state==Undefined) 0 else (dimmerItem.state as DecimalType).toBigDecimal
var newLevel = currentLevel
if (receivedCommand == INCREASE) {
if (currentLevel >= 100) {
logInfo("DimmerIncreaseDecreaseHandler", "Dimmer {} already at max. Ignored {}", dimmerItem.name, receivedCommand)
newLevel = 99
} else {
newLevel = currentLevel + 5
}
} else if (receivedCommand == DECREASE) {
if (currentLevel <= 0) {
logInfo("DimmerIncreaseDecreaseHandler", "Dimmer {} already at min. Ignored {}.", dimmerItem.name, receivedCommand)
newLevel = 0
} else {
newLevel = currentLevel - 5
}
} else {
logInfo("DimmerIncreaseDecreaseHandler", "Dimmer {} Script ignoring command {}", dimmerItem.name, receivedCommand)
}
if (newLevel > 99)
newLevel = 99
else if (newLevel < 0)
newLevel = 0
if (newLevel != currentLevel) {
logInfo("DimmerIncreaseDecreaseHandler", "Dimmer {} received {}. Changed level from {} to {}.", dimmerItem.name, receivedCommand, currentLevel, newLevel)
sendCommand(dimmerItem, newLevel)
} else {
logInfo("DimmerIncreaseDecreaseHandler", "Dimmer {} received {}. Level {} unchanged, no updates required.", dimmerItem.name, receivedCommand, currentLevel)
}
]
// lambda expression that can be used as a function (here: with 2 parameters)
val org.eclipse.xtext.xbase.lib.Functions$Function2 RollershutterStopMoveHandler = [
org.openhab.core.library.items.RollershutterItem rollershutterItem,
receivedCommand |
var currentLevel = if(rollershutterItem.state==Undefined) 0 else (rollershutterItem.state as DecimalType).toBigDecimal
var newLevel = currentLevel
if (receivedCommand == MOVE) {
logInfo("RollershutterStopMoveHandler", "Rollershutter {} Script ignoring command {}", rollershutterItem.name, receivedCommand)
} else if (receivedCommand == STOP) {
logInfo("RollershutterStopMoveHandler", "Rollershutter {} stopped.", rollershutterItem.name)
newLevel = currentLevel
} else {
logInfo("RollershutterStopMoveHandler", "Rollershutter {} Script ignoring command {}", rollershutterItem.name, receivedCommand)
}
if (newLevel > 100)
newLevel = 100
else if (newLevel < 0)
newLevel = 0
if (newLevel != currentLevel) {
logInfo("RollershutterStopMoveHandler", "Rollershutter {} received {}. Changed level from {} to {}.", rollershutterItem.name, receivedCommand, currentLevel, newLevel)
sendCommand(rollershutterItem, newLevel)
} else {
logInfo("RollershutterStopMoveHandler", "Rollershutter {} received {}. Level {} unchanged, no updates required.", rollershutterItem.name, receivedCommand, currentLevel)
}
]
rule "TestDimmer Increase/Decrease control"
when
Item Light_FF_Living_Ceiling_Couch received command DECREASE or
Item Light_FF_Living_Ceiling_Couch received command INCREASE
then
DimmerIncreaseDecreaseHandler.apply(TestDimmer, receivedCommand)
end
rule "TestRollershutter Move/Stop control"
when
Item TestRollershutter received command STOP or
Item TestRollershutter received command MOVE
then
RollershutterStopMoveHandler.apply(TestRollershutter, receivedCommand)
end
Die eigentlichen Rules findet ihr weiter unten und dort müsst ihr "TestRollershutter" und "TestDimmer" durch eure Itemnamen ersetzen. Oben werden die eigentlichen Funktionen definiert. Da ich leider weder Dimmer noch Rollershutter habe, kann ich persönlich nicht testen. Falls jemand einen Fehler in den Rules findet und einen Verbesserungstipp hat - immer gerne.
Gruß
Ollie