I am sure that I am doing something wrong, but it just has not dawned on me yet. I am trying to set my fan speed based on the sht31 temperature reading. I removed the conversion to degrees F assuming that was the issue and it is not. This fan is intended to never turn off during operation. The setpoint should have the fan running at full speed, instead it is running at the minimum speed designated and I never see a log entry indicating it should change speed. I know I am doing something very simple wrong.
substitutions:
name: apple-fan
friendly_name: Apple Fan Controller
devicename: apple-fan
esphome_platform: esp32
esphome_board: esp32dev
esphome_project_name: "Apple.temperature_control"
esphome_project_version: "apple-fan-v.1"
esphome:
name: apple-fan
friendly_name: Apple Fan Controller
name_add_mac_suffix: false
project:
name: $esphome_project_name
version: $esphome_project_version
on_boot:
# Power up fan at boot
priority: 800
then:
- if:
condition:
api.connected: null
then:
- logger.log: API is connected! Now we can trigger what we want!
else:
- delay: 1s
- output.set_level:
id: apple_pwm_speed
level: 0.25 # 25% pwm speed until temp is taken
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
# Allow Over-The-Air updates
ota:
- platform: esphome
wifi:
domain: .home
ssid: !secret wifi_ssid
password: !secret wifi_password
# Set up a wifi access point
ap:
ssid: "${friendly_name}"
password: "12345678"
dashboard_import:
package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
import_full_config: true
web_server:
include_internal: True
status_led:
pin:
number: GPIO2
inverted: false
i2c:
sda: GPIO21
scl: GPIO22
frequency: 100kHz
output:
- platform: ledc
id: apple_pwm_speed
pin: GPIO27
frequency: 25000Hz
number:
- platform: template
name: "Pwm Fan Slider"
id: slider
min_value: 15
max_value: 100
step: 1
optimistic: true
set_action:
then:
- output.set_level:
id: apple_pwm_speed
level: !lambda "return x/100;"
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:
- platform: sht3xd
temperature:
name: "Apple Internal Temperature"
id: sht30t
internal: false
# filters:
# - lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
on_value_range:
- above: 20.0
then:
- logger.log: "Set fan level 100 over 20"
- output.set_level:
id: apple_pwm_speed
level: 100%
- above: 18.0
then:
- logger.log: "Set fan level 66 over 18"
- output.set_level:
id: apple_pwm_speed
level: 66%
- above: 17.0
then:
- logger.log: "Set fan level 33 over 17F"
- output.set_level:
id: apple_pwm_speed
level: 33%
- below: 17.0
then:
- logger.log: "Set fan level 0 under 17F"
- output.set_level:
id: apple_pwm_speed
level: 15%
humidity:
name: "Apple Internal Humidity"
id: sht30h
internal: false
address: 0x44
update_interval: 30s
# Fan Speed
- platform: pulse_counter
pin:
number: GPIO25
mode:
input: true
pullup: true
name: PWM Fan RPM
id: fan_pulse
unit_of_measurement: 'RPM'
internal: false
filters:
- multiply: 0.5
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
update_interval: 3s
# Send WiFi signal strength & uptime to HA
- platform: wifi_signal
name: $friendly_name WiFi Strength
update_interval: 60s
- platform: uptime
name: $friendly_name Uptime Human
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();
switch:
- platform: restart
name: "Restart"
I have made the requested changes, the darn thing is just flat ignoring the fan speed setting… Also no log entry ever and stuck at 670RPM. Is using a percentage a problem, but I would think it would still log but not set the speed. Converting the percent to decimal did not fix it either.
substitutions:
name: apple-fan
friendly_name: Apple Fan Controller
devicename: apple-fan
esphome_platform: esp32
esphome_board: esp32dev
esphome_project_name: "Apple.temperature_control"
esphome_project_version: "apple-fan-v.1"
esphome:
name: apple-fan
friendly_name: Apple Fan Controller
name_add_mac_suffix: false
project:
name: $esphome_project_name
version: $esphome_project_version
on_boot:
# Power up fan at boot
priority: 800
then:
- if:
condition:
api.connected: null
then:
- logger.log: API is connected! Now we can trigger what we want!
else:
- delay: 1s
- output.set_level:
id: apple_pwm_speed
level: 0.25 # 25% pwm speed until temp is taken
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
# Allow Over-The-Air updates
ota:
- platform: esphome
wifi:
domain: .home
ssid: !secret wifi_ssid
password: !secret wifi_password
# Set up a wifi access point
ap:
ssid: "${friendly_name}"
password: "12345678"
dashboard_import:
package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
import_full_config: true
web_server:
include_internal: True
status_led:
pin:
number: GPIO2
inverted: false
i2c:
sda: GPIO21
scl: GPIO22
frequency: 100kHz
output:
- platform: ledc
id: apple_pwm_speed
pin: GPIO27
frequency: 25000Hz
number:
- platform: template
name: "Pwm Fan Slider"
id: slider
min_value: 15
max_value: 100
step: 1
optimistic: true
set_action:
then:
- output.set_level:
id: apple_pwm_speed
level: !lambda "return x/100;"
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:
- platform: sht3xd
temperature:
name: "Apple Internal Temperature"
id: sht30t
internal: false
# filters:
# - lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
on_value_range:
- above: 20.0
then:
- logger.log: "Set fan level 100 over 20"
- output.set_level:
id: apple_pwm_speed
level: 100%
- above: 18.0
below: 20
then:
- logger.log: "Set fan level 66 over 18"
- output.set_level:
id: apple_pwm_speed
level: 66%
- above: 17.0
below: 18
then:
- logger.log: "Set fan level 33 over 17F"
- output.set_level:
id: apple_pwm_speed
level: 33%
- below: 16.9
then:
- logger.log: "Set fan level 0 under 17F"
- output.set_level:
id: apple_pwm_speed
level: .15
humidity:
name: "Apple Internal Humidity"
id: sht30h
internal: false
address: 0x44
update_interval: 30s
# Fan Speed
- platform: pulse_counter
pin:
number: GPIO25
mode:
input: true
pullup: true
name: PWM Fan RPM
id: fan_pulse
unit_of_measurement: 'RPM'
internal: false
filters:
- multiply: 0.5
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
update_interval: 3s
# Send WiFi signal strength & uptime to HA
- platform: wifi_signal
name: $friendly_name WiFi Strength
update_interval: 60s
- 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();
switch:
- platform: restart
name: "Restart"
Logs showing fan speed and temp/humidity.
[18:26:50][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1361.82 pulses/min
[18:26:50][D][sensor:093]: 'PWM Fan RPM': Sending state 680.90790 RPM with 2 decimals of accuracy
[18:26:50][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1339.11 pulses/min
[18:26:50][D][sensor:093]: 'PWM Fan RPM': Sending state 669.55365 RPM with 2 decimals of accuracy
[18:26:50][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1340.89 pulses/min
[18:26:50][D][sensor:093]: 'PWM Fan RPM': Sending state 670.44696 RPM with 2 decimals of accuracy
[18:26:51][D][sht3xd:097]: Got temperature=21.45°C humidity=38.40%
[18:26:51][D][sensor:093]: 'Apple Internal Temperature': Sending state 21.44846 °F with 1 decimals of accuracy
[18:26:51][D][sensor:093]: 'Apple Internal Humidity': Sending state 38.39933 % with 1 decimals of accuracy
[18:26:53][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1358.19 pulses/min
[18:26:53][D][sensor:093]: 'PWM Fan RPM': Sending state 679.09454 RPM with 2 decimals of accuracy
[18:26:56][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1340.45 pulses/min
[18:26:56][D][sensor:093]: 'PWM Fan RPM': Sending state 670.22339 RPM with 2 decimals of accuracy
[18:26:59][D][pulse_counter:181]: 'PWM Fan RPM': Retrieved counter: 1358.64 pulses/min
[18:26:59][D][sensor:093]: 'PWM Fan RPM': Sending state 679.32068 RPM with 2 decimals of accuracy
If all indentations are correct, I really don’t know what’s wrong…
Are you getting any errors when you update your code?
Try if it’s triggering on any value:
Only explanation I can think of is from documentation:
“This trigger will only trigger when the new value is inside the range and the previous value was outside the range.”
So if there is no change on the values, it doesn’t trigger at all?
Try to manipolate the temperature to output a value that is in different range.
If nothing else works, go with on_value automation and make if-else conditions to change the speed.
I’m done for tonight, good luck!
So, it is working… I think I was stuck in a window on boot and therefore the fan speed did not change to the expected speed. Once I raised the temperature of the sensor to the next window the automation took over and it has been working properly. I see no way to force a run through of the conditions at first boot to get the fan speed into regulation…