2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.pidcontroller.internal.type;
15 import static org.openhab.automation.pidcontroller.internal.PIDControllerConstants.*;
17 import java.math.BigDecimal;
18 import java.util.ArrayList;
19 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.automation.pidcontroller.internal.handler.PIDControllerTriggerHandler;
23 import org.openhab.core.automation.Visibility;
24 import org.openhab.core.automation.type.Output;
25 import org.openhab.core.automation.type.TriggerType;
26 import org.openhab.core.config.core.ConfigDescriptionParameter;
27 import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
28 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
32 * @author Hilbrand Bouwkamp - Initial Contribution
35 public class PIDControllerTriggerType extends TriggerType {
36 private static final String DEFAULT_LOOPTIME_MS = "1000";
38 public static PIDControllerTriggerType initialize() {
39 List<ConfigDescriptionParameter> configDescriptions = new ArrayList<>();
40 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_INPUT_ITEM, Type.TEXT) //
41 .withRequired(true) //
42 .withMultiple(false) //
43 .withContext("item") //
44 .withLabel("Input Item") //
45 .withDescription("Item to monitor") //
47 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_SETPOINT_ITEM, Type.TEXT) //
48 .withRequired(true) //
49 .withMultiple(false) //
50 .withContext("item") //
51 .withLabel("Setpoint") //
52 .withDescription("Targeted setpoint") //
54 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KP_GAIN, Type.DECIMAL).withRequired(true) //
55 .withMultiple(false) //
56 .withDefault("1.0") //
57 .withMinimum(BigDecimal.ZERO) //
58 .withLabel("Proportional Gain (Kp)") //
59 .withDescription("Change to output propertional to current error value.") //
61 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KI_GAIN, Type.DECIMAL) //
62 .withRequired(true) //
63 .withMultiple(false) //
64 .withDefault("1.0") //
65 .withMinimum(BigDecimal.ZERO) //
66 .withLabel("Integral Gain (Ki)") //
67 .withDescription("Accelerate movement towards the setpoint.") //
69 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_GAIN, Type.DECIMAL) //
70 .withRequired(true) //
71 .withMultiple(false) //
72 .withDefault("1.0") //
73 .withMinimum(BigDecimal.ZERO) //
74 .withLabel("Derivative Gain (Kd)") //
75 .withDescription("Slows the rate of change of the output.") //
77 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_KD_TIMECONSTANT, Type.DECIMAL) //
78 .withRequired(true) //
79 .withMultiple(false) //
80 .withMinimum(BigDecimal.ZERO) //
81 .withDefault("1.0") //
82 .withLabel("Derivative Time Constant") //
83 .withDescription("Slows the rate of change of the D part (T1) in seconds.") //
86 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_COMMAND_ITEM, Type.TEXT) //
87 .withRequired(false) //
88 .withMultiple(false) //
89 .withContext("item") //
90 .withLabel("Command Item") //
91 .withDescription("You can send String commands to this Item like \"RESET\".") //
93 configDescriptions.add(ConfigDescriptionParameterBuilder.create(CONFIG_LOOP_TIME, Type.DECIMAL) //
94 .withRequired(true) //
95 .withMultiple(false) //
96 .withDefault(DEFAULT_LOOPTIME_MS) //
97 .withLabel("Loop Time") //
98 .withDescription("The interval the output value is updated in ms") //
101 Output output = new Output(OUTPUT, BigDecimal.class.getName(), "Output", "Output value of the PID Controller",
103 Output pInspector = new Output(P_INSPECTOR, BigDecimal.class.getName(), "P Inspector",
104 "Current P value of the pid controller", null, null, null);
105 Output iInspector = new Output(I_INSPECTOR, BigDecimal.class.getName(), "I Inspector",
106 "Current I value of the pid controller", null, null, null);
107 Output dInspector = new Output(D_INSPECTOR, BigDecimal.class.getName(), "D Inspector",
108 "Current D value of the pid controller", null, null, null);
109 Output eInspector = new Output(E_INSPECTOR, BigDecimal.class.getName(), "Error Value Inspector",
110 "Current error value of the pid controller", null, null, null);
112 List<Output> outputs = List.of(output, pInspector, iInspector, dInspector, eInspector);
114 return new PIDControllerTriggerType(configDescriptions, outputs);
117 public PIDControllerTriggerType(List<ConfigDescriptionParameter> configDescriptions, List<Output> outputs) {
118 super(PIDControllerTriggerHandler.MODULE_TYPE_ID, configDescriptions, "PID controller triggers", null, null,
119 Visibility.VISIBLE, outputs);