[openwebnet] calculate position only if startedMovingAt is valid. (#10775)
After OH reboot position remains UNDEF. Signed-off-by: Massimo Valla <mvcode00@gmail.com>
This commit is contained in:
parent
22c5e841dd
commit
7f05dbaf2c
@ -140,10 +140,10 @@ Devices support some of the following channels:
|
|||||||
For Percent commands and position feedback to work correctly, the `shutterRun` Thing config parameter must be configured equal to the time (in ms) to go from full UP to full DOWN.
|
For Percent commands and position feedback to work correctly, the `shutterRun` Thing config parameter must be configured equal to the time (in ms) to go from full UP to full DOWN.
|
||||||
It's possible to enter a value manually or set `shutterRun=AUTO` (default) to calibrate `shutterRun` automatically: in this case a *UP >> DOWN >> Position%* cycle will be performed automatically the first time a Percent command is sent to the shutter.
|
It's possible to enter a value manually or set `shutterRun=AUTO` (default) to calibrate `shutterRun` automatically: in this case a *UP >> DOWN >> Position%* cycle will be performed automatically the first time a Percent command is sent to the shutter.
|
||||||
|
|
||||||
- if `shutterRun` is not set, or is set to AUTO but calibration has not been performed yet, then position estimation will remain `UNDEFINED`
|
- if `shutterRun` is not set, or is set to `AUTO` but calibration has not been performed yet, then position estimation will remain `UNDEF` (undefined)
|
||||||
- if `shutterRun` is wrongly set higher than the actual runtime, then position estimation will remain `UNDEFINED`: try to reduce shutterRun until you find the right value
|
- if `shutterRun` is wrongly set higher than the actual runtime, then position estimation will remain `UNDEF`: try to reduce shutterRun until you find the right value
|
||||||
- before adding/configuring roller shutter Things it is suggested to have all roller shutters `UP`, otherwise the Percent command won’t work until the roller shutter is fully rolled up
|
- before adding/configuring roller shutter Things it is suggested to have all roller shutters `UP`, otherwise the Percent command won’t work until the roller shutter is fully rolled up
|
||||||
- if the gateways gets disconnected the binding cannot estimate anymore the shutter positions: just roll the shutter all `UP` or `DOWN` and its position will be estimated again
|
- if OH is restarted the binding does not know if a shutter position has changed in the meantime, so its position will be `UNDEF`. Move the shutter all `UP`/`DOWN` to synchronize again its position with the binding
|
||||||
- the shutter position is estimated based on UP/DOWN timing: an error of ±2% is normal
|
- the shutter position is estimated based on UP/DOWN timing: an error of ±2% is normal
|
||||||
|
|
||||||
## Full Example
|
## Full Example
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class OpenWebNetAutomationHandler extends OpenWebNetThingHandler {
|
|||||||
private int shutterRun = SHUTTER_RUN_UNDEFINED;
|
private int shutterRun = SHUTTER_RUN_UNDEFINED;
|
||||||
private static final String AUTO_CALIBRATION = "AUTO";
|
private static final String AUTO_CALIBRATION = "AUTO";
|
||||||
|
|
||||||
private long startedMovingAt = -1;
|
private long startedMovingAtTS = -1; // timestamp when device started moving UP/DOWN
|
||||||
private int movingState = MOVING_STATE_UNKNOWN;
|
private int movingState = MOVING_STATE_UNKNOWN;
|
||||||
private int positionEstimation = POSITION_UNKNOWN;
|
private int positionEstimation = POSITION_UNKNOWN;
|
||||||
private @Nullable ScheduledFuture<?> moveSchedule;
|
private @Nullable ScheduledFuture<?> moveSchedule;
|
||||||
@ -351,7 +351,7 @@ public class OpenWebNetAutomationHandler extends OpenWebNetThingHandler {
|
|||||||
} else if (msg.isStop()) {
|
} else if (msg.isStop()) {
|
||||||
long stoppedAt = System.currentTimeMillis();
|
long stoppedAt = System.currentTimeMillis();
|
||||||
if (calibrating == CALIBRATION_GOING_DOWN && shutterRun == SHUTTER_RUN_UNDEFINED) {
|
if (calibrating == CALIBRATION_GOING_DOWN && shutterRun == SHUTTER_RUN_UNDEFINED) {
|
||||||
shutterRun = (int) (stoppedAt - startedMovingAt);
|
shutterRun = (int) (stoppedAt - startedMovingAtTS);
|
||||||
logger.debug("& {} & CALIBRATION - reached DOWN ---> shutterRun={}", deviceWhere, shutterRun);
|
logger.debug("& {} & CALIBRATION - reached DOWN ---> shutterRun={}", deviceWhere, shutterRun);
|
||||||
updateMovingState(MOVING_STATE_STOPPED);
|
updateMovingState(MOVING_STATE_STOPPED);
|
||||||
logger.debug("& {} & CALIBRATION - COMPLETED, now going to {}%", deviceWhere, positionRequested);
|
logger.debug("& {} & CALIBRATION - COMPLETED, now going to {}%", deviceWhere, positionRequested);
|
||||||
@ -393,19 +393,19 @@ public class OpenWebNetAutomationHandler extends OpenWebNetThingHandler {
|
|||||||
private void updateMovingState(int newState) {
|
private void updateMovingState(int newState) {
|
||||||
if (movingState == MOVING_STATE_STOPPED) {
|
if (movingState == MOVING_STATE_STOPPED) {
|
||||||
if (newState != MOVING_STATE_STOPPED) { // moving after stop
|
if (newState != MOVING_STATE_STOPPED) { // moving after stop
|
||||||
startedMovingAt = System.currentTimeMillis();
|
startedMovingAtTS = System.currentTimeMillis();
|
||||||
synchronized (DATE_FORMATTER) {
|
synchronized (DATE_FORMATTER) {
|
||||||
logger.debug("# {} # MOVING {} - startedMovingAt={} - {}", deviceWhere, newState, startedMovingAt,
|
logger.debug("# {} # MOVING {} - startedMovingAt={} - {}", deviceWhere, newState, startedMovingAtTS,
|
||||||
DATE_FORMATTER.format(new Date(startedMovingAt)));
|
DATE_FORMATTER.format(new Date(startedMovingAtTS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // we were moving
|
} else { // we were moving
|
||||||
updatePosition();
|
updatePosition();
|
||||||
if (newState != MOVING_STATE_STOPPED) { // moving after moving, take new timestamp
|
if (newState != MOVING_STATE_STOPPED) { // moving after moving, take new timestamp
|
||||||
startedMovingAt = System.currentTimeMillis();
|
startedMovingAtTS = System.currentTimeMillis();
|
||||||
synchronized (DATE_FORMATTER) {
|
synchronized (DATE_FORMATTER) {
|
||||||
logger.debug("# {} # MOVING {} - startedMovingAt={} - {}", deviceWhere, newState, startedMovingAt,
|
logger.debug("# {} # MOVING {} - startedMovingAt={} - {}", deviceWhere, newState, startedMovingAtTS,
|
||||||
DATE_FORMATTER.format(new Date(startedMovingAt)));
|
DATE_FORMATTER.format(new Date(startedMovingAtTS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cancel the schedule
|
// cancel the schedule
|
||||||
@ -424,8 +424,9 @@ public class OpenWebNetAutomationHandler extends OpenWebNetThingHandler {
|
|||||||
*/
|
*/
|
||||||
private void updatePosition() {
|
private void updatePosition() {
|
||||||
int newPos = POSITION_UNKNOWN;
|
int newPos = POSITION_UNKNOWN;
|
||||||
if (shutterRun > 0) {// we have shutterRun defined, let's calculate new positionEstimation
|
if (shutterRun > 0 && startedMovingAtTS != -1) {// we have shutterRun and startedMovingAtTS defined, let's
|
||||||
long movedTime = System.currentTimeMillis() - startedMovingAt;
|
// calculate new positionEstimation
|
||||||
|
long movedTime = System.currentTimeMillis() - startedMovingAtTS;
|
||||||
logger.debug("# {} # current positionEstimation={} movedTime={}", deviceWhere, positionEstimation,
|
logger.debug("# {} # current positionEstimation={} movedTime={}", deviceWhere, positionEstimation,
|
||||||
movedTime);
|
movedTime);
|
||||||
int movedSteps = Math.round((float) movedTime / shutterRun * POSITION_MAX_STEPS);
|
int movedSteps = Math.round((float) movedTime / shutterRun * POSITION_MAX_STEPS);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user