Need helb by PID-Climate Controller

Hello,

I’m looking for a way to control a diesel heater via ESP (ESPhome) to maintain the heater’s output as consistently as possible, ensuring the target temperature is maintained without the unit constantly switching up, down, on, or off.

The unit has 10 power levels (from 1 to 10).

1 = lowest fuel consumption and lowest fan speed of the heat exchanger.

10 = highest output.

I can control the diesel heater using various remote control codes:
Off
On
Plus
%
Minus

Climate & Bang-Bang

Initially, I considered the Bang-Bang Climate component.

However, this would require me to write all the logic for stabilizing the power levels myself.

Then I came across the Climate PID component.

I believe and hope that the PID controller handles this logic.

I’m still at the very beginning and don’t fully understand the logic yet.

Climate & Bang-Bang

At first, I considered the Bang-Bang Climate component.

However, I would have to write all the logic for stabilizing the power levels myself.

Then I came across the Climate PID component.

I believe and hope that the PID controller handles this logic.

I’m still at the very beginning and don’t fully understand the logic yet.

Here is my code ===>

# Example configuration entry
climate:
  - platform: pid
    name: "PID Climate Controller"
    sensor: TEMP_DHT_1
    default_target_temperature: 21°C
    heat_output: pidHeaterOutputOn
    control_parameters:
      kp: 0.49460
      ki: 0.00487
      kd: 12.56301
      output_averaging_samples: 5      # smooth the output over 5 samples
      derivative_averaging_samples: 5  # smooth the derivative value over 10 samples
    deadband_parameters:
      threshold_high: 0.5°C       # deadband within +/-0.5°C of target_temperature
      threshold_low: -0.5°C

output:
  - platform: template
    id: pidHeaterOutputOn
    type: float
    min_power: 0.01
    max_power: 1.00
    write_action:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '000111000xxxxxxxxxxxxxxx10110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: Heizung AN 11111!

Here is the part of the manual option to control the heating.

button:
  - platform: template
    name: Heizung An
    id: heaterOn
    on_press:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '00011100xxxxxxxxxxxxxxxxx110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: Heizung ANgeschaltet!
      #- climate.control:
      #    id: my_climate
      #    mode: "HEAT"
  - platform: template
    name: Heizung Aus
    id: heaterOff
    on_press:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '000111xxxxxxxxxxxxxxxxxx0001000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: Heizung AUSgeschaltet!
      #- climate.control:
       #   id: my_climate
          #mode: "OFF"
  - platform: template
    name: Heizleistung Plus
    id: heaterPlus
    on_press:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '000111xxxxxxxxxxxxxxxxx10000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
  - platform: template
    name: Heizleistung Minus
    id: heaterMinus
    on_press:
      #- script.call: heizleistung_1
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '00011xxxxxxxxxxxxxxxxxxxx001000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s

However, if I change the target temperature, the output remains in idle mode.

(See image)

It should normally switch to heating mode.

The example where the
output:

is called initially only shows one signal that the transmitter should send.
In the end, there will be four signals: On, Off, Plus, and Minus.

I suspect that the PID controller has or needs to send some information so that the output knows what to do… should it go to the Plus or Minus branch, or directly to the Off or On branch?

Or have I misunderstood the PID controller and its function?

The screenshots are shown in the images. When the target temperature is changed, the mode doesn’t change; it always remains in idle mode.
However, the output is being accessed.

I suspect I need to intercept some value that the PID controller sends.

many thank’s for any help


i add now a new section of code

#### Test PID Climate 
# Example configuration entry
climate:
  - platform: pid
    name: "PID Climate Controller"
    sensor: TEMP_DHT_1
    default_target_temperature: 21°C
    heat_output: pidHeaterOutputHeat
    cool_output: pidHeaterOutputCool
    control_parameters:
      kp: 0.49460
      ki: 0.00487
      kd: 12.56301
      output_averaging_samples: 5      # smooth the output over 5 samples
      derivative_averaging_samples: 5  # smooth the derivative value over 10 samples
    deadband_parameters:
      threshold_high: 0.5°C       # deadband within +/-0.5°C of target_temperature
      threshold_low: -0.5°C

output:
  - platform: template
    id: pidHeaterOutputHeat
    type: float
    min_power: 0.01
    max_power: 1.00
    write_action:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '00011100xxxxxxxxxxxxxxxxx10110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: Heizung ==> heat plus!
  - platform: template
    id: pidHeaterOutputCool
    type: float
    min_power: 0.01
    max_power: 1.00
    write_action:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '0001110xxxxxxxxxxxxxxxxxx110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: Heizung ==> cool MINUS!


  - platform: pid
    name: "PID Climate Result"
    type: RESULT
  - platform: pid
    name: "PID Climate Cool"
    type: Cool
  - platform: pid
    name: "PID Climate HEAT"
    type: HEAT

I then manipulated the temperature reading on the DHT sensor to see what would happen.

It now switches to heating mode and cooling mode when the target temperature is undershot or exceeded.
That’s a step in the right direction.

How can I now transmit the values ​​so that it adjusts the heating output within a range of 1-10 as needed?

It should look something like this: Target temperature = undershot = increase heating output by 1
Target temperature = exceeded = decrease heating output by 1

Later, I could store the current heating output in a global variable, and when it reaches 1 or 10, it would no longer need to increase or decrease the output.

and that’s the result===>

[19:21:57.835][D][climate:404]:   Action: COOLING
[19:21:57.839][D][climate:422]:   Current Temperature: 29.10°C
[19:21:57.850][D][climate:428]:   Target Temperature: 25.50°C
[19:21:57.865][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 89.60000 % with 1 decimals of accuracy
[19:21:57.900][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:22:57.410][D][dht:042]: Temperature 29.9°C Humidity 87.0%
[19:22:57.414][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 29.90000 °C with 1 decimals of accuracy
[19:22:57.625][D][main:537]: Heizung ==> heat plus!
[19:22:57.837][D][main:589]: Heizung ==> cool MINUS!
[19:22:57.840][D][sensor:131]: 'PID Climate Result': Sending state -217.96112 % with 1 decimals of accuracy
[19:22:57.848][D][sensor:131]: 'PID Climate Cool': Sending state 100.00000 % with 1 decimals of accuracy
[19:22:57.856][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:22:57.865][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:22:57.868][D][climate:402]:   Mode: HEAT_COOL
[19:22:57.871][D][climate:404]:   Action: COOLING
[19:22:57.877][D][climate:422]:   Current Temperature: 29.90°C
[19:22:57.885][D][climate:428]:   Target Temperature: 25.50°C
[19:22:57.901][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 87.00000 % with 1 decimals of accuracy
[19:22:57.930][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:23:57.436][D][dht:042]: Temperature 29.3°C Humidity 45.5%
[19:23:57.441][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 29.30000 °C with 1 decimals of accuracy
[19:23:57.655][D][main:537]: Heizung ==> heat plus!
[19:23:57.866][D][main:589]: Heizung ==> cool MINUS!
[19:23:57.869][D][sensor:131]: 'PID Climate Result': Sending state -235.86096 % with 1 decimals of accuracy
[19:23:57.877][D][sensor:131]: 'PID Climate Cool': Sending state 100.00000 % with 1 decimals of accuracy
[19:23:57.885][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:23:57.892][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:23:57.897][D][climate:402]:   Mode: HEAT_COOL
[19:23:57.901][D][climate:404]:   Action: COOLING
[19:23:57.907][D][climate:422]:   Current Temperature: 29.30°C
[19:23:57.914][D][climate:428]:   Target Temperature: 25.50°C
[19:23:57.934][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 45.50000 % with 1 decimals of accuracy
[19:23:57.964][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:24:57.461][D][dht:042]: Temperature 27.9°C Humidity 45.3%
[19:24:57.464][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 27.90000 °C with 1 decimals of accuracy
[19:24:57.677][D][main:537]: Heizung ==> heat plus!
[19:24:57.888][D][main:589]: Heizung ==> cool MINUS!
[19:24:57.890][D][sensor:131]: 'PID Climate Result': Sending state -229.82077 % with 1 decimals of accuracy
[19:24:57.902][D][sensor:131]: 'PID Climate Cool': Sending state 100.00000 % with 1 decimals of accuracy
[19:24:57.911][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:24:57.919][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:24:57.922][D][climate:402]:   Mode: HEAT_COOL
[19:24:57.928][D][climate:404]:   Action: COOLING
[19:24:57.932][D][climate:422]:   Current Temperature: 27.90°C
[19:24:57.945][D][climate:428]:   Target Temperature: 25.50°C
[19:24:57.958][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 45.30000 % with 1 decimals of accuracy
[19:24:57.984][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:25:57.442][D][dht:042]: Temperature 26.7°C Humidity 46.5%
[19:25:57.448][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 26.70000 °C with 1 decimals of accuracy
[19:25:57.662][D][main:537]: Heizung ==> heat plus!
[19:25:57.872][D][main:589]: Heizung ==> cool MINUS!
[19:25:57.875][D][sensor:131]: 'PID Climate Result': Sending state -240.72444 % with 1 decimals of accuracy
[19:25:57.883][D][sensor:131]: 'PID Climate Cool': Sending state 100.00000 % with 1 decimals of accuracy
[19:25:57.892][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:25:57.899][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:25:57.904][D][climate:402]:   Mode: HEAT_COOL
[19:25:57.908][D][climate:404]:   Action: COOLING
[19:25:57.913][D][climate:422]:   Current Temperature: 26.70°C
[19:25:57.921][D][climate:428]:   Target Temperature: 25.50°C
[19:25:57.937][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 46.50000 % with 1 decimals of accuracy
[19:25:57.963][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:26:57.449][D][dht:042]: Temperature 25.9°C Humidity 47.4%
[19:26:57.451][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 25.90000 °C with 1 decimals of accuracy
[19:26:57.666][D][main:537]: Heizung ==> heat plus!
[19:26:57.874][D][main:589]: Heizung ==> cool MINUS!
[19:26:57.875][D][sensor:131]: 'PID Climate Result': Sending state -101.97839 % with 1 decimals of accuracy
[19:26:57.886][D][sensor:131]: 'PID Climate Cool': Sending state 100.00000 % with 1 decimals of accuracy
[19:26:57.894][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:26:57.902][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:26:57.906][D][climate:402]:   Mode: HEAT_COOL
[19:26:57.911][D][climate:404]:   Action: COOLING
[19:26:57.919][D][climate:422]:   Current Temperature: 25.90°C
[19:26:57.925][D][climate:428]:   Target Temperature: 25.50°C
[19:26:57.941][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 47.40000 % with 1 decimals of accuracy
[19:26:57.969][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:27:57.544][D][dht:042]: Temperature 25.3°C Humidity 48.3%
[19:27:57.547][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 25.30000 °C with 1 decimals of accuracy
[19:27:57.656][D][main:537]: Heizung ==> heat plus!
[19:27:57.868][D][main:589]: Heizung ==> cool MINUS!
[19:27:57.872][D][sensor:131]: 'PID Climate Result': Sending state -99.01081 % with 1 decimals of accuracy
[19:27:57.882][D][sensor:131]: 'PID Climate Cool': Sending state 99.01081 % with 1 decimals of accuracy
[19:27:57.889][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:27:57.897][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:27:57.902][D][climate:402]:   Mode: HEAT_COOL
[19:27:57.907][D][climate:404]:   Action: COOLING
[19:27:57.912][D][climate:422]:   Current Temperature: 25.30°C
[19:27:57.919][D][climate:428]:   Target Temperature: 25.50°C
[19:27:57.935][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 48.30000 % with 1 decimals of accuracy
[19:27:57.961][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:28:57.417][D][dht:042]: Temperature 24.9°C Humidity 49.3%
[19:28:57.417][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 24.90000 °C with 1 decimals of accuracy
[19:28:57.631][D][main:537]: Heizung ==> heat plus!
[19:28:57.841][D][main:589]: Heizung ==> cool MINUS!
[19:28:57.843][D][sensor:131]: 'PID Climate Result': Sending state -56.62439 % with 1 decimals of accuracy
[19:28:57.853][D][sensor:131]: 'PID Climate Cool': Sending state 56.62439 % with 1 decimals of accuracy
[19:28:57.864][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:28:57.868][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:28:57.873][D][climate:402]:   Mode: HEAT_COOL
[19:28:57.879][D][climate:404]:   Action: COOLING
[19:28:57.882][D][climate:422]:   Current Temperature: 24.90°C
[19:28:57.890][D][climate:428]:   Target Temperature: 25.50°C
[19:28:57.906][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 49.30000 % with 1 decimals of accuracy
[19:28:57.931][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:29:57.406][D][dht:042]: Temperature 24.5°C Humidity 48.9%
[19:29:57.411][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 24.50000 °C with 1 decimals of accuracy
[19:29:57.626][D][main:537]: Heizung ==> heat plus!
[19:29:57.838][D][main:589]: Heizung ==> cool MINUS!
[19:29:57.841][D][sensor:131]: 'PID Climate Result': Sending state -34.21554 % with 1 decimals of accuracy
[19:29:57.846][D][sensor:131]: 'PID Climate Cool': Sending state 34.21554 % with 1 decimals of accuracy
[19:29:57.856][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:29:57.862][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:29:57.865][D][climate:402]:   Mode: HEAT_COOL
[19:29:57.869][D][climate:404]:   Action: COOLING
[19:29:57.874][D][climate:422]:   Current Temperature: 24.50°C
[19:29:57.876][D][climate:428]:   Target Temperature: 25.50°C
[19:29:57.904][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 48.90000 % with 1 decimals of accuracy
[19:29:57.923][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:30:57.429][D][dht:042]: Temperature 24.3°C Humidity 49.5%
[19:30:57.431][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 24.30000 °C with 1 decimals of accuracy
[19:30:57.644][D][main:537]: Heizung ==> heat plus!
[19:30:57.855][D][main:589]: Heizung ==> cool MINUS!
[19:30:57.857][D][sensor:131]: 'PID Climate Result': Sending state -13.15631 % with 1 decimals of accuracy
[19:30:57.869][D][sensor:131]: 'PID Climate Cool': Sending state 13.15631 % with 1 decimals of accuracy
[19:30:57.874][D][sensor:131]: 'PID Climate HEAT': Sending state 0.00000 % with 1 decimals of accuracy
[19:30:57.881][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:30:57.887][D][climate:402]:   Mode: HEAT_COOL
[19:30:57.891][D][climate:404]:   Action: COOLING
[19:30:57.896][D][climate:422]:   Current Temperature: 24.30°C
[19:30:57.904][D][climate:428]:   Target Temperature: 25.50°C
[19:30:57.921][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 49.50000 % with 1 decimals of accuracy
[19:30:57.945][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:31:57.457][D][dht:042]: Temperature 24.1°C Humidity 49.7%
[19:31:57.459][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 24.10000 °C with 1 decimals of accuracy
[19:31:57.669][D][main:589]: Heizung ==> cool MINUS!
[19:31:57.879][D][main:537]: Heizung ==> heat plus!
[19:31:57.885][D][sensor:131]: 'PID Climate Result': Sending state 9.44591 % with 1 decimals of accuracy
[19:31:57.893][D][sensor:131]: 'PID Climate Cool': Sending state 0.00000 % with 1 decimals of accuracy
[19:31:57.901][D][sensor:131]: 'PID Climate HEAT': Sending state 9.44591 % with 1 decimals of accuracy
[19:31:57.910][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:31:57.914][D][climate:402]:   Mode: HEAT_COOL
[19:31:57.919][D][climate:404]:   Action: HEATING
[19:31:57.927][D][climate:422]:   Current Temperature: 24.10°C
[19:31:57.933][D][climate:428]:   Target Temperature: 25.50°C
[19:31:57.948][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 49.70000 % with 1 decimals of accuracy
[19:31:57.974][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed
[19:32:11.308][D][web_server_idf:395]: Removing dead event source session
[19:32:11.308][D][web_server_idf:480][httpd]: Event source connection closed (fd: 61)
[19:32:16.797][D][climate:011]: 'PID Climate Controller' - Setting
[19:32:16.799][D][climate:040]:   Target Temperature: 24.20
[19:32:16.804][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:32:16.808][D][climate:402]:   Mode: HEAT_COOL
[19:32:16.812][D][climate:404]:   Action: HEATING
[19:32:16.820][D][climate:422]:   Current Temperature: 24.10°C
[19:32:16.824][D][climate:428]:   Target Temperature: 24.20°C
[19:32:19.525][D][climate:011]: 'PID Climate Controller' - Setting
[19:32:19.529][D][climate:040]:   Target Temperature: 26.20
[19:32:19.535][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:32:19.538][D][climate:402]:   Mode: HEAT_COOL
[19:32:19.542][D][climate:404]:   Action: HEATING
[19:32:19.547][D][climate:422]:   Current Temperature: 24.10°C
[19:32:19.551][D][climate:428]:   Target Temperature: 26.20°C
[19:32:47.410][D][web_server_idf:395]: Removing dead event source session
[19:32:47.410][D][web_server_idf:480][httpd]: Event source connection closed (fd: 62)
[19:32:57.484][D][dht:042]: Temperature 24.0°C Humidity 49.9%
[19:32:57.489][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 24.00000 °C with 1 decimals of accuracy
[19:32:57.703][D][main:589]: Heizung ==> cool MINUS!
[19:32:57.911][D][main:537]: Heizung ==> heat plus!
[19:32:57.916][D][sensor:131]: 'PID Climate Result': Sending state 43.36065 % with 1 decimals of accuracy
[19:32:57.924][D][sensor:131]: 'PID Climate Cool': Sending state 0.00000 % with 1 decimals of accuracy
[19:32:57.932][D][sensor:131]: 'PID Climate HEAT': Sending state 43.36065 % with 1 decimals of accuracy
[19:32:57.941][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:32:57.946][D][climate:402]:   Mode: HEAT_COOL
[19:32:57.954][D][climate:404]:   Action: HEATING
[19:32:57.960][D][climate:422]:   Current Temperature: 24.00°C
[19:32:57.964][D][climate:428]:   Target Temperature: 26.20°C
[19:32:57.980][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 49.90000 % with 1 decimals of accuracy
[19:32:58.011][D][esp32.preferences:149]: Writing 1 items: 0 cached, 1 written, 0 failed
[19:33:57.501][D][dht:042]: Temperature 23.9°C Humidity 50.1%
[19:33:57.503][D][sensor:131]: 'Garage Temperatur DHT_1': Sending state 23.90000 °C with 1 decimals of accuracy
[19:33:57.716][D][main:589]: Heizung ==> cool MINUS!
[19:33:57.923][D][main:537]: Heizung ==> heat plus!
[19:33:57.928][D][sensor:131]: 'PID Climate Result': Sending state 93.82323 % with 1 decimals of accuracy
[19:33:57.936][D][sensor:131]: 'PID Climate Cool': Sending state 0.00000 % with 1 decimals of accuracy
[19:33:57.944][D][sensor:131]: 'PID Climate HEAT': Sending state 93.82323 % with 1 decimals of accuracy
[19:33:57.952][D][climate:399]: 'PID Climate Controller' - Sending state:
[19:33:57.957][D][climate:402]:   Mode: HEAT_COOL
[19:33:57.962][D][climate:404]:   Action: HEATING
[19:33:57.968][D][climate:422]:   Current Temperature: 23.90°C
[19:33:57.977][D][climate:428]:   Target Temperature: 26.20°C
[19:33:57.995][D][sensor:131]: 'Garage Luftfeuchtigkeit DHT_1': Sending state 50.10000 % with 1 decimals of accuracy
[19:33:58.020][D][esp32.preferences:149]: Writing 1 items: 1 cached, 0 written, 0 failed

Looks now better…
but the problem is

he jump every time in both sections like Heat plus & Heat Minus

output:
  - platform: template
    id: pidHeaterOutputHeat
 &
  - platform: template
    id: pidHeaterOutputCool

19:44:58	[D]	[main:589]	Heizung ==> cool MINUS!
19:44:58	[D]	[main:537]	Heizung ==> heat plus!

I thought the PID controller only switched to cooling mode when cooling and to heating mode when heating… but mine is being activated in both modes simultaneously… why is that?

I don’t have time to dive in to your case now, but I wanted to note that constant power is not necessarily the most efficient way. Not all devices are modulating the power ideally, so power 6 at 50% duty could actually be more efficient than power 3 at 100% duty.

Where do you get the information about the duty cycle (100% or 50%) and the power level (3 or 6)?

This is probably a silly question, but I’m looking for a way for the PID controller to automatically set and send the power level (1-10).
Or do I have to query and control all of this myself using lambda ?

My comment was not related to Esphome at all. Just about modulation efficiency of a heater.

my “PID Climate Controller” send any state value to

  • pidHeaterOutputHeat
  • and
  • pidHeaterOutputCool

I would like to display these values ​​in my debug log.
However, I’m getting errors when compiling.

Compiling .pioenvs/esp32-s2-mini-saola/src/main.cpp.o
/config/esphome/test1.yaml: In lambda function:
/config/esphome/test1.yaml:212:21: error: 'class esphome::pid::PIDClimate' has no member named 'state'
  212 |           return id(pidId).state;
      |                     ^~~~~
*** [.pioenvs/esp32-s2-mini-saola/src/main.cpp.o] Error 1
========================= [FAILED] Took 62.24 seconds =========================

Can someone help me figure out how to display the values ​​of the PID climate controller?

ther is the code snippet

write_action:
      - lambda: |-
          
          return id(pidId).state;
          //id(pidId).state;
          if (state == 0) {
            // Cooling needed
            //- logger.log: State = 0;
            //heater_run = 0.0;

there is the complete code

# Example configuration entry
climate:
  - platform: pid
    name: "PID Climate Controller"
    sensor: TEMP_DHT_1
    id: pidId
    default_target_temperature: 21°C
    heat_output: pidHeaterOutputHeat
    cool_output: pidHeaterOutputCool
    control_parameters:
      kp: 0.49460
      ki: 0.00487
      kd: 12.56301
      output_averaging_samples: 5      # smooth the output over 5 samples
      derivative_averaging_samples: 5  # smooth the derivative value over 10 samples
    deadband_parameters:
      threshold_high: 0.5°C       # deadband within +/-0.5°C of target_temperature
      threshold_low: -0.5°C


output:
  - platform: template
    id: pidHeaterOutputHeat
    type: float
    min_power: 0.01
    max_power: 1.00
    write_action:
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '0001110xxxxxxxxxxxxx0110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: climate.pid.state
  - platform: template
    id: pidHeaterOutputCool
    type: float
    min_power: 0.01
    max_power: 1.00
    write_action:
      - lambda: |-
          return id(pidId).state;
          //id(pidId).state;
          if (state == 0) {
            // Cooling needed
            //- logger.log: State = 0;
            //heater_run = 0.0;
          }
          if (state == 1) {
            // Heating needed
            //- logger.log: State = 1;
            //heater_run = 1.0;
          }
          if (state > 1) {
            // Heating needed
            //- logger.log: State > 1;
            // heater_run = state;
          }else{
            //heater_run = state;
          }
      - logger.log: state  
      - remote_transmitter.transmit_rc_switch_raw:   
          code: '0001110xxxxxxxxxxxxxxx10110000'
          protocol: 
            pulse_length: 255
          repeat:
            times: 5
            wait_time: 0s
      - logger.log: climate.pidHeaterOutputCool


Maybe not the best solution,but im using this on Extraflame pellet stove.For me works like a charm.

climate:
  - platform: thermostat
    name: "Ketty võimsusjuhtimine"
    id: ketty_thermostaat
    sensor: shellytemp
    heat_deadband: 0.0
    heat_overrun: 0.0
    visual:
      min_temperature: 15
      max_temperature: 30
      temperature_step: 0.1
    min_heating_off_time: 2s
    min_heating_run_time: 2s
    min_idle_time: 2s
    heat_action: []
    idle_action: []
    preset:
      - name: Kodus
        default_target_temperature_low: 20 °C
      - name: Eemal
        default_target_temperature_low: 18 °C
number:
  - platform: micronova
    thermostat_temperature:
      name: Micronova termostaadi temp
      id: micronova_thermo
      step: 1
    power_level:
      name: Micronova võimsuse tase
      id: micronova_power
script:
  - id: update_kamina_power
    mode: restart
    then:
      - if:
          condition:
            sensor.in_range:
              id: kamina_delta
              below: -0.4
          then:
            - number.set:
                id: micronova_power
                value: 5

      - if:
          condition:
            sensor.in_range:
              id: kamina_delta
              below: -0.3
              above: -0.4
          then:
            - number.set:
                id: micronova_power
                value: 4

      - if:
          condition:
            sensor.in_range:
              id: kamina_delta
              below: -0.2
              above: -0.3
          then:
            - number.set:
                id: micronova_power
                value: 3

      - if:
          condition:
            sensor.in_range:
              id: kamina_delta
              below: -0.1
              above: -0.2
          then:
            - number.set:
                id: micronova_power
                value: 2

      - if:
          condition:
            sensor.in_range:
              id: kamina_delta
              above: 0
          then:
            - number.set:
                id: micronova_power
                value: 1
sensor:
  - platform: template
    name: "Kamina delta"
    id: kamina_delta
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    update_interval: 10s
    lambda: |-
      return id(shellytemp).state - id(ketty_thermostaat).target_temperature;
    on_value:
      then:
        - script.execute: update_kamina_power

  - platform: homeassistant
    entity_id: sensor.suuretoatempshelly_temperature
    id: shellytemp

Many many thanks @ Pafkas

I’ll try to follow the code and see if I understand it.
… 1) You define only one Climate Thermostat component

  1.1 This Climate Thermostat component essentially only 
         specifies the set target temperature.

 1.2 The two brackets [] in heat_Action & idle_action mean 
       that the call for heating and idle phase happens elsewhere.

Question:
What do these two brackets mean?
That nothing is called here initially?
And how did you know you had to put these brackets here?
Where does it say that?
I’m just wondering because I never would have figured that out.

  1. number:

    • platform: micronova
      thermostat_temperature:

      This is probably your thermostat, where the temperature
      is adjustable in 1-point increments.

    power_level:
    
    These appear to be the heating levels, which are then 
     calculated in the script below.
    
  2. script:

This script is constantly called by the sensor: kamina_delta.

In the script, you simply query the current temperature range and how far it deviates from the target temperature.

You get the values ​​from:
sensor:

  • platform: template
    name: “Kamina delta”
    id: kamina_delta
  1. sensor:

      The sensor essentially only calculates the difference between
       the current temperature and the target temperature. and target 
       temperature
    

Result for me:

I would only need to:

  1. extend the script to my 10 possible heating levels
  2. swap your number of sections with my button sections
    so that the 433MHz transmitter and the corresponding
    On/Off/Plus or Minus code are called on my device

button:
- platform: template
name: Heaton Power Plus
id: heaterPlus
on_press:
- remote_transmitter.transmit_rc_switch_raw:
code: ‘0001110001xxxxxxxxxxxxx10110000’
protocol:
pulse_length: 255
repeat:
times: 5
wait_time: 0s

I just need to save the currently set heating level somewhere.

Reason: I can’t directly select a heating level… I can’t send 1, 3, or 7; I always have to count down from 10 when restarting the heating system.

If I want heating level 5 after restarting, I have to send a minus code 5 times. If I then want heating level 7, I have to send a plus code 2 times.

But I can manage that.

If I’ve understood the above correctly, please let me know.

Thank you so much. You’ve been a great help.

Your solution looks neat, simple, and logically sound.

Great!

Best regards

try in script:

1 Like

Hi,
your code is a perfect fit for my project. Even more importantly, I now understand much better how to program ESPHOME using your code and examples.

The approach with the “IF” statements and the above and below commands is also ideal.

Since my diesel heater, which I use in the garage, is a bit slow to respond, I just need to add some logic with switching times and waiting periods to prevent it from changing the heating level too quickly in response to temperature differences.

Thanks to your code, that’s no longer a problem.

I originally thought I’d have to solve this using the built-in logic of the Climate PID controller.

Thanks again for your code, which has been a great help in moving forward.

Best regards

You welcome!

1 Like