khenderick / esphome-opentherm

OpenTherm support for ESPHome
MIT License
14 stars 4 forks source link

How to get PID climate to work? #13

Open ShurikenGitHub opened 9 months ago

ShurikenGitHub commented 9 months ago

Hi,

I'm trying to make a PID climate thermostat using your code. As far as i know the homeassistant generic thermostat is just a basic on/off thermostat. I tried to use the esphome PID climate component but i am struggling with the heat_output parameter. This expects an output. I tried to set the ch_setpoint_temperature, but this is a number so it's not compatible with the output component.

How would i implement a PID climate using the ch_setpoint_temperature number?

Thanks

khenderick commented 9 months ago

Hi,

It indeed makes sense to use ESPHome's PID Climate. If that component needs an output, you can add a Template Output to your setup and use this Template Output in the PID Climate's configuration. The Template Output has a write_action that can be used to control the various sensors/numbers of the OpenTherm component. For example, when the PID Climate turns on the Template Output, the write_action could then turn on the OpenTherm CH enabled switch and/or change the CH setpoint.

ShurikenGitHub commented 9 months ago

I tried to use the template output like you documented but it doesn't set the CH setpoint number unfortunately:

 climate: 
    ...
    heat_output: t_set
    on_state:
      lambda: !lambda |-
        if (id(pid_climate).mode == 3) {
          id(ch_enabled).turn_on();
        } else {
          id(ch_enabled).turn_off();
        } 

output:
  - platform: template
    id: t_set
    type: float
    write_action:
      - number.set:
          id: opentherm_ch_setpoint <-- I added an id to the ch_setpoint_temperature
          value: !lambda return state;

This turns on the CH enabled when the thermostat is set to heat but does not change the CH setpoint value. Please let me know what stupid mistake i probably made ;)

khenderick commented 9 months ago

The log output might indicate whether something strange is going on.

A few things that might be the issue:

A note on the setpoint range; it's important to understand that while a boiler might support a setpoint range from e.g. 25 to 60 degrees C (it's the boiler setpoint, not a regular room thermostat setpoint), it might be possible that your heating infrastructure does not support the same range. For example, certain radiators might gladly accept a setpoint of 80 degrees C (which will result in a very hot radiator), while underfloor heating might get damaged with temperatures above 50 degrees C, even though the boiler would not care (that's also why underfloor heating often has additional safety bypass valves). Make sure that you understand the reasonable limits of your system.

ananyevgv commented 9 months ago

I checked the PID this morning, the boiler turns on and warms and turns off, but the ch_setpoint_temperature in ESPHOME does not change. I will try to check the PID completely over the weekend.

ananyevgv commented 9 months ago

image

khenderick commented 9 months ago

What are the minimum and maximum CH setpoint values as stated by the boiler? Are you setting values within the limit? If you can't figure it out, feel free to post ESPHome config and HA automations you're using.

ananyevgv commented 9 months ago

image

ananyevgv commented 9 months ago

My configuration for ESPHOME https://github.com/ananyevgv/esphome-opentherm-khenderick/blob/main/boiler.yaml

ananyevgv commented 9 months ago

here there was also an attempt to add output to your component https://github.com/foxey/esphome-opentherm/tree/main/components/opentherm/output

ShurikenGitHub commented 9 months ago

I had the same issue, it is because the PID tries to set a temp that is not in the range of the setpoint temps, other logic is needed to translate it to a valid range. @khenderick could you maybe create a good working example for the PID climate? I'm not too familiar with the esphome lambda's/functions etc so it would take me a lot of time to figure such a thing out. I understand what the logical problem is so i will take a look at it again this weekend, but some help might be helpful.

ananyevgv commented 9 months ago

I agree ch_setpoint was equal to 25 degrees

ananyevgv commented 9 months ago

The PID seems to start picking up the temperature starting from 0 degrees.

[16:08:56][D][number:054]: 'CH setpoint temperature' - Setting number value [16:08:56][W][number:105]: 'CH setpoint temperature' - Value 0.000000 must not be less than minimum 10.000000

when changing h_setpoint_temperature: min_value: 0.0, the value of ch_setpoint starts to increase slowly

khenderick commented 9 months ago

I'll try to come up with a reasonable example somewhere in the coming weeks when I find some spare time.

However, keep in mind that such example won't be a fit-for-all, as the mapping between PID output setpoint and OpenTherm CH setpoint won't be a fixed thing and will - as stated before - be depending on the specific heating configuration on premise (underfloor heating vs radiators, possible outside temperature compensations, ...). For example, I never lived in a place where I needed to change the CH setpoint at all, as the only thing that needed to be controlled were the valves to the radiators or underfloor heating circuits, which were controlled by the output of a PID loop.

ananyevgv commented 9 months ago

I have done so far so: output: