Setting ESPHome PID control_parameters from Home Assistant

I’m trying to set the PID controller parameters from Home Assistant. I tried using lambda’s but it won’t pass compilation. Can anyone help me out?

climate:
  - platform: pid
    id: PID_Kachelthermostaat
    name: "PID Kachelthermostaat"
    sensor: living_temperatuur
    default_target_temperature: 21.5°C
    heat_output: gasklep
    control_parameters:
      kp: !lambda: 
        return id(PID_Kp_HA).state;
      ki: !lambda: 
        return id(PID_Ki_HA).state;
      kd: !lambda: 
        return id(PID_Kd_HA).state;
      output_averaging_samples: 5      # smooth the output over 5 samples
      derivative_averaging_samples: 10  # smooth the derivative value over 10 samples
    deadband_parameters:
      threshold_high: 0°C
      threshold_low: -0.1°C
      deadband_output_averaging_samples: 15   # average the output over 15 samples within the deadband

sensor:  
  - platform: homeassistant
    id: PID_Kd_HA
    entity_id: input_number.pid_kd

  - platform: homeassistant
    id: PID_Ki_HA
    entity_id: input_number.pid_ki

  - platform: homeassistant
    id: PID_Kp_HA
    entity_id: input_number.pid_kp

Thanks for any help.

So theres a comlile error that tells you what the problem is and at what line number the error is in, but you decided to make it a mystery to everyone? Should we all take turns guessing what the error was or do you think you can post the error with the yaml?

INFO ESPHome 2023.12.9
INFO Reading configuration /config/esphome/esp8266f-kachel.yaml…
ERROR Error while reading config: Invalid YAML syntax:

could not determine a constructor for the tag ‘!lambda:’
in “/config/esphome/esp8266f-kachel.yaml”, line 178, column 9:
!lambda:
^

when you limit the information to what you think is all people need to know, it does 2 things. It makes people not want to mess with you’re post and help you, and it’s incredibly annoying.

someone can only assume the error is for one of lambda’s you are showing and that line 178 in the error is for 1 of those 3 lambdas because you only copied part of the error? I can’t tell because you decided you know whats best and what information is relevant.

You’re HA input_select sensor, is it returning an int or a float?
The control_parameters require a floating point number, not an int.

control_parameters (Required): Control parameters of the PID controller.

  • kp (Required, float): The factor for the proportional term of the PID controller.
  • ki (Optional, float): The factor for the integral term of the PID controller. Defaults to 0.
  • kd (Optional, float): The factor for the derivative term of the PID controller. Defaults to 0.

you can try this though.

control_parameters:
      kp: !lambda |- 
        return id(PID_Kp_HA).state / 100;
      ki: !lambda |-
        return id(PID_Ki_HA).state / 100;
      kd: !lambda |-
        return id(PID_Kd_HA).state / 100;

or try this

control_parameters:
      kp: !lambda |- 
        return float(id(PID_Kp_HA).state);
      ki: !lambda |-
        return float(id(PID_Ki_HA).state);
      kd: !lambda |-
        return float(id(PID_Kd_HA).state);