I have a physical switch with four buttons and the following (shortened for here) rule:
switch(button) {
case "top-right":
items.getItem("RollerShutter").sendCommand("UP");
break;
case "bottom-right":
items.getItem("RollerShutter").sendCommand("DOWN");
break;
default:
console.error("Invalid button: ${button}")
}
When a button has been pressed the rule runs and the roller shutter moves up or down. I’d like to stop the roller shutter when pressing the up button while it moves up. How can I detect if the roller shutter is currently moving?
The state if the roller shutter is a number: 0 for up, 100 for down and other numbers for in between. According to Items | openHAB rollershutter items also can have the “StopMove” state, but how do I get it?
The Items cannot have a StopMove state. You can send a StopMovecommand to it but the Rollershutter’s state is always going to be a PercentType. It’s the same as sending an OFF command to a Dimmer Item. It’s state won’t ever be OFF.
The only approach I can think of is going to be a little brittle. Assuming that this button is the only way that the rollershutter is controlled, you can keep track of the last button pressed. Then, if the same button is pressed again, send the StopMove command instead of UP or DOWN. If StopMove was sent, clear the last button presses so pressing “top-right” a third time will send the rollershutter moving again.
It might get more complicated if more than one button can send the shutter up or down and even more complicated if the same button can send the rollershutter up or down. But I think it’s still possible even in these cases. You’ll just need to build a state machine.
If for some reason you don’t want to send the StopMove command if the rollershutter isn’t actually moving, you’ll have to know how long the rollershutter takes to move from fully open to fully closed and if the last button is the same and was pressed less than that amount of time assume that the rollershutter is moving.
Unfortunately, unless there is a Channel on the Thing that tells you, there is no good way to know whether the rollershutter is moving at any given time.
If it is still relevant…My approach is to track the current power usage, together with button presses and/or scheduled or automatic commands keeping track of a virtual state with possible values: Moving up, moving down, stopped up, stopped down, stopped undefined. It is not perfect as there is a slight delay in the power usage.