Posts: 21
Threads: 3
Joined: Dec 2023
Reputation:
0
(01-07-2024, 11:10 AM)admin Wrote: thanks for sharing your result. maybe you can also post this problem to ESPHome forum.
Some feedback.
I was able to solve my "low SPS" problem as described above, by doing the following:
- set update interval to never for all sensors
- use interval and loop through sensors and add delay manually
This fixes the issue that it switches inputs on the multiplexer in an uncontrolled matter.
Code: interval:
- interval: 10s
then:
- lambda: |-
id(Measured_Current_01).update();
# # ESP_LOGD("custom", "Measured Current-1: %f", id(ai1).state);
- delay: 625ms
- lambda: |-
id(Measured_Current_02).update();
# # ESP_LOGD("custom", "Measured Current-2: %f", id(Measured_Current_2).state);
- delay: 625ms
- lambda: |-
id(Measured_Current_03).update();
# # ESP_LOGD("custom", "Measured Current-3: %f", id(Measured_Current_3).state);
- delay: 625ms
- lambda: |-
id(Measured_Current_04).update();
# # ESP_LOGD("custom", "Measured Current-4: %f", id(Measured_Current_4).state);
- delay: 625ms
=> I update my values every 10 seconds, in sequence.
I also have better results when using calibrate_linear with method "exact" instead of the default least_squares.
Used a bunch of devices and combinations with power factor 1 (resistive loads) for callibration.
sample duration of 500ms works well for me.
Code: - platform: ct_clamp
sensor: ai16
id: Measured_Current_16
name: "Measured Current-16"
sample_duration: 500ms
update_interval: never
accuracy_decimals: 5
filters:
- calibrate_linear:
method: exact
datapoints:
- 0 -> 0
- 0.00231 -> 0
- 0.00348 -> 0.063
- 0.00603 -> 0.170
- 0.00642 -> 0.180
- 0.00858 -> 0.252
- 0.01343 -> 0.407
- 0.02111 -> 0.653
- 0.02277 -> 0.713
- 0.05721 -> 1.775
- 0.07191 -> 2.243
- 0.07719 -> 2.398
- 0.14918 -> 4.650
- 0.19534 -> 6.100
- 0.28517 -> 8.960
- 0.47080 -> 14.550
Did this for all 16 clamps by putting them all on the same wire when doing the measurements.
It's much less jumpy then before. Still struggle to really measure low power, but that must be because of the overall accuracy.
Posts: 6,726
Threads: 848
Joined: Oct 2020
Reputation:
163
thanks for share the result.
Posts: 1
Threads: 0
Joined: Feb 2024
Reputation:
0
Thanks for the good idea posted above, nickdd.
I took that concept and wrote the nodejs code below to generate the sensor section of my yaml, it is working pretty well for me.
This code generates the sensor and interval yaml blocks, I combine it with the base example provided by Kincony for the rest of the yaml.
Code: const fs = require('fs');
const entries = [
[[1,2],50,"power_downstairs_hvac_compressor","Downstairs HVAC Compressor"],
[[3],20,"power_garage_outlets_and_fridges","Garage Outlets and Fridges"],
[[4],20,"power_kitchen_fridge","Kitchen Fridge"],
// this inverter/compressor has a weird phantom load which registers as high idle current
// but since we don't measure true reactive power etc we need to just clip it.
// Seems to read true once turned on
[[5,6],50,"power_upstairs_hvac","Upstairs HVAC",{clamp_amps:1}],
[[7],50, "power_left_laundry","Left Laundry"],
[[8],20,"power_office_plugs","Office Plugs"],
[[9],20,"power_kitchen_plugs","Kitchen Plugs 1"],
[[10],20,"power_right_laundry","Right Laundry"],
[[11],20,"power_dishwasher","Dishwasher"],
[[12],20,"power_instant_hot_water_heater","Instant Hot Water Heater"],
[[13],20,"power_kitchen_plugs_2","Kitchen Plugs 2"],
];
let conf = `
sensor:
`;
let interval_conf = `
interval:
- interval: 10s
then:`;
for (let i=0;i<entries.length;i++) {
const entry = entries[i];
const ct_list = [];
const [ct_ids, CTAMPS, POWERID, POWERNAME, options={}] = entry;
for (let j=0;j<ct_ids.length;j++) {
const INDEX = ct_ids[j];
ct_list.push(`Measured_Current_${INDEX}`);
const ct_template = `
- platform: ct_clamp
sensor: ai${INDEX}
id: Measured_Current_${INDEX}
internal: true
sample_duration: 500ms
update_interval: never
accuracy_decimals: 5
filters: !include { file: inc/ct${CTAMPS}.yaml }`;
conf += ct_template;
const ct_interval_template = `
- lambda: |-
id(Measured_Current_${INDEX}).update();
- delay: 600ms`;
interval_conf += ct_interval_template;
}
const opts = Object.assign({
clamp_amps:0,
prefix: 'Power - ',
},options);
const power_template = `
- platform: template
id: ${POWERID}
name: "${opts.prefix}${POWERNAME}"
lambda: if (id(${ct_list[0]}).state < ${opts.clamp_amps}) { return 0; } return (${ct_list.map(r => 'id(' + r + ').state').join(' + ')}) * 120;
device_class: power
accuracy_decimals: 3
unit_of_measurement: 'W'
update_interval: never`
conf += power_template;
const power_interval_template = `
- lambda: |-
id(${POWERID}).update();
- delay: 25ms`;
interval_conf += power_interval_template;
}
console.log(conf.replace(/(\s*\n){2,}/gm,'\n'));
console.log(interval_conf.replace(/(\s*\n){2,}/gm,'\n'));
const this_code = fs.readFileSync(process.argv[1]).toString();
console.log("# generated by the following code:");
console.log(this_code.replaceAll(/^(.*)/gm,'#$1'));
My ct20.yaml contains this:
Code: - clamp:
min_value: 0
max_value: 20
- calibrate_linear:
method: exact # least_squares
datapoints:
- 0 -> 0
- 0.006 -> 0 # calibrated 20231213
- 0.016 -> 0.45 # calibrated 20231213
- 0.040 -> 1.23 # calibrated 20231213
- 0.146 -> 5.51 # calibrated 20231213
- 0.238 -> 7.60 # calibrated 20231213
- 0.340 -> 10.3 # calibrated 20231213
Posts: 6
Threads: 0
Joined: Feb 2024
Reputation:
0
@nickdd
I've set below values on `ct_clamp` sensors but I still get a lot of switches. My current setup is 10 clamp sensors.
Code: sample_duration: 500ms
update_interval: never
What about AI sensors (cd74hc4067)? What value do you have there?
Why such delay in interval section? Does it have something to do with sum of all delays and sampling duration vs 10s interval?
Can you share some more how you configured in YAML?
Posts: 21
Threads: 3
Joined: Dec 2023
Reputation:
0
(02-15-2024, 04:20 PM)sanurss Wrote: @nickdd
I've set below values on `ct_clamp` sensors but I still get a lot of switches. My current setup is 10 clamp sensors.
Code: sample_duration: 500ms
update_interval: never
What about AI sensors (cd74hc4067)? What value do you have there?
=> I never got it to work when using the update_interval statements. It works if you only use it for a couple of CT's, but at some point the switching starts and never got it to work.
Instead I use update_interval: never everywhere and poll manually instead.
Why such delay in interval section? Does it have something to do with sum of all delays and sampling duration vs 10s interval?
=> I just defined for myself that an update every 10 seconds for each CT sensor would be good enough and since there are 16 clamps it's just 10.000ms / 16 = 625 ms interval and I just poll each CT sequentially.
You can see it in the dashboard/logs that it just updates each sensor in order and so you have a continuous loop of updates every 625 ms
Can you share some more how you configured in YAML?
=> sure, I put my full config on dropbox, you can download it here:
https://www.dropbox.com/scl/fi/xy658ay1l...hpe9e&dl=1
Didn't have time yet to add the Watt calculations and since it doesn't offer the power factor I need to rethink what circuits I actually want to monitor.
Maybe I was a bit too quick to order and didn't know the M30 board was coming which would have been more suitable for what I wanted to do: measure house usage on different circuits, but since a lot of things are electronic devices like computers, tv's, ... the M16v2 only offers current measurement and so unable to calculate the real power/wattage usage like this.
Regards,
Nick
Posts: 6
Threads: 0
Joined: Feb 2024
Reputation:
0
02-16-2024, 11:55 AM
(This post was last modified: 02-16-2024, 11:58 AM by sanurss.)
@nickdd Thanks for sharing you config!
I think I will manage without Power Factor because I'm only charged for the real power, not apparent power, so real power is my main concern currently. But I first need to get it fully configured to confirm
Do you maybe know if updating current will trigger update of dependent cd74hc4067? It seems to do so...
Code: id(current_4).update();
# Clamp 4
- platform: cd74hc4067
id: ai4
number: 3
sensor: adc35
update_interval: never
- platform: ct_clamp
sensor: ai4
id: current_4
name: "Current 4" sample_duration: 500ms
update_interval: never
accuracy_decimals: 5
@admin
In your source code there's some part which I don't understand. Can you explain what does the "adc35"? Can I safely remove the "m16--AI-1" - seems to be leftover from M16 v1?
Code: - platform: adc
pin: 35
id: adc35
update_interval: never
attenuation: 11db
# - platform: adc
# name: "m16--AI-1"
# pin: 36
# id: adc36
# update_interval: 60s
# attenuation: 11db
# - platform: adc
# pin: 34
# name: "m16--AI-2"
# id: adc34
# update_interval: 60s
# attenuation: 11db
# - platform: adc
# pin: 39
# name: "m16--AI-3"
# id: adc39
# update_interval: 60s
# attenuation: 11db
And one more question: does it matter what maximum current I will use to calibrate the clamp? Let's say I have a water pump using 0.15 A and a 10A clamp (the smallest I could get). Should I calibrate up to 5-10A or just to 1-2 A will be ok?
Posts: 6,726
Threads: 848
Joined: Oct 2020
Reputation:
163
1. you can't remove ADC35, because we use this pin expand for 16CH input. ESP32 GPIO35 use for 74HC4067 chip. actually only cost ESP32 1 GPIO.
2. i think you can try to calibrate 5-10A firstly, then you can test with 0.15A.
Posts: 21
Threads: 3
Joined: Dec 2023
Reputation:
0
Same here: only charged for real power, but CT clamps measure apparent power so you do need a power factor correction to be able to define the real power usage.
for the calibration: I did many attempts and had the best results with changing the callibration method to "exact" https://esphome.io/components/sensor/#sensor-filter-calibrate-linear
With only a few callibration points for like 2A and 5A I found that the readings where too far off with smaller loads like a light bulb.
I think it may have to do with the attenuation setting of the ADC.
So I just gathered all resistive capacity loads I could get my hand on: 20W, 40W, 55W and 100W light bulbs. A hair dryer, some old electric heater and then combinations of those.
Did all the testing at once by putting all 16 CT's on 1 wire and took note of all the values for each test and put them in.
After adding the calibration values in the yaml, I retested with those loads to see if the readings were ok. only with "exact" I had quite ok values, not with the default setting.
Posts: 6
Threads: 0
Joined: Feb 2024
Reputation:
0
Quote:CT clamps measure apparent power
I hope I get the power factor rather stable for the loads I want to measure, but we'll see.
Quote:With only a few callibration points for like 2A and 5A I found that the readings where too far off with smaller loads like a light bulb.
That's what I was afraid to see. Good to know I need to find smaller resistive loads as well. My current lowest is around 0.65A but some loads I want to measure get down to 0.1A.
Quote:Did all the testing at once by putting all 16 CT's on 1 wire and took note of all the values for each test and put them in.
Wouldn't it be better to measure on actual wires in the walls? I believe the readings may be influenced by plenty of wires around in my fuse box.
Posts: 21
Threads: 3
Joined: Dec 2023
Reputation:
0
[quote pid="11787" dateline="1708112777"]
Quote:I hope I get the power factor rather stable for the loads I want to measure, but we'll see.
Was also my plan: will use an accurate socket power meter and read the power factor and then use this as a static value to calculate the power. Could work for always-on devices or devices with stable power factor.
But there are also quite a few devices for which the power factor varies greatly, especially when they are in standby or some low/medium/high mode (like my ventilation unit - or my oven in standby vs in use because of the electronics/digital clock). My led drivers are also a pain to measure.
Maybe I can take multiple measurements depending on the state and then apply some if-then-else logic for the calculation in esphome or home assistant.
I should give up on trying to be watt-accurate, after all I would be happy to be able to get a good overview of the distribution of my energy usage throughout the house.
Quote:That's what I was afraid to see. Good to know I need to find smaller resistive loads as well. My current lowest is around 0.65A but some loads I want to measure get down to 0.1A.
I think that should work. 0.1.
Btw, a tip to get more calibration points: you can just wrap the wire around the CT multiple times. e.g. if you have a stable 1A load and you wrap it around 4 times you can use that as a reference point for a 4A load.
Quote:Wouldn't it be better to measure on actual wires in the walls? I believe the readings may be influenced by plenty of wires around in my fuse box.
I just calibrated them outside my cabinet before installing them on the lines I needed. But during testing I tried to move and wiggle them around but that didn't seem to affect the readings.
Didn't see a difference between having 1 or all 16 lined up next to each other, so I think that is quite ok.
[/quote]
|