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

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

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

  [复制链接]

0

主题

14

帖子

281

积分

中级会员

Rank: 3Rank: 3

积分
281
金钱
267
HASS币
0
发表于 2024-10-3 11:48:30 | 显示全部楼层
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

帖子

643

积分

高级会员

Rank: 4

积分
643
金钱
596
HASS币
0
发表于 2024-10-3 12:16:09 | 显示全部楼层
好啊,这个,也需要
回复

使用道具 举报

0

主题

11

帖子

140

积分

注册会员

Rank: 2

积分
140
金钱
129
HASS币
0
发表于 2024-10-3 14:07:24 | 显示全部楼层
努力学习,拷贝代码研究
回复

使用道具 举报

0

主题

10

帖子

74

积分

注册会员

Rank: 2

积分
74
金钱
64
HASS币
0
发表于 2024-10-8 09:55:30 | 显示全部楼层
学习一下,正需要
回复

使用道具 举报

43

主题

327

帖子

2788

积分

论坛DIY达人

积分
2788
金钱
2456
HASS币
50
发表于 2024-10-8 15:57:34 | 显示全部楼层
本帖最后由 shadowba 于 2024-10-8 15:59 编辑
leung 发表于 2024-10-2 17:05
没搞懂MOS管怎么驱动PWM风扇,能上个原理图吗?
意思是风扇4Pin PWM控制线不用?ESP32的PWM输出接到mos管 ...
大致是下面的意思,二极管是防止mos管击穿烧毁单片机的,电阻串一个50欧左右的即可
微信图片_20241008155702.png
回复

使用道具 举报

16

主题

178

帖子

938

积分

高级会员

Rank: 4

积分
938
金钱
760
HASS币
0
发表于 2024-10-9 15:45:06 | 显示全部楼层
shadowba 发表于 2024-10-8 15:57
大致是下面的意思,二极管是防止mos管击穿烧毁单片机的,电阻串一个50欧左右的即可

...

麻烦帮我看看这样设计有问题不?十分感谢
微信图片_20241009153828.png
回复

使用道具 举报

15

主题

416

帖子

2808

积分

金牌会员

Rank: 6Rank: 6

积分
2808
金钱
2392
HASS币
0
发表于 2024-10-9 20:39:21 | 显示全部楼层
本帖最后由 george65 于 2024-10-9 22:59 编辑

找到原因了  這幾行沒抄到
substitutions:
  device_name: "fan01s"
  friendly_name: "fan01s"
  comment: "fan01s"
  version: "1.0.0"
  speed_low: "20"
  speed_med: "50"
  speed_full: "100"

esphome:
  name: "${friendly_name}"
  friendly_name: "${friendly_name}"
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev
  on_boot:
    then:
      - delay: 3s
      - fan.turn_on:
          id: ${friendly_name}_fan
      - delay: 3s
      - fan.turn_on:
          id: ${friendly_name}_fan
          speed: "${speed_low}"


--------------------------------------
請問出現下列錯誤要怎麼修改?

Failed config
button.template: [source /config/esphome/esphome-web-8ed3a0.yaml:117]
  platform: template
  icon: mdi:fan-speed-1
  name: ${device_name} Low
  on_press:
    - fan.turn_on:
        id: esp01s_fan_fan
        
        Expected integer, but cannot parse ${speed_low} as an integer.
        speed: ${speed_low}
回复

使用道具 举报

0

主题

3

帖子

90

积分

注册会员

Rank: 2

积分
90
金钱
87
HASS币
0
发表于 2024-10-10 09:32:59 | 显示全部楼层
高手,这是高手!
回复

使用道具 举报

0

主题

12

帖子

124

积分

注册会员

Rank: 2

积分
124
金钱
112
HASS币
0
发表于 2024-10-10 10:58:24 | 显示全部楼层
回复

使用道具 举报

3

主题

132

帖子

1260

积分

金牌会员

Rank: 6Rank: 6

积分
1260
金钱
1128
HASS币
0
发表于 2024-10-10 11:06:45 | 显示全部楼层
不错不错,回头找时间复刻一个
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 14:00 , Processed in 0.057411 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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