Combine the state of several sensors dropout filter

I’m trying to make the Combine the state of several sensors helper work as efficiently as possible for combining energy sensors. In this screenshot, you can see that I combine a couple LIFX bulbs (via PowerCalc integration) into a Combine the state of several sensors sensor (Type set to Sum and Ignore non-numeric enabled) called Spotlights:

The LIFX bulb named Spot clearly drops out a lot. This creates an energy spike for Spotlights. So far, I’ve band-aided these situations across all of the troublesome entities in my energy dashboard with a Utility Meter, but I cannot help wonder if there isn’t a better way (I consider template sensors with Availability filters to be a band-aid as well).

Could the Combine the state of several sensors helper be modified to filter out these drops, perhaps as an optional filter alongside Ignore non-numeric?

Please post the config for your total energy sensor. You probably just need an availability template.

EDIT:

Oh, you’re using the UI.

Using YAML it would look something like this example of mine:

template:
  - sensor:
      - name: "Known Loads"
        icon: "mdi:gauge"
        unit_of_measurement: "W"
        state: >
          {{states('sensor.cinema_av_power')|float(0) +
            states('sensor.cinema_subwoofer_power')|float(0) +
            states('sensor.comms_rack_power')|float(0)*1000 +
            states('sensor.dishwasher_power')|float(0) +
            states('sensor.downstairs_heat_pump_power')|float(0) +
            states('sensor.electric_blanket_power')|float(0) +
            states('sensor.electronics_bench_power')|float(0) +
            states('sensor.hot_water_power')|float(0) +
            states('sensor.led_table_power')|float(0) +
            states('sensor.mechanical_bench_power')|float(0) +
            states('sensor.pc_monitor_power')|float(0) +
            states('sensor.spb_electric_blanket_power')|float(0) +
            states('sensor.upstairs_heat_pump_power')|float(0) +
            states('sensor.washing_machine_power')|float(0) }}
        availability: >
          {{has_value('sensor.cinema_av_power') and
            has_value('sensor.cinema_subwoofer_power') and
            has_value('sensor.comms_rack_power') and
            has_value('sensor.dishwasher_power') and
            has_value('sensor.downstairs_heat_pump_power') and
            has_value('sensor.electric_blanket_power') and
            has_value('sensor.electronics_bench_power') and
            has_value('sensor.hot_water_power') and
            has_value('sensor.led_table_power') and
            has_value('sensor.mechanical_bench_power') and
            has_value('sensor.pc_monitor_power') and
            has_value('sensor.spb_electric_blanket_power') and
            has_value('sensor.upstairs_heat_pump_power') and
            has_value('sensor.washing_machine_power') }}

This will cause gaps in your sensor graph rather than spikes down to 0.

Not sure why you say this:

It is how it is supposed to be done.

I know how to write template sensors and have a lot of them, but I’m trying to use the UI (specifically helpers) as much as possible to clean up most of them which do simple things like summing other entities, etc. In the process, I’m seeking more elegant solutions than things like availability filters when it seems core HA should be able to handle it more efficiently and cleaner (i.e. optionally filter dropouts).

If this post yields no other ideas based on the current options, I’ll submit a feature request to this effect:

Could the Combine the state of several sensors helper be modified to filter out these drops, perhaps as an optional filter alongside Ignore non-numeric ?

Anyone else know a better way?

You have

So your sensor is going to drop in value when LIFX bulb is unavailable. The only way around this is an availability template. This is not currently available in the UI.

There is already a feature request for this you can vote for:

I’m amazed there are only (now) 10 votes for this. But, thank you for pointing that out.

I’m not sure ignore non-numeric really matters in this situation. Take a fictional sum helper that at time (t) had a group member go unavailable. Let’s say just before t, the value of that sensor was this (regardless of the ignore non-numeric setting):

10 + 15 = 25

Here is how ignore non-numeric is meant to work according to the options UI:

“If “ignore non-numeric” is enabled, the group’s state is calculated if at least one member has a numerical value.”

10 + unavailable = 10

“If “ignore non-numeric” is disabled, the group’s state is calculated only if all group members have numerical values.”

10 + unavailable = ?

But, in both cases, the sum helper should stay at >=25 until group member 2 becomes available again.

Again, I know this can be done with templates and availability filters, but it should also be possible via the UI.

The UI template sensor was deliberately designed to be simple. It was mentioned in the release party youtube video when the template helper was introduced that if they wanted to add all the features available they’d essentially have to redesign an entire yaml interpreter. If you want a simple template use the UI. If you want something more advanced use YAML+Jinja. See: https://www.youtube.com/live/JSNRrWk9IHs?si=NRSvl8vrAtn1iU1A&t=2138

I do agree an availability template in the UI is needed.

I watch the release parties. Templates in the UI are a funny thing. To me, the advantage of using the UI for combining sensors is more in the use of the dropdowns and keyword search to minimize errors in picking constituent sensors and/or quickly modifying them. That’s why I think the Combine the state of several sensors helper is how I’d like to drive all of these simple custom sensors. It’s just missing one key option that seems vital to reliability.

Are you talking about another helper type or an option within an existing helper? How would you implement what I’m discussing?

why are you even using a template here? Just use a sensor group w/ state characteristic sum.

EDIT: Nevermind, your top post covers it. Ignore.

An option within the existing helper. I’ll leave it to the devs to work out how to present it.

1 Like