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
    phase_a:
      voltage:
        name: ${disp_name} Volts A
        id: ic1Volts
        accuracy_decimals: 1
# Split Phase A
      current:
        name: ${disp_name} CT01 Amps
        id: ct1Amps
      power:
        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
    filters:
      - 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.

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

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