Hi, I have an issue that I can not find the solution to.
I am/was using a CT_Clamp on my ESP32 board to track the power usage of my washing machine. I wanted to add a energy monitor and while changing it said that a new bootloader could be installed if connecting the device with a cable.
I updated the device with a cable (APRIL Release) and since then all the logic that before showed 0A or 0W just went crazy and always show a high A value (between 23A or 30A). So that means the tracking is completely broken.
I have no idea what else to check, I changed the ESP32 device just in case and I could reproduce the exact same issue with the new board. I attached the code.
I though maybe the new CPU frequency was to blame but setting it to 160MHZ does not change anything.
Also tried using an old version ESP32 version and the problem still happens (although I supose that IF the problem is the bootloader then an old version does not fix it?)
The issue sounds kind of similar to ads1118 measures bad values after upgrade to 2025.7.0, but that is an old issue and the board was working before.
Does anyone know what can be the problem and or how could I resolve it, fix it or debug it?
Thanks
The config:
esphome:
name: esp-energy-monitor-technickraum
friendly_name: Energy Monitor Technickraum
devices:
- id: home_main_power_meter
name: "Home Main Power Meter"
on_boot:
priority: -100
then:
- lambda: |-
id(_glbl_timeout_ticks) = 0;
id(_timer_tick).stop();
id(washmachine_state).publish_state("Apagada");
- delay: 10s
esp32:
board: esp32dev
framework:
type: arduino
advanced:
minimum_chip_revision: "3.0"
substitutions:
sml_totals_throttle_time: "60s"
sml_uart_rx_pin: GPIO3
sml_uart_tx_pin: GPIO1
packages:
sml_meter_config: !include common/sml-meter.yaml
logger:
baud_rate: 0
level: WARN
logs:
esp-idf: ERROR
# sml: DEBUG
# adc: WARN
ct_clamp: WARN
sensor: WARN
# template.sensor: WARN
api:
encryption:
key: "edited"
ota:
- platform: esphome
password: "edited"
wifi:
ssid: !secret iot_ssid
password: !secret iot_password_for_trusted_devices
manual_ip:
static_ip: 10.69.61.3
gateway: 10.69.61.1
subnet: 255.255.255.0
use_address: esp-energy-monitor-technickraum.local
ap:
ssid: "Energy-Monitor-Technickraum"
password: "edited"
captive_portal:
globals:
- id: glbl_relay_latched
type: bool
restore_value: yes
initial_value: "true"
- id: glbl_timeout_length_ticks
type: int
restore_value: yes
initial_value: "300"
- id: _glbl_timeout_ticks
type: int
restore_value: no
initial_value: "0"
script:
- id: on_timer_end
mode: single
then:
- select.set:
id: washmachine_state
option: "Esperando"
- logger.log: "on_timer_end: washmachine_state should be Esperando!"
- id: on_timer_stop
mode: single
then:
- lambda: |-
id(_timer_tick).stop();
id(_glbl_timeout_ticks) = 0;
// ESP_LOGD("script.on_timer_stop", "_timer_tick now stopped and _glbl_timeout_ticks is %d", id(_glbl_timeout_ticks));
- id: _timer_tick
mode: queued
then:
- delay: 1s
- lambda: |-
id(_glbl_timeout_ticks) += 1;
if (id(_glbl_timeout_ticks) >= id(glbl_timeout_length_ticks)) {
id(on_timer_end).execute();
// ESP_LOGD("lambda._timer_tick", "_glbl_timeout_ticks is >= glbl_timeout_length_ticks %d >= %d ", id(_glbl_timeout_ticks), id(glbl_timeout_length_ticks));
id(_glbl_timeout_ticks) = 0;
id(_timer_tick).stop();
// ESP_LOGD("lambda._timer_tick", "_timer_tick now stopped!");
return;
}
// ESP_LOGD("lambda._timer_tick", "_glbl_timeout_ticks is < glbl_timeout_length_ticks %d < %d ", id(_glbl_timeout_ticks), id(glbl_timeout_length_ticks));
id(_timer_tick).execute();
sensor:
- platform: template
name: Countdown Value
id: countdown_value
icon: mdi:timer
accuracy_decimals: 0
update_interval: 1s
lambda: |-
return id(_glbl_timeout_ticks);
- platform: adc
pin: GPIO34
id: adc_sensor_wash_machine
attenuation: 12db
accuracy_decimals: 2
internal: true
update_interval: 2s
- platform: ct_clamp
sensor: adc_sensor_wash_machine
id: washmachine_current
name: "Washmachine Current"
unit_of_measurement: "A"
device_class: current
sample_duration: 1200ms
update_interval: 2s
filters:
- clamp:
min_value: 0
max_value: 30
- calibrate_linear:
method: exact
datapoints:
- 0 -> 0
- 0.004 -> 0
- 0.006 -> 0
- 0.007 -> 0
- 0.010 -> 0
- 0.014 -> 0.133
- 0.1052 -> 2.9
- 0.147 -> 4.03
- 0.21 -> 5.61
- 0.2995 -> 8
- lambda: |-
if (x < 0.055) {
// ESP_LOGD("lambda", "Sent 0 for %f", x);
return 0;
} else {
// ESP_LOGD("lambda", "Sent Real value %f", x);
return x;
}
- platform: template
name: "Washmachine Current (Round)"
id: washmachine_current_round
unit_of_measurement: "A"
device_class: current
lambda: |-
return id(washmachine_current).state;
update_interval: 2s
filters:
- median:
window_size: 15
send_every: 7
send_first_at: 5
- quantile:
window_size: 60
send_every: 30
send_first_at: 10
quantile: .9
on_value:
then:
lambda: |-
// ESP_LOGD("washmachine_current_round", "Value is %f", x);
if (id(washmachine_state).current_option() == "Esperando") {
// ESP_LOGD("washmachine_current_round", "We do not change the Esperando state");
return;
}
if (x < 0.10) {
if (id(washmachine_state).current_option() == "Apagada") {
return;
}
if (id(washmachine_state).current_option() == "Lavando" || id(washmachine_state).current_option() == "Calentando Agua") {
if (!id(_timer_tick).is_running()) {
id(_timer_tick).execute();
}
return;
}
id(washmachine_state).publish_state("Apagada");
return;
}
if (id(_timer_tick).is_running()) {
id(on_timer_stop).execute();
}
if (x >= 0.10 && x <= 7) {
id(washmachine_state).publish_state("Lavando");
return;
}
if (x > 7) {
id(washmachine_state).publish_state("Calentando Agua");
return;
}
// ESP_LOGE("washmachine_current_round", "We are outside of the valid ifs!");
id(washmachine_state).publish_state("Apagada");
- platform: template
name: "Washmachine Power"
id: washmachine_power
unit_of_measurement: "W"
device_class: power
state_class: measurement
lambda: |-
return id(washmachine_current).state * 230;
update_interval: 2s
- platform: template
name: "Washmachine Power Round"
id: washmachine_power_round
unit_of_measurement: "W"
device_class: power
state_class: measurement
update_interval: 60s
lambda: |-
return id(washmachine_current_round).state * 230;
# - platform: integration
# name: "Washmachine Energy"
# sensor: washmachine_power
# time_unit: h
# unit_of_measurement: "kWh"
# device_class: energy
# state_class: total_increasing
# accuracy_decimals: 3
# restore: false
# - platform: integration
# name: "Washmachine Energy Round"
# sensor: washmachine_power_round
# time_unit: h
# unit_of_measurement: "kWh"
# device_class: energy
# state_class: total_increasing
# accuracy_decimals: 3
# restore: false
select:
- platform: template
name: "Washmachine State"
id: washmachine_state
icon: "mdi:washing-machine"
options:
- "Apagada"
- "Calentando Agua"
- "Lavando"
- "Esperando"
optimistic: true
restore_value: true
initial_option: "Apagada"