New Automation: PID Controller

Ah - OK , that will explain it then! It might be useful if there was a setting in the controller to reduce the frequency of triggers on a time basis, although maybe this would compromise the ‘purity’ of the PID controller. I can achieve a similar effect by making changes to my rules.

By the way, for a bit of background, I am using the PID controller to control battery-powered TRVs so wanted to reduce the frequency of small valve position changes to improve battery life. I’ve also been experimenting with a ‘minimum percentage change’ figure in my rules and ignoring small control output changes this way too.

Many PID controllers have a dead time, exactly as you describing. That might be a useful feature for this PID, too.

Ok, new to this PID thing…
I have a Eurotronic TRV that does not work very well (its own PID does overheat often), so I am experimenting with this automation addon.

First, thank you for providing it :slight_smile:

So I installed the addon, and created items for it.


triggers:
  - id: "1"
    configuration:
      input: gTemp_living
      setpoint: pid_LRM_step
      kp: 50
      kd: 0
      kdTimeConstant: 1
      commandItem: pid_LRM_RESET
      ki: 0.1
      loopTime: 60000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      output: pid_LRM_o
      pInspector: pid_LRM_p
      iInspector: pid_LRM_i
      dInspector: pid_LRM_d
    type: pidcontroller.action

Then I have two rules to complement the PID:


rule "PID Workaround"
when
	Item pid_LRM_o changed
then
   var Number oldValue = (trv_n2_valve_aperture.state as Number)
   var Number newValue = (pid_LRM_o.state as Number)
   if (newValue < 0) {
      newValue = 0
      pid_LRM_RESET.sendCommand("RESET")
   }
   else if (newValue > 100) newValue = 100
   else newValue = (newValue + 0.5).intValue
   if (newValue != oldValue) {
      trv_n2_valve_aperture.sendCommand(newValue)
   }
end

rule "PID Reset"
when
    Item pid_LRM_step changed
then
    // reset PID controller
    pid_LRM_RESET.sendCommand("RESET")
end

I will see overtime.

Since this heating PID is only controlling heating and not cooling, I also put in the workaround rule a test to reset the PID when the input temperature is equal or greater than the setpoint (negative PID output). If not, it builds up a negative integral value that IMO is not accurate here.

2 Likes

Yes, I had been wondering about that; as a radiator is unable to cool the room when there is an external influence heating it (e.g. it warms up outside). A large negative integral builds up which then delays the valve from opening as it should when the room cools again (e.g. when it gets colder outside).

Hello to all,

I have updated to openHAB 3.2.0.M1 and I have checked the rules, there I got the problem that the status is “uninitilized”.
There seems a problem with “pidcontroller.action”.

Does somebody have the same behaviour?

image

@Morgano @bolemo I’m able to relate concerning the negative integral part. Honestly, I’m using an old version of the PID controller where the limits on the integral part can still be applied, because I don’t know how to use the reset method in my use case (PV zero export). I then removed the limits as they seem hackish from a controlling point of view. On the other side you can achieve results fast by limiting the i-part, if you aren’t a control expert, which I guess is the majority of the users. I think I will add them again.

@Koechi The custom action module was dropped because the OH core already provides a module for that purpose. Simply add an “Item Action” instead:

See PID Controller Automation - Automation | openHAB

To configure a rule, you need to add a Trigger (“PID controller triggers”) and an Action (“Item Action”). Select the Item you like to control in the “Item Action” and leave the command empty.

@fwolter Thank you for your feedback.
I have replaced in all rules type: pidcontroller.action with core.ItemCommandAction.

Now the rule is active again.

triggers:
  - id: "1"
    configuration:
      input: KnxEGWohnzimmerIstTemp
      setpoint: KnxEGWohnzimmerSollTemp
      kp: 65
      kd: 0
      kdTimeConstant: 1
      commandItem: cInspectorLivingRoom
      ki: 0.2
      loopTime: 600000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      output: outputLivingRoom
      pInspector: pInspectorLivingRoom
      iInspector: iInspectorLivingRoom
      dInspector: dInspectorLivingRoom
      eInspector: eInspectorLivingRoom
    type: core.ItemCommandAction
1 Like

@george.erhan There’s a use case for battery powered heating valve actuators to update the output less frequently, when the setpoint is reached to save battery. Maybe there are other use cases where minor changes to the output should be avoided. Are there any PID mechanisms we can implement in this PID controller to support this use case? It seems I’m missing the correct search terms to find anything useful on this topic concerning control theory. Can you point me in the right direction?

Hi, I was just upgrading my whole solution to new instance of OH 3.1 - I saw that PID is now added to default plugin list but there seem to be changes compared to previous implementation.

It took me some time to figure it out - AFAIK:

  • output changed to itemName
  • pidcontroller.action → core.ItemCommandAction

Where there any other changes?

PS. Next time it would be nice to add it somewhere to the official documentation. Probably rule sample (as text would also be a nice starting point)

PS2. Addon is not throwing any error if items for debugging are not existing but are placed in the rule (at least I think the rule was not executed at all)

Sample:

triggers:
  - id: "1"
    configuration:
      input: Filip_Virtual_Temperature
      setpoint: Filip_Desired_SetPoint
      kp: 65
      kd: 0
      kdTimeConstant: 1
      ki: 0.1
      loopTime: 60000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      output: Filip_Desired_Dimmer
    type: pidcontroller.action

Would become

triggers:
  - id: "1"
    configuration:
      input: Filip_Virtual_Temperature
      setpoint: Filip_Desired_SetPoint
      kp: 65
      kd: 0
      kdTimeConstant: 1
      ki: 0.1
      loopTime: 60000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: Filip_Desired_Dimmer
    type: core.ItemCommandAction
1 Like

The change was done to a milestone release. It was mentioned here: New Automation: PID Controller - #91 by fwolter. Breaking changes to milestone releases are not announced separately, since it’s prototype code.

Would be awesome if you could add an example to the documentation!

I added a pull request logging an error message if an inspector Item doesn’t exist.

1 Like

Thanks I didn’t spotted it.

Regarding documentation - I’m planning to write a tutorial on how I have set up my heaters using your PID controller. I hope it would be enough documentation on possible approach. I was just surprised that my rules stopped working all of a sudden and tracking down the issue was hard as I couldn’t figure out what is wrong.

You (and possibly others) might take a look here → Set up house heating using Eurotronic Spirit actuators with PID control and "manual" control

Any suggestions are welcome.

1 Like

@fwolter
I’m having some trouble with the new version of PID controller after upgrading to openHAB Stable 3.1.0.

I have removed the 3.1.0-SNAPSHOT jar from the addons folder.

I don’t see any error messages in the log but the PID controller rule no longer responds to a ‘RESET’ command.

Here is one of my PID controller configs:

triggers:
  - id: "1"
    configuration:
      input: BedroomMultisensorSensorTemperature
      setpoint: BedroomTrvPidSetpoint
      kp: 100
      kd: 0
      kdTimeConstant: 1
      commandItem: BedroomTrvPidCommandItem
      ki: 0.5
      loopTime: 480000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      output: BedroomTrvPidValvePosition
      pInspector: BedroomTrvPidPInspectorItem
      iInspector: BedroomTrvPidIInspectorItem
      dInspector: BedroomTrvPidDInspectorItem
      eInspector: BedroomTrvPidErrorInspectorItem
    type: pidcontroller.action

My ‘Reset’ rule looks like this:

rule "Bedroom TRV PID controller reset"
when
    Item BedroomTrvPidControllerResetScene changed to ON
then
    // reset PID controller
    logInfo("Bedroom", "Manual request, resetting Bedroom TRV PID controller")
   
    BedroomTrvPidCommandItem.sendCommand("RESET")
    BedroomTrvPidCommandItem.sendCommand("")
end

When it was working before I found I had to send an empty string after the ‘RESET’ otherwise it sticks on ‘RESET’ and the PID controller cannot see the change the next time it is run.

It seems you run a pre-3.1.0 version, if your posted config is working. You are using the action type pidcontroller.action which should be core.ItemCommandAction, now. Also, the inspector items must be configured within the trigger module. Your config before the edit looked better.

The issue with the self-resetting RESET command should have been fixed in 3.1.0.

@fwolter
Thanks for the info. I think I am closer, but it is still not working.

Part of the problem is that I had renamed the prototype JAR

org.openhab.automation.pidcontroller-3.1.0-SNAPSHOT.jar

to

org.openhab.automation.pidcontroller-3.1.0-SNAPSHOT.jar.old

in my

/usr/share/openhab/addons

directory but it was still loading it. I could see this by checking in the openHAB cli:

openhab-cli console

then running

bundle:list

The old PID controller add-on was still showing at the bottom of the list:

255 ? Active ?  75 ? 3.1.0                 ? openHAB Add-ons :: Bundles :: Transformation Service :: Map
256 ? Active ?  80 ? 3.1.0                 ? openHAB UI :: Bundles :: Basic UI
257 ? Active ?  80 ? 3.1.0                 ? openHAB UI :: Bundles :: HABPanel UI
258 ? Active ?  80 ? 3.1.0                 ? openHAB UI :: Bundles :: Icon Set :: Classic
259 ? Active ?  80 ? 3.1.0.202101141550    ? openHAB Add-ons :: Bundles :: Automation :: PID Controller

So I removed the JAR completely and restarted openHAB. I also modified my PID rules as below:

triggers:
  - id: "1"
    configuration:
      setpoint: BedroomTrvPidSetpoint
      iInspector: BedroomTrvPidIInspectorItem
      kp: 100
      pInspector: BedroomTrvPidPInspectorItem
      kdTimeConstant: 1
      dInspector: BedroomTrvPidDInspectorItem
      input: BedroomMultisensorSensorTemperature
      eInspector: BedroomTrvPidErrorInspectorItem
      kd: 0
      commandItem: BedroomTrvPidCommandItem
      ki: 0.5
      loopTime: 480000
    type: pidcontroller.trigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: BedroomTrvPidValvePosition
    type: core.ItemCommandAction

I now get the following error in the Rule:

HANDLER_INITIALIZING_ERROR
Missing handler 'pidcontroller.trigger' for module '1' 

It seems that the PID Controller add-on is not installed and I couldn’t see anywhere to install it in the GUI.

I tried clearing the cache:

sudo systemctl stop openhab
sudo rm -rf /var/lib/openhab/cache/*
sudo rm -rf /var/lib/openhab/tmp/*
sudo systemctl start openhab

but this has not helped.

You can install it under Settings/Automation, click on the plus symbol:

Thanks for the tip! I installed the PID controller addon from the GUI and there are no error messages now.

I am still having an issue with the PID reset though - I am not sure if this is working correctly, or if its behaviour is different to the prototype.

I have a scene that I can trigger manually to reset the PID. This sends the RESET string to the command item:

2021-10-26 10:25:29.923 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'BedroomTrvPidCommandItem' received command RESET

2021-10-26 10:25:29.924 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'BedroomTrvPidCommandItem' changed from NULL to RESET

2021-10-26 10:25:29.925 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'BedroomTrvPidCommandItem' changed from RESET to NULL

I can see that the PID Controller has received the reset command because it gets set back to NULL immediately afterwards.

However, in the past I would expect this to set the ‘I’ value to zero and then change on the next PID trigger. I am seeing a non-zero value in the ‘I’ Inspector immediately.

Is that what you would expect now?

The integral and derivative part are internally reset to 0, but the inspector Items are only updated on the next trigger. In the meantime, the I part could be risen again. So, this should be only a cosmetic issue.

Yes, that would make sense - it does appear to be internally resetting, just the behaviour is slightly different as you say.

Can this be used using text rule (non gui)?