Atm90e32 - Filter Out Negative Values

I’m using a 12 channel circuitsetup atm90e32 to monitor energy usage. I have a couple of channels that are not hooked up to anything and they show minuscule negative values that screw up some of my charts. Is there any way to put a filter in the yaml so that negative values aren’t passed to home assistant?

Here is an example of the code:

  - platform: atm90e32
    cs_pin: 5
        name: ${disp_name} Volts A
        id: ic1Volts
        accuracy_decimals: 1
# Split Phase A
        name: ${disp_name} CT01 Amps
        id: ct1Amps
        name: ${disp_name} CT01 Watts
        id: ct1Watts
      gain_voltage: ${voltage_cal}
      gain_ct: ${cal_sct_016}

and then a little further down (for the same channel)

#CT1 kWh
  - platform: total_daily_energy
    name: ${disp_name} CT01 Daily kWh
    power_id: ct1Watts
      - multiply: 0.001
    unit_of_measurement: kWh

Interesting there’s no “threshold filters”. Try one of these lambda filters.

First filter will replace negatives with 0’s.

I think the second one should work and just stop negatives passing through.

  - lambda: |
      if (x < 0) return 0; 
      else return x;
  - lambda: |
      if (x < 0) return {}; 
      else return x;

Thank you for the response! I just came back to this post to reply with what I did (which is exactly the same as your first solution). So, no need to post it now.

Thanks again!

1 Like