cpw7922
(Chris)
December 5, 2024, 4:00pm
1
I am trying to write this code to filter out any small values from a power meter that are mostly just noise and not actual power usage. Maybe there’s a better way to do it?
- &small
lambda:
if (x > 10) {
return (x * 1);
} else {
return (x * 0);
}
but when I go to install I get this error. Any idea what I’m doing wrong?
Invalid key "{'lambda': 'if (x > 10) { return (x * 1); } else { return (x * 0); }'}" (not hashable)
in "/config/energy-monitor-v2.yaml", line 114, column 5
RonnieLast
(Last of the Ronnies)
December 5, 2024, 4:05pm
2
Hi, have a look at the filter options:
The ESP32 ADC is noisy and or maybe it is to do with the software implementation… Anyhow you can get good data with allot of filtering…
In this example I use the same code to measure voltage with a voltage sense transformer:
- platform: ct_clamp #current sensor component can be used to measure voltage
sensor: voltage_sensor_pin
name: "Voltage"
unit_of_measurement: V
device_class: voltage
id: voltage
sample_duration: 500ms
update_interval: 2000ms
accuracy_decim…
cpw7922:
- &small
^^ not sure what this one mean.
Can You provide more background - may be whole sensor config !?
IMHO not a lambda is a cause, but it usage.
Here’s how a commercial company does it.
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: diagnostic
device_class: ""
- platform: cse7766
current:
name: "Current"
filters:
- throttle_average: ${sensor_update_interval}
- lambda: if (x < 0.060) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected
on_value_range:
- above: ${current_limit}
then:
- switch.turn_off: relay
voltage:
name: "Voltage"
filters:
- throttle_average: ${sensor_update_interval}
1 Like
cpw7922
(Chris)
December 6, 2024, 9:48pm
5
Thanks for the help everyone but turns out it was an error with where I was trying to use the filter instead of the lambda code itself.
For more info, I was trying to add an extra filter to this project and was adding the filter to portion where it copied the sensor data
- { platform: copy, name: "Dishwasher Power", source_id: cir3, filters: *throttle_avg, *small }
instead of where it was reading the CT Clamp
- { phase_id: phase_b, input: "1", power: { id: cir1, filters: [ *pos, multiply: 2, *small ] } }