### Trigger
-| Name | Type | Description | Required |
-|-----------------|---------|----------------------------------------------------------------------------------------------|----------|
-| `dutycycleItem` | Item | The Item (PercentType) to read the duty cycle from | Yes |
-| `interval` | Decimal | The constant interval in which the output is switch ON and OFF again in sec. | Yes |
-| `minDutyCycle` | Decimal | Any duty cycle below this value will be increased to this value | No |
-| `maxDutycycle` | Decimal | Any duty cycle above this value will be decreased to this value | No |
-| `deadManSwitch` | Decimal | The output will be switched off, when the duty cycle is not updated within this time (in ms) | No |
+| Name | Type | Description | Required |
+|----------------------|---------|----------------------------------------------------------------------------------------------|----------|
+| `dutycycleItem` | Item | The Item (PercentType) to read the duty cycle from | Yes |
+| `interval` | Decimal | The constant interval in which the output is switch ON and OFF again in sec. | Yes |
+| `minDutyCycle` | Decimal | Any duty cycle below this value will be increased to this value | No |
+| `equateMinToZero` | Boolean | True if the duty cycle below `minDutycycle` should be set to 0 (defaults to false) | No |
+| `maxDutycycle` | Decimal | Any duty cycle above this value will be increased to 100 | No |
+| `equateMaxToHundred` | Boolean | True if the duty cycle above `maxDutyCycle` should be set to 100 (defaults to true) | No |
+| `deadManSwitch` | Decimal | The output will be switched off, when the duty cycle is not updated within this time (in ms) | No |
The duty cycle can be limited via the parameters `minDutycycle` and `maxDutyCycle`.
This is helpful if you need to maintain a minimum time between the switching of the output.
public static final String CONFIG_DUTY_CYCLE_ITEM = "dutycycleItem";
public static final String CONFIG_PERIOD = "interval";
public static final String CONFIG_MIN_DUTYCYCLE = "minDutycycle";
+ public static final String CONFIG_EQUATE_MIN_TO_ZERO = "equateMinToZero";
public static final String CONFIG_MAX_DUTYCYCLE = "maxDutycycle";
+ public static final String CONFIG_EQUATE_MAX_TO_HUNDRED = "equateMaxToHundred";
public static final String CONFIG_COMMAND_ITEM = "command";
public static final String CONFIG_DEAD_MAN_SWITCH = "deadManSwitch";
public static final String CONFIG_OUTPUT_ITEM = "outputItem";
private final EventFilter eventFilter;
private final Optional<Double> minDutyCycle;
private final Optional<Double> maxDutyCycle;
+ private final boolean isEquateMinToZero;
+ private final boolean isEquateMaxToHundred;
private final Optional<Double> deadManSwitchTimeoutMs;
private final Item dutyCycleItem;
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
"DutyCycle item is not set");
minDutyCycle = getOptionalDoubleFromConfig(config, CONFIG_MIN_DUTYCYCLE);
+ isEquateMinToZero = getBooleanFromConfig(config, CONFIG_EQUATE_MIN_TO_ZERO);
maxDutyCycle = getOptionalDoubleFromConfig(config, CONFIG_MAX_DUTYCYCLE);
+ isEquateMaxToHundred = getBooleanFromConfig(config, CONFIG_EQUATE_MAX_TO_HUNDRED);
deadManSwitchTimeoutMs = getOptionalDoubleFromConfig(config, CONFIG_DEAD_MAN_SWITCH);
try {
return Optional.empty();
}
+ private boolean getBooleanFromConfig(Configuration config, String key) {
+ return ((Boolean) config.get(key)).booleanValue();
+ }
+
@Override
public void receive(Event event) {
if (!(event instanceof ItemStateEvent)) {
restartDeadManSwitchTimer();
+ // set duty cycle to 0% if it is 0% or it is smaller than min duty cycle and equateMinToZero is true
// set duty cycle to min duty cycle if it is smaller than min duty cycle
- // set duty cycle to 0% if it is 0%, regardless of the min duty cycle
final double newDutyCycleFinal1 = newDutycycle;
newDutycycle = minDutyCycle.map(minDutycycle -> {
- if (Math.round(newDutyCycleFinal1) <= 0) {
+ long dutycycleRounded1 = Math.round(newDutyCycleFinal1);
+ if (dutycycleRounded1 <= 0 || (dutycycleRounded1 <= minDutycycle && isEquateMinToZero)) {
return 0d;
} else {
return Math.max(minDutycycle, newDutyCycleFinal1);
}
}).orElse(newDutycycle);
- // set duty cycle to 100% if the current duty cycle is larger than the max duty cycle
+ // set duty cycle to 100% if it is 100% or it is larger then max duty cycle and equateMaxToHundred is
+ // true
+ // set duty cycle to max duty cycle if it is larger then max duty cycle
final double newDutyCycleFinal2 = newDutycycle;
newDutycycle = maxDutyCycle.map(maxDutycycle -> {
- if (Math.round(newDutyCycleFinal2) >= maxDutycycle) {
+ long dutycycleRounded2 = Math.round(newDutyCycleFinal2);
+ if (dutycycleRounded2 >= 100 || (dutycycleRounded2 >= maxDutycycle && isEquateMaxToHundred)) {
return 100d;
} else {
- return newDutyCycleFinal2;
+ return Math.min(maxDutycycle, newDutyCycleFinal2);
}
}).orElse(newDutycycle);
.withDefault("0") //
.withLabel("Min Dutycycle") //
.withUnit("%") //
- .withDescription("The dutycycle will be min this value").build());
+ .withDescription("The dutycycle below this value will be increased to this value").build());
+ configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MIN_TO_ZERO, Type.BOOLEAN) //
+ .withRequired(false) //
+ .withMultiple(false) //
+ .withDefault("false") //
+ .withLabel("Equate Min Dutycycle to 0") //
+ .withDescription("True if the dutycycle below Min Dutycycle should be set to 0 (defaults to false)")
+ .build());
configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_MAX_DUTYCYCLE, Type.DECIMAL) //
.withRequired(false) //
.withMultiple(false) //
.withDefault("100") //
.withUnit("%") //
.withLabel("Max Dutycycle") //
- .withDescription("The dutycycle will be max this value").build());
+ .withDescription("The dutycycle above this value will be increased to 100").build());
+ configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_EQUATE_MAX_TO_HUNDRED, Type.BOOLEAN) //
+ .withRequired(false) //
+ .withMultiple(false) //
+ .withDefault("true") //
+ .withLabel("Equate Max Dutycycle to 100") //
+ .withDescription("True if the dutycycle above Max Dutycycle should be set to 100 (defaults to true)")
+ .build());
configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_DEAD_MAN_SWITCH, Type.DECIMAL) //
.withRequired(false) //
.withMultiple(false) //