Repository navigation
Description
It is connected to an ESP32, I am using ESPHome, and communication is via I2C. The code is as follows:
`
esphome:
name: esp01
friendly_name: ESP01
on_boot:
priority: -100
then:
- delay: 3s
- lambda: |-
// Sync curve ch1 on startup - Corrección de valor de fábrica
uint8_t reg = 0x11;
uint8_t curve = 0;
if (id(bus_a).write(${dimmerlink_addr}, ®, 1, false) == i2c::ERROR_OK) {
if (id(bus_a).read(${dimmerlink_addr}, &curve, 1) == i2c::ERROR_OK) {
auto call = id(dimming_curve_ch1).make_call();
// Si el valor es correcto (0, 1 o 2), lo aplicamos normalmente
if (curve == 0 || curve == 1 || curve == 2) {
switch (curve) {
case 0: call.set_option("LINEAR"); break;
case 1: call.set_option("RMS"); break;
case 2: call.set_option("LOG"); break;
}
call.perform();
ESP_LOGI("dimmerlink", "Synced curve ch1: %d", curve);
}
// Si lee un valor basura (como 50), forzamos el inicio en LINEAR (0)
else {
ESP_LOGW("dimmerlink", "Valor inválido detectado (%d). Forzando LINEAR (0) en Canal 1...", curve);
call.set_option("LINEAR");
call.perform(); // Esto activará el set_action de tu YAML y reescribirá el registro 0x11 con un 0
}
}
}
- delay: 100ms
- lambda: |-
// Sync curve ch2 on startup
uint8_t reg = 0x13;
uint8_t curve = 0;
if (id(bus_a).write(${dimmerlink_addr}, ®, 1, false) == i2c::ERROR_OK) {
if (id(bus_a).read(${dimmerlink_addr}, &curve, 1) == i2c::ERROR_OK) {
auto call = id(dimming_curve_ch2).make_call();
switch (curve) {
case 0: call.set_option("LINEAR"); break;
case 1: call.set_option("RMS"); break;
case 2: call.set_option("LOG"); break;
}
call.perform();
ESP_LOGI("dimmerlink", "Synced curve ch2: %d", curve);
}
}
`
`
select:
-
platform: template
name: "Curva dimmer ch1"
id: dimming_curve_ch1
icon: "mdi:chart-bell-curve"
options:- "LINEAR"
- "RMS"
- "LOG"
initial_option: "LINEAR"
optimistic: true
restore_value: true
set_action: - lambda: |-
uint8_t curve = 0;
if (x == "RMS") curve = 1;
else if (x == "LOG") curve = 2;
uint8_t data[2] = {0x11, curve};
id(bus_a).write(${dimmerlink_addr}, data, 2, true);
ESP_LOGI("dimmerlink", "Curva ch1: %s", x.c_str());
-
platform: template
name: "Curva dimmer ch2"
id: dimming_curve_ch2
icon: "mdi:chart-bell-curve"
options:- "LINEAR"
- "RMS"
- "LOG"
initial_option: "LINEAR"
optimistic: true
restore_value: true
set_action: - lambda: |-
uint8_t curve = 0;
if (x == "RMS") curve = 1;
else if (x == "LOG") curve = 2;
uint8_t data[2] = {0x13, curve};
id(bus_a).write(${dimmerlink_addr}, data, 2, true);
ESP_LOGI("dimmerlink", "Curva ch2: %s", x.c_str());
`
Register 0x13 works fine, but register 0x11 holds a value of 50, no matter how hard you try to write to it. This is my log:
[21:05:28.226][W][dimmerlink:034]: Valor inválido detectado (50). Forzando LINEAR (0) en Canal 1...
[21:05:28.234][I][dimmerlink:772]: Curva ch1: LINEAR
[21:05:28.348][I][dimmerlink:792]: Curva ch2: LINEAR
[21:05:28.351][I][dimmerlink:095]: Synced curve ch2: 0
[21:05:28.363][S][select]: 'Curva dimmer ch1' >> LINEAR
[21:05:28.364][S][binary_sensor]: 'Status' >> ON
[21:05:28.364][S][select]: 'Curva dimmer ch2' >> LINEAR
Activity