New Automation: PID Controller

I don’t think it’s possible to write a rule as DSL rule. It would require some additional coding I think.

It’s possible to create a rule with jsr223. Here is an example in JavaScript. It’s without any additional libraries. With some additional libraries it can be written more condense:

I put in some random numbers.

'use strict';

scriptExtension.importPreset("RuleSupport");
scriptExtension.importPreset("RuleSimple");

var sRule = new SimpleRule() {
    execute: function(module, input) {
      print("input:" + input); // input contains all the output values
    }
};

sRule.setName("My PID Rule");
sRule.setTriggers([
    TriggerBuilder.create()
        .withId("my_pid_trigger")
        .withLabel("My PID Trigger")
        .withTypeUID("pidcontroller.trigger")
        .withConfiguration(
            new Configuration({
                "input": "input_item",   // input item name
                "setpoint": "setpoint_item", // setpoint item name
                "integralLowerLimit": 0.0,
                "integralUpperLimit": 10.0,
                "loopTime": 1000,
                "kp": 0.4,
                "ki": 1.0,
                "kd": 1.0,
                "kdTimeConstant": 1.0
            })).build()
    ]);
automationManager.addRule(sRule);

There is also an Action pidcontroller.action that can be used to put the output in items. But it looks like this action isn’t implemented correctly. I remember initially not fully understanding how it should work. It only seems to work if your pid trigger has id 1.

Edit: updated renamed integralLowerLimit and integralUpperLimit.