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