Hi,
I have a 3-channel PWM generator for controlling fans. It supports to set the Duty values via UART TX/RX, so I added an ESP32 to it. I can set the value with uart.write.
I played with the fan component code, but I am stuck at basic steps cince I cannot retrieve the value I changed in the UI.
My code:
uart:
#- id: uart_1
tx_pin: GPIO08
rx_pin: GPIO10
baud_rate: 9600
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: “\n”
sequence:
- lambda: UARTDebug::log_string(direction, bytes);output:
- platform: template
id: Ruck_125L_EC_Output
type: float
write_action:
- uart.write: ‘D1:099’ # for testing
fan:
- platform: speed
name: Ruck 125L EC
id: Ruck_125L_EC
output: Ruck_125L_EC_Output
on_speed_set:
- uart.write: !lambda |-
char buf[256];
sprintf(buf, “D1:0%d”, Ruck_125L_EC->speed));
return ((std::string) buf).c_str();
I dont know how to get the value so I tried above code, but get an error int the lamba part:
“/config/esphome/m5stampc3u-b.yaml:63:39: error: could not convert ‘std::__cxx11::basic_string(((const char*)((char*)(& buf))), std::allocator()).std::__cxx11::basic_string::c_str()’ from ‘const char*’ to ‘std::vector’”
The fan component entity is visible and I get the on_speed_set event. just dont know how the get the value…
Any hellp is highly appreciated
best geetings
EDIT:
I manged to get the value with this code:
- platform: speed
name: Ruck 125L EC
id: Ruck_125L_EC
output: Ruck_125L_EC_Output
speed_count: 100
on_speed_set:
- uart.write: !lambda |-
char buf[256];
sprintf(buf, “D1:0%d”, Ruck_125L_EC->speed);
std::string s = buf;
return (std::vector( s.begin(), s.end()));
Can anyone help me how to get a slider? Like in the first picture on the fan component documentation.