Problem setting homeassistant.service and PID climate target temperature

Hello everyone. I have problems to put things together and need your help.

i want to switch from ha-pid-controller to ESPHome PID climate. In homeassistant i use custom VEsync with a Classic300S Humidifier.

I managed to set up PID Climate based on this code. I use ledc for PWM.

##Edit - short update:
I need help to

  • set default_target_temperature with id: RH_ZIEL (solved)
  • set mist level based on id: rh_output_level (solved)
  • insert global mist_level instead of ‘8’ in script (see post 4, there is the complete script)
value: '8' #'mist_level' #!lambda 'return mist_level;'

Here is the relevant code fro PID Climate:

climate:
  - platform: pid
    name: "PID Humidity Controller"
    id: pid_humidity_controller
    sensor: RH_MITTELWERT
    default_target_temperature: 70 °C
    heat_output: pwm_output
    visual:
      min_temperature: 30
      max_temperature: 80
    control_parameters:
      kp: 0.30606
      ki: 0.00319
      kd: 7.34541
      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: 2°C       # deadband within +/-0.5°C of target_temperature
      threshold_low: -2°C
button:
  - platform: template
    name: "PID Climate Autotune"
    on_press:
      - climate.pid.autotune: pid_humidity_controller

output:
  - platform: ledc
    id: pwm_output
    pin: GPIO39

sensor:
  - platform: pid
    name: "RH Output Level"
    id: rh_output_level
    climate_id: pid_humidity_controller
    type: HEAT

Thank you in advance
Schnabulator

This looks wrong. turn_turn_on? Surely not!

Hello

sorry - you are absolutely right.
The code above is WIP including the part i need help with :slight_smile:. I correct my initial post.

In ha the following automation works great.
Downside is sending massive sensor data from esp home to home assistant (for “fast” reaction of the humidifier). Another thing is that the humidifier start with mist level 1. My workaround is setting mist static to level 6 (pid > 0).

To be clear i need help to write data from a template sensor on ESPHome

  • id: RH_ZIEL values in climate.esp_pid_humidity_controller directly on the ESP.
  • turn on / off the domain humidifier in HA
alias: ESPHome PID Controller Luftbefeuchter Ansteuerung
description: ""
trigger:
  - platform: time_pattern
    seconds: /10
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: "{{ states('sensor.esp_rh_ziel') }}"
    target:
      entity_id: climate.esp_pid_humidity_controller
  - if:
      - condition: numeric_state
        entity_id: sensor.esp_rh_output_level
        above: "0"
    then:
      - type: turn_on
        device_id: 8087b5018bbe0c6d1de2a789d8b5c9a2
        entity_id: 1f5fa2674733027e2665ed63e0a603de
        domain: humidifier
      - delay:
          hours: 0
          minutes: 0
          seconds: 2
          milliseconds: 0
      - service: number.set_value
        metadata: {}
        data:
          value: "6"
        target:
          entity_id: number.classic300s_mist_level
        enabled: true
      - if:
          - condition: numeric_state
            entity_id: sensor.pid_humidity
            above: 30
        then:
          - service: number.set_value
            metadata: {}
            data:
              value: "6"
            target:
              entity_id: number.classic300s_mist_level
        else:
          - service: number.set_value
            metadata: {}
            data:
              value: "4"
            target:
              entity_id: number.classic300s_mist_level
        enabled: false
    else:
      - type: turn_off
        device_id: 8087b5018bbe0c6d1de2a789d8b5c9a2
        entity_id: 1f5fa2674733027e2665ed63e0a603de
        domain: humidifier
mode: single

short update:

  • set default_target_temperature with id: RH_ZIEL is solved.
  • setting mist_level works

ToDo:

  • insert global mist_level instead of ‘8’ in script
value: '8' #'mist_level' #!lambda 'return mist_level;'

complete script:

globals:
  - id: "mist_level"
    type: float #int
    restore_value: no
    initial_value: '1'

script:
  - id: luftbefeuchter_an_mistlevel
    then:
      - homeassistant.service:
          service: homeassistant.turn_on
          data:
            entity_id: 'humidifier.classic300s'
      - delay: 2s
      - homeassistant.service:
          service: number.set_value
          data:
            entity_id: 'number.classic300s_mist_level'
            value: '8' #'mist_level' #!lambda 'return mist_level;'

  - id: luftbefeuchter_aus_mistlevel
    then:
      - homeassistant.service:
          service: homeassistant.turn_off
          data:
            entity_id: 'humidifier.classic300s'

setting mist_level (works)

sensor:
  - platform: pid
    name: "RH Output Level"
    id: rh_output_level
    climate_id: pid_humidity_controller
    type: HEAT
    on_value:
      then:
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                below: 0
            then:
              - lambda: |-
                  id(mist_level) = 1;
              - script.execute: luftbefeuchter_aus_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_aus_mistlevel ausführung gestartet - Mistlevel %f eingestellt"
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]  
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                above: 0.1
                below: 20
            then:
              - lambda: |-
                  id(mist_level) = 5;
              - script.execute: luftbefeuchter_an_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_an_mistlevel ausführung gestartet - Mistlevel %f eingestellt "
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                above: 20
                below: 40
            then:
              - lambda: |-
                  id(mist_level) = 6;
              - script.execute: luftbefeuchter_an_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_an_mistlevel ausführung gestartet - Mistlevel %f eingestellt"
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                above: 40
                below: 60
            then:
              - lambda: |-
                  id(mist_level) = 7;
              - script.execute: luftbefeuchter_an_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_an_mistlevel ausführung gestartet - Mistlevel %f eingestellt"
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                above: 60
                below: 80
            then:
              - lambda: |-
                  id(mist_level) = 8;
              - script.execute: luftbefeuchter_an_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_an_mistlevel ausführung gestartet - Mistlevel %f eingestellt"
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]
        - if:
            condition:
              sensor.in_range:
                id: rh_output_level
                above: 80
                below: 100
            then:
              - lambda: |-
                  id(mist_level) = 9;
              - script.execute: luftbefeuchter_an_mistlevel
              - logger.log:
                  format: "script: luftbefeuchter_an_mistlevel ausführung gestartet - Mistlevel %f eingestellt "
                  args: [ 'id(mist_level)' ]
              - logger.log:
                  format: "Luftbefeuchter state: %d"
                  args: [ 'id(luftbefeuchter_zustand).state' ]

set default_target_temperature with id: RH_ZIEL is solved.

     on_value:
      then:
        - lambda: |-
            id(pid_humidity_controller).target_temperature = id(RH_ZIEL).state;
        - logger.log:
            format: "Luftfeuchtigkeit = %.1f eingestellt :)"
            args: [ 'id(pid_humidity_controller).target_temperature' ]

insert global mist_level instead of ‘8’ in script works :slight_smile:

      - homeassistant.service:
          service: number.set_value
          data:
            entity_id: 'number.classic300s_mist_level'
            value: !lambda return id(mist_level);

I suggest you post your complete working code for the benefit of others.