mattlward
(Matt Ward)
February 1, 2025, 2:19am
1
I have a slider that controls a PWM fan speed. If I go all the way to zero, the fan may not start. I have found that about 15% is the minimum that I can use. Ideally the bottom number would be about 35…
output:
- platform: ledc
id: apple_pwm_speed
pin: GPIO27
# 25KHz is standard PWM PC fan frequency, minimises buzzing
frequency: "25000 Hz"
min_power: 15%
max_power: 100%
Hello. Please format your code.
Spaces at the beginning of the line are critical in yaml, and people trying to help you may want to copy your code so that they can try it out themselves, so please format it correctly when you are posting.
Use the preformatted text tool (</> in the edit post toolbar). If it is not immediately visible, it will be in the cogwheel menu.
[Code_format]
Alternatively you can use three backticks (the key is on the far left, 2nd row on en keyboards) on their own line above and below the code. That i…
mattlward
(Matt Ward)
February 1, 2025, 5:32pm
3
I did but I used the wrong darn tick.
Karosm
(Karosm)
February 1, 2025, 6:47pm
4
min_power: 0.15
will limit the output to >15%, but where is the slider coming from?
mattlward
(Matt Ward)
February 1, 2025, 7:12pm
5
I assume from this code block. As the name is Fan Speed. It seems to me that ESPHome wants to add the slider since it is a PWM control. I am also trying to figure out how to remove the on/off switch as I am not using a relay and turning it off does not stop the fan and I am ok with that. The noctua fan is so quite at 15% that I do not mind it running at all.
fan:
- platform: speed
name: "Fan speed"
output: apple_pwm_speed
id: fanpwm
Karosm
(Karosm)
February 1, 2025, 7:22pm
6
That wasn’t present on your first post.
What if you post your whole code.
Most of people don’t like to guess here.
This would be the most minimalistic control of pwm with slider limited to min.15%:
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;"
output:
- platform: ledc
id: apple_pwm_speed
pin: GPIO27
frequency: 25000Hz
mattlward
(Matt Ward)
February 1, 2025, 8:04pm
7
Sorry, here is my complete code so far… And yes, I suck at writing yaml, but I am good at hardware.
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
- fan.turn_on: fanpwm
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: !secret wifi_ap_password
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
# 25KHz is standard PWM PC fan frequency, minimises buzzing
frequency: "25000 Hz"
min_power: 15%
max_power: 100%
fan:
- platform: speed
name: "Fan speed"
output: apple_pwm_speed
id: fanpwm
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"
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
switch:
- platform: restart
name: "Restart"
Karosm
(Karosm)
February 1, 2025, 8:08pm
8
Much better.
Replace the fan and output components with the code I posted and try if you like it better.
mattlward
(Matt Ward)
February 1, 2025, 8:17pm
9
So, I did and I have a new entry in the front end which is correct. But, I still have the old entry and switch that I do not want.
Karosm
(Karosm)
February 1, 2025, 8:19pm
10
I wrote, replace the fan and output componets…
You need to delete the fan component on your code
mattlward
(Matt Ward)
February 1, 2025, 8:31pm
11
I did, but it would not compile. I had to also remove the command to force it on at boot. So, now it does not start at boot.
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
# - light.turn_on: apple_pwm_speed
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: !secret wifi_ap_password
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;"
#fan:
# - platform: speed
# name: "Fan speed"
# output: apple_pwm_speed
# id: fanpwm
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"
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
switch:
- platform: restart
name: "Restart"
mattlward
(Matt Ward)
February 1, 2025, 8:32pm
12
It did indeed clean up the panel!
mattlward
(Matt Ward)
February 1, 2025, 8:35pm
13
I honestly figured that pointing the on_boot at the ledc would work, it does not. Compile errors. I also tried light.turn_on. It seems that when I take out the fan: section the ability to turn on a boot also goes away. So, what I have been able to figure out is that I have to move the slider just up one point to start the fan after boot. So, it appears something is telling the PWM not to output anything at boot.
INFO ESPHome 2024.12.4
INFO Reading configuration /config/esphome/esphome-web-8281ec.yaml...
Failed config
esphome: None
name: apple-fan
friendly_name: Apple Fan Controller
name_add_mac_suffix: False
project:
name: Apple.temperature_control
version: apple-fan-v.1
on_boot:
priority: 800
then:
- if:
condition:
api.connected: {}
then:
- logger.log: API is connected! Now we can trigger what we want!
else:
- delay: 1s
-
Unable to find action with the name 'ledc.turn_on'.
ledc.turn_on: apple_pwm_speed
Karosm
(Karosm)
February 1, 2025, 8:56pm
14
The syntax is:
- output.turn_on: apple_pwm_speed
and if you want to set level:
- output.set_level:
id: apple_pwm_speed
level: 0.5 # 50% pwm speed
mattlward
(Matt Ward)
February 1, 2025, 9:16pm
15
That was what I was missing… yaml will yet drive me to drinking or kill me.
Works perfectly!
Karosm
(Karosm)
February 1, 2025, 9:21pm
16
drive you drinking sounds ok, drinking while driving might kill you though…
Nice it worked!
mattlward
(Matt Ward)
February 1, 2025, 9:37pm
17
Thanks a bunch, hate to rely on the community. I am learning, but have a long way to go,
Karosm
(Karosm)
February 1, 2025, 9:52pm
18
We all have… Community is great.