『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
楼主: gmzjy1989

[技术探讨] ESPHOME接入4PIN风扇给机柜散热

  [复制链接]

0

主题

14

帖子

271

积分

中级会员

Rank: 3Rank: 3

积分
271
金钱
257
HASS币
0
发表于 3 天前 | 显示全部楼层
PID 自动控制温度,实测很好用(部署好就没再管过它了)

https://github.com/patrickcollins12/esphome-fan-controller

number:

  ## OPTIONAL:
  # RECEIVE KP, KI and KD parameters from input_text.kx helpers in 
  # Home Assistant. See the PID controller below
  # These helper values will get saved to flash thus permanently over-riding 
  # the initial values set in the PID below.

  # KP
  - platform: template
    name: kp
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: 0.3
    min_value: 0
    max_value: 50
    step: 0.001
    set_action: 
      lambda: |- 
        id(console_thermostat).set_kp( x );

  # KI
  - platform: template
    name: ki
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: 0.0015
    min_value: 0
    max_value: 50
    step: 0.0001
    set_action: 
      lambda: id(console_thermostat).set_ki( x );

  # KD
  - platform: template
    name: kd
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: 0.0
    min_value: -50
    max_value: 50
    step: 0.001
    set_action: 
      lambda: id(console_thermostat).set_kd( x );

  # Set threshold low
  - platform: template
    name: Deadband Threshold Low
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: -1.0
    min_value: -20
    max_value: 0
    step: 0.1
    set_action: 
      lambda: id(console_thermostat).set_threshold_low( x );

  # Set threshold high
  - platform: template
    name: Deadband Threshold High
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: 0.4
    min_value: 0
    max_value: 20
    step: 0.1
    set_action: 
      lambda: id(console_thermostat).set_threshold_high( x );

  # Set ki multiplier
  - platform: template
    name: Deadband ki Multiplier
    icon: mdi:chart-bell-curve
    restore_value: true
    initial_value: 0.04
    min_value: 0
    max_value: .2
    step: 0.01
    set_action: 
      lambda: id(console_thermostat).set_ki_multiplier( x );

text_sensor:

  # Send IP Address
  - platform: wifi_info
    ip_address:
      name: $friendly_name IP Address

  # Send Uptime in raw seconds
  - platform: template
    name: $friendly_name Uptime
    id: uptime_human
    icon: mdi:clock-start

sensor:

  # Send WiFi signal strength & uptime to HA
  - platform: wifi_signal
    name: $friendly_name WiFi Strength
    update_interval: 60s

  # This is a bit of overkill. It sends a human readable 
  # uptime string 1h 41m 32s instead of 6092 seconds
  - platform: uptime
    name: $friendly_name Uptime
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            # Custom C++ code to generate the result
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

  # Read the Tacho PIN and show measured RPM as a sensor (only with 4-pin PWM fans!)

  - platform: pulse_counter
    pin: 
      number: GPIO26   # Connect to any input PIN on the ESP
      mode: INPUT_PULLUP
    unit_of_measurement: 'RPM'
    id: fan_speed
    name: $friendly_name Fan Speed
    accuracy_decimals: 0
    filters:
      - multiply: 0.5  # Depending on how many pulses the fan sends per round - should be 0.5 or 1 - try...

########################################################
# START THE FAN CONTROLLER SETUP

  - platform: template
    name: $friendly_name p term
    id: p_term
    unit_of_measurement: "%"
    accuracy_decimals: 2

  - platform: template
    name: $friendly_name i term
    id: i_term
    unit_of_measurement: "%"
    accuracy_decimals: 2

  - platform: template
    name: $friendly_name d term
    id: d_term
    unit_of_measurement: "%"
    accuracy_decimals: 2

  - platform: template
    name: $friendly_name output value
    unit_of_measurement: "%"
    id: o_term
    accuracy_decimals: 2

  - platform: template
    name: $friendly_name error value
    id: e_term
    accuracy_decimals: 2

  - platform: template
    name: $friendly_name is in deadband
    id: in_deadband_term
    accuracy_decimals: 0



  # GET TEMP/HUMIDITY FROM DS18B20
  - platform: dallas
    address: 0x7206220013581828
    name: "Temperature"
    id: console_fan_temperature
    accuracy_decimals: 3
#    filters:
 #    - exponential_moving_average:  
  #       alpha: 0.1
   #      send_every: 15

  # Take the "COOL" value of the pid and send 
  # it to the frontend to graph the output voltage
  - platform: pid
    name: "Fan Speed (PWM Voltage)"
    climate_id: console_thermostat
    type: COOL

#DS18B20
dallas:
  - pin: GPIO33


output:
  # Wire this pin (13) into the PWM pin of your 12v fan
  # ledc is the name of the pwm output system on an esp32
  - platform: ledc
    id: console_fan_speed
    pin: GPIO13

    # 25KHz is standard PC fan frequency, minimises buzzing
    frequency: "25000 Hz" 

    # my fans stop working below 13% powerful.
    # also they're  powerful and loud, cap their max speed to 80%
    min_power: 0%
    max_power: 100%

# Good for debugging, you can manually set the fan 
# speed. Just make sure the Climate device is set to off or it will keep getting overridden.
# fan:
#   - platform: speed
#     output: console_fan_speed
#     name: "Console Fan Speed"

# Expose a PID-controlled Thermostat
# Manual: https://esphome.io/components/climate/pid.html
climate:
  - platform: pid
    name: "Console Fan Thermostat"
    id: console_thermostat
    sensor: console_fan_temperature

    # It is summer right now, so 30c is a decent target.
    default_target_temperature: 30°C
    cool_output: console_fan_speed

    # ON state change, publish the values to the x_term numbers defined 
    # above, so that they can be viewed in HA
    on_state:
      - sensor.template.publish:
          id: p_term
          state: !lambda 'return -id(console_thermostat).get_proportional_term() * 100.0;'
      - sensor.template.publish:
          id: i_term
          state: !lambda 'return -id(console_thermostat).get_integral_term()* 100.0;'
      - sensor.template.publish:
          id: d_term
          state: !lambda 'return -id(console_thermostat).get_derivative_term()* 100.0;'
      - sensor.template.publish:
          id: o_term
          state: !lambda 'return -id(console_thermostat).get_output_value()* 100.0;'
      - sensor.template.publish:
          id: in_deadband_term
          state: !lambda 'return id(console_thermostat).in_deadband();'
      - sensor.template.publish:
          id: e_term
          state: !lambda 'return -id(console_thermostat).get_error_value();'
        
    # The extents of the HA Thermostat
    visual:
      min_temperature: 20 °C
      max_temperature: 50 °C
  
    # See the README for setting up these parameters.
    # These are over ridden by the number templates above.
    control_parameters:
      kp: 0.3
      ki: 0.0015
      kd: 0
      max_integral: 0.0
      output_averaging_samples: 1
      derivative_averaging_samples: 5

    # How to behave when close to the target temperature?
    deadband_parameters:
      threshold_high: 0°C
      threshold_low: -0°C
      kp_multiplier: 0.0
      ki_multiplier: 0.04
      kd_multiplier: 0.0
      deadband_output_averaging_samples: 15

switch:
  # Expose an ESP32 restart button to HA
  - platform: restart
    name: ${friendly_name} ESP32 Restart
    id: console_fan_restart

# Restart every day at 12:30am. 
# I've had some memory issues lockup 
# the device after a couple weeks
time:
  - platform: homeassistant
    on_time:
      # Every morning at 12:30am
    - seconds: 0
      minutes: 30
      hours: 0
      then:
       - switch.turn_on: console_fan_restart


# I was able to find good KP,KI,KD values manually, per the instructions,
# but you can try pressing the autotune button from home assistant and copying the 
# values it produces. 
# See more at: https://esphome.io/components/climate/pid.html#climate-pid-autotune-action
button:
- platform: template
  name: "PID Climate Autotune"
  on_press: 
    - climate.pid.autotune: console_thermostat
    
回复

使用道具 举报

0

主题

47

帖子

641

积分

高级会员

Rank: 4

积分
641
金钱
594
HASS币
0
发表于 3 天前 | 显示全部楼层
好啊,这个,也需要
回复

使用道具 举报

0

主题

11

帖子

134

积分

注册会员

Rank: 2

积分
134
金钱
123
HASS币
0
发表于 3 天前 | 显示全部楼层
努力学习,拷贝代码研究
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-10-6 08:40 , Processed in 0.057069 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表