Can't suppress ADC sensor update traffic

Hello

I am trying to finalize my esphome project and optimize the traffic. I have an ADC sensor and then a copy sensor to filter and average it. I have a delta filter on the copy sensor which suppresses state updates when nothing is changing. This is working (its reading motor current, so its usually 0 when the motor is off).
But the original ADC sensor is spewing out state updates even when the motor is off. That’s despite marking this sensor as internal and not giving it a friendly name. I can’t use a delta filter here due to the following copy filter.

Thanks!

[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:46][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:47][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:47][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy
[07:23:47][D][sensor:094]: 'motor_current_sense': Sending state 0.00000 A with 3 decimals of accuracy

I have an update interval set to 0.1, and a window filter to average 10 samples. So I get a clean filtered current reading every second.

sensor:
  - platform: uptime
    name: Uptime Sensor
# Use ADC sensor with the gain of the CS, which is 2.5v per amp
# ADC needs to be on the Max range, 11dB attenuation
# The ADC is terrrible!
# Provide a zero offset, ie when motor not powered it needs to be 0
# It also needs a gain correction and the low current is not accurate
# but we really only use it for over current check (redundant with fault).
  - platform: adc
    pin: GPIO32
    id: motor_current_sense
    internal: true
    attenuation: 11dB
    accuracy_decimals: 3
    unit_of_measurement: A
    update_interval: 0.1s
    filters:
      - offset: -0.1420
      - multiply: 0.4

# Now copy that sensor and average it becuase ADC is very noisy
  - platform: copy
    source_id: motor_current_sense
    name: "Motor Current"
    id: motor_current
    entity_category: "diagnostic"
    accuracy_decimals: 3
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
      - delta: 0.010

So far I see in sensor component - this does not mean sending to HA.
But sending state out of the sensor code to copy sensor too - in that case.

Why are you copying it at all?

You can add all those filters directly to the ADC. They will be applied in the order you list them. Also if you want periodic updates (can be handy for graphing) but not often, unless there is a significant change then you can OR a throttle and a delta filter.

sensor:
  - platform: adc
    pin: GPIO32
    name: "Motor Current"
    attenuation: 11dB
    accuracy_decimals: 3
    unit_of_measurement: A
    update_interval: 0.1s
    filters:
      - offset: -0.1420
      - multiply: 0.4
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
      - or:
          - throttle: 300s # send a periodic update every 5 minutes
          - delta: 0.010 # send an update when there is a change

Hi Tom

Yes, someone suggested this on the discord too, its working too.
I think i started developing thinking I would have a high sampling rate internally and then slower diagnostic feedback into HA front end. But I really only need one now its mostly working.

Throttle is the other thing I needed! I was trying to use heartbeat not getting what I wanted. That was also a great tip.

So regarding the ADC sensor, is the update_interval the sample rate of the ADC and is this checked against the ADC’s specifications?

Yes it is the sample rate and I am unsure if you can exceed the settling time specification. I suspect you will be able to, leading to inaccuracies for fast changing signals. The built in ADC isn’t very accurate anyway. It has non-linearities at the extremes of its range. You can somewhat account for this using the calibrate filters.