Hi,
I do have some issues I was unable to solve using my normal routine.
My new ESPHome project is a fan controller (PWM) which not only will be included in my Home Assistant, but will also have a local rotary encoder two change the speed. So far so good. Rotary encoder and pwm is working, but I face an issue with changing speed with the rotary encoder.
esphome:
name: fan-controller
esp8266:
board: d1_mini
# Enable logging
logger:
switch:
- platform: restart
name: Restart
binary_sensor:
# Reports if this device is Connected or not
- platform: status
name: Status
# globals
globals:
- id: global_pwmfan0
type: float
restore_value: no
initial_value: '0.0'
- id: global_pwmfan1
type: float
restore_value: no
initial_value: '0.0'
- id: global_pwmfan2
type: float
restore_value: no
initial_value: '0.0'
- id: global_pwmfan3
type: float
restore_value: no
initial_value: '0.0'
# fan
output:
- platform: esp8266_pwm
pin: D5
frequency: 25000 Hz
id: pwmfan0
- platform: esp8266_pwm
pin: D6
frequency: 25000 Hz
id: pwmfan1
- platform: esp8266_pwm
pin: D7
frequency: 25000 Hz
id: pwmfan2
- platform: esp8266_pwm
pin: D8
frequency: 25000 Hz
id: pwmfan3
fan:
- platform: speed
output: pwmfan0
name: Fan 0
- platform: speed
output: pwmfan1
name: Fan 1
- platform: speed
output: pwmfan2
name: Fan 2
- platform: speed
output: pwmfan3
name: Fan 3
# rotary encoder
sensor:
- platform: rotary_encoder
name: "Rotary Encoder"
pin_a: D1
pin_b: D2
on_clockwise:
- logger.log: "Increase fan speed"
- lambda: |-
if( id(global_pwmfan0) < 1 ) {
id(global_pwmfan0) += 0.05;
id(pwmfan0).set_level(return id(global_pwmfan0));
}
- logger.log:
format: "Value %d"
args: ['return id(global_pwmfan0)']
on_anticlockwise:
- logger.log: "Decrease fan speed"
- lambda: |-
if( id(global_pwmfan0) > 0 ) {
id(global_pwmfan0) -= 0.05;
id(pwmfan0).set_level(return id(global_pwmfan0));
}
# Reports IP
text_sensor:
- platform: wifi_info
ip_address:
name: IP
# Enable Home Assistant API
api:
encryption:
key: "WicZuNX02FLn5StHBFhb+vGtxAFpwtIhluPMbv8STKo="
ota:
password: "871a922f9e1c283b3d6e1354a42eb179"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Fan-Controller Fallback Hotspot"
password: "fizLVmJSOGnW"
captive_portal:
To be able to use the rotary encoder and the home assistant interface I will have to rely on a global variable as far as I know, because I cannot get the current level of the pwm. So my lambda for the level seems to be the problem. Does some have an idea whats wrong?
de-/increasing the global variable with the nob is no issue also changing speed in HA, but the global variable does not change the PWM level.
Any help is very much apprechiated.
BR,
bqzero