HA Helpers Sum Energy

I have a helper that sum all energy values, the problem is when one going off, the helper fail sum the values of working ones.

it’s possible fix that?