Simple PID Controller

A few months ago I created the Simple PID Controller, a PID control which can be fully configured from the UI!

It’s downloadable from HACS, more information here: GitHub - bvweerd/simple_pid_controller: PID Controller integration for Home Assistant

2 Likes

Hello, all PID controllers I could find for HA were not working, I ended up doing one in automation. Cool you did it, I will surely test it. Purpose is EV charger and inverter control not to blow my circuit braker, not for temperature. Thanks for this!

Good to hear! It’s definitely meant as a generic PID controller, not for temperatures specifically. Hope it works for you!

Doing a PID is easy, having it like it seems (not tested yet) is another thing. I will keep you posted. David. Where are you from?

Hello, Is your PID controller now working correctly for your car charger ?

Yes it is.
It is a drama not to find one that works

Hi, first of all I want to thank you very much for this PID controller. I have only used it for one room in the zone control of my house but it is working perfectly so far. I have one request. If it would be possible to adjust the setpoint to one tenth place? Now I can only enter the whole number 21 or 22, it would be great if I could enter 21.5
Snímka obrazovky 2025-11-17 131804


When I set 21 the window is fine but when I manually enter 21.5 there it is red

Good catch, small type in the code. fixed in v1.5.1, will be available shortly

1 Like

Hi,

thank you for your great work.
I urgently need a PID Controller, but I don’t understand how this integration works, where I have to put which information to get it up and running.
I need support.

This is my use case:

While loading my solar battery in my house I am not allowed to exceed 17kW power import from the grid.
Since I have a lot of loads switching on an off all the time, I cannot work with a static value for the charging current of my battery and could use a PID controller and set it to setpoint 16 (kW) to provide a charging power close to my limit of 17 kW, but hopefully not exceeding it.

My entity for the power import in kW from the grid is “sensor.power_import”.
That entity can vary theoretically from -10 to 30 but the negative numbers are irrelevant during the time period I am charging the battery.
During that phase the entity varies between 5-20 but I do not want to exceed 17.
I want to control the charging current of my solar battery “number.max_battery_grid_charge_current”.
The value range of that entity is 0 - 30.

How do I have to set this up?

If you could explain this to me I would be very thankful.

1. Install the Integration

First, install the Simple PID Controller in Home Assistant:

  • Go to Settings > Devices & Services
  • Click Add Integration → Search for Simple PID Controller

2. Initial Configuration

When setting up the integration, enter:

  • Name: Battery Grid Charge Controller
  • Input Sensor Entity: sensor.power_import
  • Input Range Min: -10 (your sensor’s minimum)
  • Input Range Max: 30 (your sensor’s maximum)
  • Output Range Min: 0 (minimum charging current)
  • Output Range Max: 30 (maximum charging current)

3. Configure PID Parameters

After setup, go to Settings > Devices & Services → Find your new controller → Click Configure or adjust the entities:

Critical Settings:

  • Setpoint: 16 (kW - your target grid import)
  • Kp: -2.0 (negative for inverse control)
  • Ki: -0.2 (negative for inverse control)
  • Kd: -0.5 (negative for inverse control)
  • Sample Time: 5 seconds (fast response for load changes)
  • Output Min: 0 A
  • Output Max: 30 A
  • Auto Mode: ON
  • Windup Protection: ON (prevents integral windup)

4. Why Negative Gains?

This is an inverse control problem:

  • When grid import increases (approaches 17 kW) → reduce battery charging
  • When grid import decreases (below 16 kW) → increase battery charging

Using negative Kp, Ki, and Kd inverts the controller action to achieve this behavior.

5. Create Automation to Apply Output

The PID controller creates a sensor (e.g., sensor.battery_grid_charge_controller_pid_output) that outputs the calculated charging current. You need an automation to apply this to your battery:

automation:
  - alias: "Apply PID Battery Charging Control"
    trigger:
      - platform: state
        entity_id: sensor.battery_grid_charge_controller_pid_output
    action:
      - service: number.set_value
        target:
          entity_id: number.max_battery_grid_charge_current
        data:
          value: "{{ states('sensor.battery_grid_charge_controller_pid_output') | float }}"

6. Enable Diagnostic Sensors (for tuning)

Go to Settings > Devices & Services → Your controller → Enable these sensors:

  • PID P Contribution
  • PID I Contribution
  • PID D Contribution
  • Error

These help you monitor how the controller responds to your loads.

7. Fine-Tuning

Start with the suggested values and observe:

  • If the controller is too aggressive (oscillates): Reduce the magnitude of Kp, increase Kd
  • If the controller is too slow to respond: Increase the magnitude of Kp
  • If there’s steady-state error (settles above/below 16 kW): Increase the magnitude of Ki
  • If loads change very frequently: Consider increasing Sample Time to 10-15 seconds

8. Safety Considerations

  • The controller will try to keep grid import at 16 kW, but sudden large loads may briefly exceed 17 kW
  • Consider setting Output Max to something like 28 A instead of 30 A to leave a safety margin
  • Monitor the system for a few days and adjust as needed

Expected Behavior

With this setup:

  • Grid import at 14 kW → PID increases charging current
  • Grid import at 16 kW → PID holds steady
  • Grid import at 18 kW → PID reduces charging current
  • Large sudden load (e.g., +5 kW) → PID quickly reduces battery charging to compensate
2 Likes

Absolutely awesome!

Thank you so much.
I will implement that later today, but with these detailed informations it will work for sure.

My main problem was, that I didn’t know how to set the target.
Now, with the automation, it’s crystal clear.

Thank you :pray: