xref: /openbmc/phosphor-pid-control/configure.md (revision 608b9391cdc031a63a985375f0675621907fad04)
11dad21b9SPatrick Venture# How to Configure Phosphor-pid-control
21dad21b9SPatrick Venture
31dad21b9SPatrick VentureA system needs two groups of configurations: zones and sensors.
41dad21b9SPatrick Venture
5217a827dSPatrick WilliamsThey can come either from a dedicated config file or via D-Bus from e.g.
6217a827dSPatrick Williams`entity-manager`.
71dad21b9SPatrick Venture
8f7575a70SPaul Fertser## D-Bus Configuration
9f7575a70SPaul Fertser
10f7575a70SPaul FertserIf config file does not exist the configuration is obtained from a set of D-Bus
11f7575a70SPaul Fertserinterfaces. When using `entity-manager` to provide them refer to `Pid`,
12f7575a70SPaul Fertser`Pid.Zone` and `Stepwise`
13f7575a70SPaul Fertser[schemas](https://github.com/openbmc/entity-manager/tree/master/schemas). The
14f7575a70SPaul Fertserkey names are not identical to JSON but similar enough to see the
15f7575a70SPaul Fertsercorrespondence.
16f7575a70SPaul Fertser
17bcdeb83cSBrandon Kim## Compile Flag Configuration
18bcdeb83cSBrandon Kim
19bcdeb83cSBrandon Kim### --strict-failsafe-pwm
20bcdeb83cSBrandon Kim
21217a827dSPatrick WilliamsThis build flag is used to set the fans strictly at the failsafe percent when in
22217a827dSPatrick Williamsfailsafe mode, even when the calculated PWM is higher than failsafe PWM. Without
23217a827dSPatrick Williamsthis enabled, the PWM is calculated and set to the calculated PWM **or** the
24217a827dSPatrick Williamsfailsafe PWM, whichever is higher.
25bcdeb83cSBrandon Kim
267e63502aSPatrick Rudolph### --offline-failsafe-pwm
277e63502aSPatrick Rudolph
287e63502aSPatrick RudolphThis build flag is used to set the fans to failsafe percent when offline. The
297e63502aSPatrick Rudolphcontroller is offline when it's rebuilding the configuration or when it's about
307e63502aSPatrick Rudolphto shutdown.
317e63502aSPatrick Rudolph
32f7575a70SPaul Fertser## JSON Configuration
33f7575a70SPaul Fertser
34f7575a70SPaul FertserDefault config file path `/usr/share/swampd/config.json` can be overridden by
35f7575a70SPaul Fertserusing `--conf` command line option.
36f7575a70SPaul Fertser
37f7575a70SPaul FertserThe JSON object should be a dictionary with two keys, `sensors` and `zones`.
38ea0e6cbfSPatrick Venture`sensors` is a list of the sensor dictionaries, whereas `zones` is a list of
39ea0e6cbfSPatrick Venturezones.
40ea0e6cbfSPatrick Venture
41ea0e6cbfSPatrick Venture### Sensors
42ea0e6cbfSPatrick Venture
43*608b9391SGeorge Liu```json
441dad21b9SPatrick Venture"sensors" : [
451dad21b9SPatrick Venture    {
461dad21b9SPatrick Venture        "name": "fan1",
471dad21b9SPatrick Venture        "type": "fan",
481dad21b9SPatrick Venture        "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1",
491dad21b9SPatrick Venture        "writePath": "/sys/devices/platform/ahb/ahb:apb/1e786000.pwm-tacho-controller/hwmon/**/pwm1",
501dad21b9SPatrick Venture        "min": 0,
516b9f5999SPatrick Venture        "max": 255,
526b9f5999SPatrick Venture        "ignoreDbusMinMax": true
538f73ad76SAlex.Song        "unavailableAsFailed": true
541dad21b9SPatrick Venture    },
551dad21b9SPatrick Venture    {
561dad21b9SPatrick Venture        "name": "fan2",
571dad21b9SPatrick Venture        "type": "fan",
581dad21b9SPatrick Venture        "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan2",
591dad21b9SPatrick Venture        "writePath": "/sys/devices/platform/ahb/ahb:apb/1e786000.pwm-tacho-controller/hwmon/**/pwm2",
601dad21b9SPatrick Venture        "min": 0,
6110f42efdSPatrick Venture        "max": 255,
6210f42efdSPatrick Venture        "timeout": 4,
631dad21b9SPatrick Venture    },
64ea0e6cbfSPatrick Venture...
651dad21b9SPatrick Venture```
661dad21b9SPatrick Venture
6710f42efdSPatrick VentureA sensor has a `name`, a `type`, a `readPath`, a `writePath`, a `minimum` value,
68217a827dSPatrick Williamsa `maximum` value, a `timeout`, a `ignoreDbusMinMax` and a `unavailableAsFailed`
69217a827dSPatrick Williamsvalue.
701dad21b9SPatrick Venture
711dad21b9SPatrick VentureThe `name` is used to reference the sensor in the zone portion of the
721dad21b9SPatrick Ventureconfiguration.
731dad21b9SPatrick Venture
741dad21b9SPatrick VentureThe `type` is the type of sensor it is. This influences how its value is
75f7575a70SPaul Fertsertreated. Supported values are: `fan`, `temp`, and `margin`.
761dad21b9SPatrick Venture
771dad21b9SPatrick VentureThe `readPath` is the path that tells the daemon how to read the value from this
781dad21b9SPatrick Venturesensor. It is optional, allowing for write-only sensors. If the value is absent
791dad21b9SPatrick Ventureor `None` it'll be treated as a write-only sensor.
801dad21b9SPatrick Venture
811dad21b9SPatrick VentureIf the `readPath` value contains: `/xyz/openbmc_project/extsensors/` it'll be
821dad21b9SPatrick Venturetreated as a sensor hosted by the daemon itself whose value is provided
831dad21b9SPatrick Ventureexternally. The daemon will own the sensor and publish it to dbus. This is
841dad21b9SPatrick Venturecurrently only supported for `temp` and `margin` sensor types.
851dad21b9SPatrick Venture
861dad21b9SPatrick VentureIf the `readPath` value contains: `/xyz/openbmc_project/` (this is checked after
871dad21b9SPatrick Ventureexternal), then it's treated as a passive dbus sensor. A passive dbus sensor is
881dad21b9SPatrick Ventureone that listens for property updates to receive its value instead of actively
891dad21b9SPatrick Venturereading the `Value` property.
901dad21b9SPatrick Venture
911dad21b9SPatrick VentureIf the `readPath` value contains: `/sys/` this is treated as a directly read
921dad21b9SPatrick Venturesysfs path. There are two supported paths:
931dad21b9SPatrick Venture
94217a827dSPatrick Williams- `/sys/class/hwmon/hwmon0/pwm1`
95217a827dSPatrick Williams- `/sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk asterisk>/pwm1`
961dad21b9SPatrick Venture
971dad21b9SPatrick VentureThe `writePath` is the path to set the value for the sensor. This is only valid
981dad21b9SPatrick Venturefor a sensor of type `fan`. The path is optional. If can be empty or `None`. It
991dad21b9SPatrick Venturethen only supports two options.
1001dad21b9SPatrick Venture
1011dad21b9SPatrick VentureIf the `writePath` value contains: `/sys/` this is treated as a directory
1021dad21b9SPatrick Venturewritten sysfs path. There are two support paths:
1031dad21b9SPatrick Venture
104217a827dSPatrick Williams- `/sys/class/hwmon/hwmon0/pwm1`
105217a827dSPatrick Williams- `/sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk asterisk>/pwm1`
1061dad21b9SPatrick Venture
107217a827dSPatrick WilliamsIf the `writePath` value contains:
108217a827dSPatrick Williams`/xyz/openbmc_project/sensors/fan_tach/fan{N}` it sets of a sensor object that
109217a827dSPatrick Williamswrites over dbus to the `xyz.openbmc_project.Control.FanPwm` interface. The
110217a827dSPatrick Williams`writePath` should be the full object path.
1111dad21b9SPatrick Venture
112*608b9391SGeorge Liu```text
1131dad21b9SPatrick Venturebusctl introspect xyz.openbmc_project.Hwmon-1644477290.Hwmon1 /xyz/openbmc_project/sensors/fan_tach/fan1 --no-pager
1141dad21b9SPatrick VentureNAME                                TYPE      SIGNATURE RESULT/VALUE                             FLAGS
1151dad21b9SPatrick Ventureorg.freedesktop.DBus.Introspectable interface -         -                                        -
1161dad21b9SPatrick Venture.Introspect                         method    -         s                                        -
1171dad21b9SPatrick Ventureorg.freedesktop.DBus.Peer           interface -         -                                        -
1181dad21b9SPatrick Venture.GetMachineId                       method    -         s                                        -
1191dad21b9SPatrick Venture.Ping                               method    -         -                                        -
1201dad21b9SPatrick Ventureorg.freedesktop.DBus.Properties     interface -         -                                        -
1211dad21b9SPatrick Venture.Get                                method    ss        v                                        -
1221dad21b9SPatrick Venture.GetAll                             method    s         a{sv}                                    -
1231dad21b9SPatrick Venture.Set                                method    ssv       -                                        -
1241dad21b9SPatrick Venture.PropertiesChanged                  signal    sa{sv}as  -                                        -
1251dad21b9SPatrick Venturexyz.openbmc_project.Control.FanPwm  interface -         -                                        -
1261dad21b9SPatrick Venture.Target                             property  t         255                                      emits-change writable
1271dad21b9SPatrick Venturexyz.openbmc_project.Sensor.Value    interface -         -                                        -
1281dad21b9SPatrick Venture.MaxValue                           property  x         0                                        emits-change writable
1291dad21b9SPatrick Venture.MinValue                           property  x         0                                        emits-change writable
1301dad21b9SPatrick Venture.Scale                              property  x         0                                        emits-change writable
1311dad21b9SPatrick Venture.Unit                               property  s         "xyz.openbmc_project.Sensor.Value.Uni... emits-change writable
1321dad21b9SPatrick Venture.Value                              property  x         2823                                     emits-change writable
1331dad21b9SPatrick Venture```
1341dad21b9SPatrick Venture
1351dad21b9SPatrick VentureThe `minimum` and `maximum` values are optional. When `maximum` is non-zero it
1361dad21b9SPatrick Ventureexpects to write a percentage value converted to a value between the minimum and
1371dad21b9SPatrick Venturemaximum.
138ea0e6cbfSPatrick Venture
13910f42efdSPatrick VentureThe `timeout` value is optional and controls the sensor failure behavior. If a
14010f42efdSPatrick Venturesensor is a fan the default value is 2 seconds, otherwise it's 0. When a
14110f42efdSPatrick Venturesensor's timeout is 0 it isn't checked against a read timeout failure case. If a
14210f42efdSPatrick Venturesensor fails to be read within the timeout period, the zone goes into failsafe
14310f42efdSPatrick Ventureto handle the case where it doesn't know what to do -- as it doesn't have all
14410f42efdSPatrick Ventureits inputs.
14510f42efdSPatrick Venture
146217a827dSPatrick WilliamsThe `ignoreDbusMinMax` value is optional and defaults to false. The dbus passive
147217a827dSPatrick Williamssensors check for a `MinValue` and `MaxValue` and scale the incoming values via
148217a827dSPatrick Williamsthese. Setting this property to true will ignore `MinValue` and `MaxValue` from
149217a827dSPatrick Williamsdbus and therefore won't call any passive value scaling.
1506b9f5999SPatrick Venture
151217a827dSPatrick WilliamsThe `unavailableAsFailed` value is optional and defaults to true. However, some
152217a827dSPatrick Williamsspecific thermal sensors should not be treated as Failed when they are
153217a827dSPatrick Williamsunavailable. For example, when a system is powered-off, its CPU/DIMM Temp
154217a827dSPatrick Williamssensors are unavailable, in such state these sensors should not be treated as
155217a827dSPatrick WilliamsFailed and trigger FailSafe. This is important for systems whose Fans are always
156217a827dSPatrick Williamson. For these specific sensors set this property to false.
1578f73ad76SAlex.Song
158ea0e6cbfSPatrick Venture### Zones
159ea0e6cbfSPatrick Venture
160*608b9391SGeorge Liu```json
161ea0e6cbfSPatrick Venture"zones" : [
162ea0e6cbfSPatrick Venture        {
163ea0e6cbfSPatrick Venture            "id": 1,
164ea0e6cbfSPatrick Venture            "minThermalOutput": 3000.0,
165ea0e6cbfSPatrick Venture            "failsafePercent": 75.0,
166ea0e6cbfSPatrick Venture            "pids": [],
167ea0e6cbfSPatrick Venture...
168ea0e6cbfSPatrick Venture```
169ea0e6cbfSPatrick Venture
170f7575a70SPaul FertserEach zone has its own fields, and a list of controllers.
171ea0e6cbfSPatrick Venture
172ea0e6cbfSPatrick Venture| field              | type              | meaning                                                                                                                         |
173217a827dSPatrick Williams| ------------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------- |
174ea0e6cbfSPatrick Venture| `id`               | `int64_t`         | This is a unique identifier for the zone.                                                                                       |
175e7f4a5d5SPatrick Venture| `minThermalOutput` | `double`          | This is the minimum value that should be considered from the thermal outputs. Commonly used as the minimum fan RPM.             |
176e7f4a5d5SPatrick Venture| `failsafePercent`  | `double`          | If there is a fan PID, it will use this value if the zone goes into fail-safe as the output value written to the fan's sensors. |
177f7575a70SPaul Fertser| `pids`             | `list of strings` | Fan and thermal controllers used by the zone.                                                                                   |
178ea0e6cbfSPatrick Venture
179ea0e6cbfSPatrick VentureThe `id` field here is used in the d-bus path to talk to the
180ea0e6cbfSPatrick Venture`xyz.openbmc_project.Control.Mode` interface.
181ea0e6cbfSPatrick Venture
182217a827dSPatrick Williams**_TODO:_** Examine how the fan controller always treating its output as a
183ea0e6cbfSPatrick Venturepercentage works for future cases.
184ea0e6cbfSPatrick Venture
185217a827dSPatrick WilliamsA zone collects all the setpoints and ceilings from the thermal controllers
186217a827dSPatrick Williamsattached to it, selects the maximum setpoint, clamps it by the minimum ceiling
187217a827dSPatrick Williamsand `minThermalOutput`; the result is used to control fans.
188ea0e6cbfSPatrick Venture
189f7575a70SPaul Fertser### Controllers
190ea0e6cbfSPatrick Venture
191f7575a70SPaul FertserThere are `fan`, `temp`, `margin` (PID), and `stepwise` (discrete steps)
192f7575a70SPaul Fertsercontrollers.
193ea0e6cbfSPatrick Venture
194217a827dSPatrick WilliamsThe `fan` PID is meant to drive fans or other cooling devices. It's expecting to
195217a827dSPatrick Williamsget the setpoint value from the owning zone and then drive the fans to that
196217a827dSPatrick Williamsvalue.
197ea0e6cbfSPatrick Venture
198217a827dSPatrick WilliamsA `temp` PID is meant to drive the setpoint given an absolute temperature value
199217a827dSPatrick Williams(higher value indicates warmer temperature).
200f7575a70SPaul Fertser
201217a827dSPatrick WilliamsA `margin` PID is meant to drive the setpoint given a margin value (lower value
202217a827dSPatrick Williamsindicates warmer temperature, in other words, it's the safety margin remaining
203217a827dSPatrick Williamsexpressed in degrees Celsius).
204ea0e6cbfSPatrick Venture
205ea0e6cbfSPatrick VentureThe setpoint output from the thermal controllers is called `RPMSetpoint()`
206ea0e6cbfSPatrick VentureHowever, it doesn't need to be an RPM value.
207ea0e6cbfSPatrick Venture
208217a827dSPatrick Williams**_TODO:_** Rename this method and others to not say necessarily RPM.
209ea0e6cbfSPatrick Venture
210ea0e6cbfSPatrick VentureSome PID configurations have fields in common, but may be interpreted
211ea0e6cbfSPatrick Venturedifferently.
212ea0e6cbfSPatrick Venture
213f7575a70SPaul FertserWhen using D-Bus, each configuration can have a list of strings called
214217a827dSPatrick Williams`Profiles`. In this case the controller will be loaded only if at least one of
215217a827dSPatrick Williamsthem is returned as `Current` from an object implementing
216217a827dSPatrick Williams`xyz.openbmc_project.Control.ThermalMode` interface (which can be anywhere on
217217a827dSPatrick WilliamsD-Bus). `swampd` will automatically reload full configuration whenever `Current`
218217a827dSPatrick Williamsis changed.
219f7575a70SPaul Fertser
220217a827dSPatrick WilliamsD-Bus `Name` attribute is used for indexing in certain cases so should be unique
221217a827dSPatrick Williamsfor all defined configurations.
222f7575a70SPaul Fertser
223ea0e6cbfSPatrick Venture#### PID Field
224ea0e6cbfSPatrick Venture
225ea0e6cbfSPatrick VentureIf the PID `type` is not `stepwise` then the PID field is defined as follows:
226ea0e6cbfSPatrick Venture
227ea0e6cbfSPatrick Venture| field                | type     | meaning                                                                  |
228217a827dSPatrick Williams| -------------------- | -------- | ------------------------------------------------------------------------ |
229e7f4a5d5SPatrick Venture| `samplePeriod`       | `double` | How frequently the value is sampled. 0.1 for fans, 1.0 for temperatures. |
230ea0e6cbfSPatrick Venture| `proportionalCoeff`  | `double` | The proportional coefficient.                                            |
231ea0e6cbfSPatrick Venture| `integralCoeff`      | `double` | The integral coefficient.                                                |
232ea0e6cbfSPatrick Venture| `feedFwdOffsetCoeff` | `double` | The feed forward offset coefficient.                                     |
233ea0e6cbfSPatrick Venture| `feedFwdGainCoeff`   | `double` | The feed forward gain coefficient.                                       |
234ea0e6cbfSPatrick Venture| `integralLimit_min`  | `double` | The integral minimum clamp value.                                        |
235ea0e6cbfSPatrick Venture| `integralLimit_max`  | `double` | The integral maximum clamp value.                                        |
236ea0e6cbfSPatrick Venture| `outLim_min`         | `double` | The output minimum clamp value.                                          |
237ea0e6cbfSPatrick Venture| `outLim_max`         | `double` | The output maximum clamp value.                                          |
238ea0e6cbfSPatrick Venture| `slewNeg`            | `double` | Negative slew value to dampen output.                                    |
239ea0e6cbfSPatrick Venture| `slewPos`            | `double` | Positive slew value to accelerate output.                                |
240ea0e6cbfSPatrick Venture
241ea0e6cbfSPatrick VentureThe units for the coefficients depend on the configuration of the PIDs.
242ea0e6cbfSPatrick Venture
243ea0e6cbfSPatrick VentureIf the PID is a `margin` controller and its `setpoint` is in centigrade and
244ea0e6cbfSPatrick Ventureoutput in RPM: proportionalCoeff is your p value in units: RPM/C and integral
245ea0e6cbfSPatrick Venturecoefficient: RPM/C sec
246ea0e6cbfSPatrick Venture
247ea0e6cbfSPatrick VentureIf the PID is a fan controller whose output is pwm: proportionalCoeff is %/RPM
248ea0e6cbfSPatrick Ventureand integralCoeff is %/RPM sec.
249ea0e6cbfSPatrick Venture
250217a827dSPatrick Williams**_NOTE:_** The sample periods are specified in the configuration as they are
251ea0e6cbfSPatrick Ventureused in the PID computations, however, they are not truly configurable as they
252ea0e6cbfSPatrick Ventureare used for the update periods for the fan and thermal sensors.
253ea0e6cbfSPatrick Venture
254ea0e6cbfSPatrick Venture#### type == "fan"
255ea0e6cbfSPatrick Venture
256*608b9391SGeorge Liu```json
257*608b9391SGeorge Liu{
258ea0e6cbfSPatrick Venture  "name": "fan1-5",
259ea0e6cbfSPatrick Venture  "type": "fan",
260ea0e6cbfSPatrick Venture  "inputs": ["fan1", "fan5"],
261ea0e6cbfSPatrick Venture  "setpoint": 90.0,
262ea0e6cbfSPatrick Venture  "pid": {
263ea0e6cbfSPatrick Venture  ...
264ea0e6cbfSPatrick Venture  }
265*608b9391SGeorge Liu}
266ea0e6cbfSPatrick Venture```
267ea0e6cbfSPatrick Venture
268ea0e6cbfSPatrick VentureThe type `fan` builds a `FanController` PID.
269ea0e6cbfSPatrick Venture
270ea0e6cbfSPatrick Venture| field      | type              | meaning                                                                        |
271217a827dSPatrick Williams| ---------- | ----------------- | ------------------------------------------------------------------------------ |
272e7f4a5d5SPatrick Venture| `name`     | `string`          | The name of the PID. This is just for humans and logging.                      |
273ea0e6cbfSPatrick Venture| `type`     | `string`          | `fan`                                                                          |
274e7f4a5d5SPatrick Venture| `inputs`   | `list of strings` | The names of the sensor(s) that are used as input and output for the PID loop. |
275ea0e6cbfSPatrick Venture| `setpoint` | `double`          | Presently UNUSED                                                               |
276ea0e6cbfSPatrick Venture| `pid`      | `dictionary`      | A PID dictionary detailed above.                                               |
277ea0e6cbfSPatrick Venture
278ea0e6cbfSPatrick Venture#### type == "margin"
279ea0e6cbfSPatrick Venture
280*608b9391SGeorge Liu```json
281*608b9391SGeorge Liu{
282ea0e6cbfSPatrick Venture  "name": "fleetingpid0",
283ea0e6cbfSPatrick Venture  "type": "margin",
284ea0e6cbfSPatrick Venture  "inputs": ["fleeting0"],
285ea0e6cbfSPatrick Venture  "setpoint": 10,
286ea0e6cbfSPatrick Venture  "pid": {
287ea0e6cbfSPatrick Venture  ...
288ea0e6cbfSPatrick Venture  }
289*608b9391SGeorge Liu}
290ea0e6cbfSPatrick Venture```
291ea0e6cbfSPatrick Venture
292ea0e6cbfSPatrick VentureThe type `margin` builds a `ThermalController` PID.
293ea0e6cbfSPatrick Venture
294ea0e6cbfSPatrick Venture| field      | type              | meaning                                                                      |
295217a827dSPatrick Williams| ---------- | ----------------- | ---------------------------------------------------------------------------- |
296e7f4a5d5SPatrick Venture| `name`     | `string`          | The name of the PID. This is just for humans and logging.                    |
297ea0e6cbfSPatrick Venture| `type`     | `string`          | `margin`                                                                     |
298e7f4a5d5SPatrick Venture| `inputs`   | `list of strings` | The names of the sensor(s) that are used as input for the PID loop.          |
299e7f4a5d5SPatrick Venture| `setpoint` | `double`          | The setpoint value for the thermal PID. The setpoint for the margin sensors. |
300ea0e6cbfSPatrick Venture| `pid`      | `dictionary`      | A PID dictionary detailed above.                                             |
301ea0e6cbfSPatrick Venture
302217a827dSPatrick WilliamsEach input is normally a temperature difference between some hardware threshold
303217a827dSPatrick Williamsand the current state. E.g. a CPU sensor can be reporting that it's 20 degrees
304217a827dSPatrick Williamsbelow the point when it starts thermal throttling. So the lower the margin
305217a827dSPatrick Williamstemperature, the higher the corresponding absolute value.
306f7575a70SPaul Fertser
307217a827dSPatrick WilliamsOut of all the `inputs` the minimal value is selected and used as an input for
308217a827dSPatrick Williamsthe PID loop.
309f7575a70SPaul Fertser
310ea0e6cbfSPatrick VentureThe output of a `margin` PID loop is that it sets the setpoint value for the
311ea0e6cbfSPatrick Venturezone. It does this by adding the value to a list of values. The value chosen by
312ea0e6cbfSPatrick Venturethe fan PIDs (in this cascade configuration) is the maximum value.
313ea0e6cbfSPatrick Venture
314f7575a70SPaul Fertser#### type == "temp"
315f7575a70SPaul Fertser
316217a827dSPatrick WilliamsExactly the same as `margin` but all the inputs are supposed to be absolute
317217a827dSPatrick Williamstemperatures and so the maximal value is used to feed the PID loop.
318f7575a70SPaul Fertser
319ea0e6cbfSPatrick Venture#### type == "stepwise"
320217a827dSPatrick Williams
321*608b9391SGeorge Liu```json
322*608b9391SGeorge Liu{
323903a9687SPaul Fertser  "name": "temp1",
324903a9687SPaul Fertser  "type": "stepwise",
325903a9687SPaul Fertser  "inputs": ["temp1"],
326903a9687SPaul Fertser  "setpoint": 30.0,
327903a9687SPaul Fertser  "pid": {
328903a9687SPaul Fertser    "samplePeriod": 0.1,
329903a9687SPaul Fertser    "positiveHysteresis": 1.0,
330903a9687SPaul Fertser    "negativeHysteresis": 1.0,
331903a9687SPaul Fertser    "isCeiling": false,
332903a9687SPaul Fertser    "reading": {
333903a9687SPaul Fertser      "0": 45,
334903a9687SPaul Fertser      "1": 46,
335*608b9391SGeorge Liu      "2": 47
336903a9687SPaul Fertser    },
337903a9687SPaul Fertser    "output": {
338903a9687SPaul Fertser      "0": 5000,
339903a9687SPaul Fertser      "1": 2400,
340*608b9391SGeorge Liu      "2": 2600
341*608b9391SGeorge Liu    }
342903a9687SPaul Fertser  }
343903a9687SPaul Fertser}
344903a9687SPaul Fertser```
345ea0e6cbfSPatrick Venture
346903a9687SPaul FertserThe type `stepwise` builds a `StepwiseController`.
347903a9687SPaul Fertser
348903a9687SPaul Fertser| field    | type              | meaning                                                                          |
349217a827dSPatrick Williams| -------- | ----------------- | -------------------------------------------------------------------------------- |
350903a9687SPaul Fertser| `name`   | `string`          | The name of the controller. This is just for humans and logging.                 |
351903a9687SPaul Fertser| `type`   | `string`          | `stepwise`                                                                       |
352903a9687SPaul Fertser| `inputs` | `list of strings` | The names of the sensor(s) that are used as input and output for the controller. |
353903a9687SPaul Fertser| `pid`    | `dictionary`      | A controller settings dictionary detailed below.                                 |
354903a9687SPaul Fertser
355903a9687SPaul FertserThe `pid` dictionary (confusingly named) is defined as follows:
356903a9687SPaul Fertser
357903a9687SPaul Fertser| field                | type         | meaning                                                                                              |
358217a827dSPatrick Williams| -------------------- | ------------ | ---------------------------------------------------------------------------------------------------- |
359903a9687SPaul Fertser| `samplePeriod`       | `double`     | Presently UNUSED.                                                                                    |
360903a9687SPaul Fertser| `reading`            | `dictionary` | Enumerated list of input values, indexed from 0, must be monotonically increasing, maximum 20 items. |
361903a9687SPaul Fertser| `output`             | `dictionary` | Enumerated list of output values, indexed from 0, must match the amount of `reading` items.          |
362903a9687SPaul Fertser| `positiveHysteresis` | `double`     | How much the input value must raise to allow the switch to the next step.                            |
363903a9687SPaul Fertser| `negativeHysteresis` | `double`     | How much the input value must drop to allow the switch to the previous step.                         |
364903a9687SPaul Fertser| `isCeiling`          | `bool`       | Whether this controller provides a setpoint or a ceiling for the zone                                |
365903a9687SPaul Fertser| `setpoint`           | `double`     | Presently UNUSED.                                                                                    |
366903a9687SPaul Fertser
367217a827dSPatrick Williams**_NOTE:_** `reading` and `output` are normal arrays and not embedded in the
368217a827dSPatrick Williamsdictionary in Entity Manager.
369903a9687SPaul Fertser
370217a827dSPatrick WilliamsEach measurement cycle out of all the `inputs` the maximum value is selected.
371217a827dSPatrick WilliamsThen it's compared to the list of `reading` values finding the largest that's
372217a827dSPatrick Williamsstill lower or equal the input (the very first item is used even if it's larger
373217a827dSPatrick Williamsthan the input). The corresponding `output` value is selected if hysteresis
374217a827dSPatrick Williamsallows the switch (the current input value is compared with the input present at
375217a827dSPatrick Williamsthe moment of the previous switch). The result is added to the list of setpoints
376903a9687SPaul Fertseror ceilings for the zone depending on `isCeiling` setting.
377