[SOLVED] Combine the state of several sensors (maximum) issue

Hi everyone,

I would lke to use the helper Combine the state of several sensors with the maximum function to store the maximum power generation of my solar panel.

The maximum does not seem to work properly (and there is not much I could do wrong, I guess ;-)):
The current value of this sensor is: 45 W, but I had already more than 80 W the day before yesterday:

Shouldn’t this store the all-times-high as the maximum value in this helper?

EDIT:
I just recognized that the value is actually decreasing simultaneously to the source sensor.
The only explanation is, that it’s the (current) maximum of all input sensors.
:frowning:

The reason is probably that you do not have enough samples specified or your max_age is too short

https://www.home-assistant.io/integrations/statistics/#sampling_size

Show your configuration.

My all-time high max power recording automation, relying on a manually-created input_number helper:

- alias: Energy - max power recorder
  description: Updates the maximum power recorder whenever prior maximum is exceeded
  id: 0fef4933-5115-4055-91d2-48d5d3a051b7

  trigger:
    - platform: numeric_state
      entity_id: sensor.power_meter_house
      above: input_number.max_power

  action:
    - service: input_number.set_value
      data:
        entity_id: input_number.max_power
        value: "{{ states('sensor.power_meter_house')|float(0.0) }}"

Thank you for you help, Tom.

I meant this helper I created using the UI:

What you mean is, that this statistics is not looking back long enough (e.g. just a few seconds for example)?
But how to configure this when creating the sensor / helper by UI?
What is the default max_age used in the “background” when creating the helper via UI?

@Troon
Thanks for this suggestion - that’s a good approach.
I prefer also manual config for Utility Meters for instance, but first I would like to understand how the max/min here suppused to work.
I will keep this in my backpocket though if I fail to get it done :wink:

I thought you were using this:

No, I am tryiing to use this:
(which has been renamed to Combine the state of several sensors)
Min/Max - Home Assistant (home-assistant.io)

But the statistic function might also be an option.

But you only have one entity listed. That integration pics the current (not past) maximum from a list of sensors.

So if you had:

Sensor 1 = 10
Sensor 2 = 25
Sensor 3 = 5

The output would be 25.

Then if they change to:

Sensor 1 = 10
Sensor 2 = 8
Sensor 3 = 5

The output would be 10.

If you want the maximum of a sensor over a time range you should use the integration I linked to.

1 Like

Thanks, will do, Tom!

Thank you, Tom.
It works well.
To be mentioned is that the sampling_size number needs to be reasonably high (to be able to cover the full max_age:
If it’s too low for the desired max_age, the result will look weird (much lower) because it will be the (“incomprehensible”) maximum from sometime within the max_age period (going back in time just the number of sampling_size discrete values.
So the result then can be anything between the currentl value and the real maximum (if sampling size is large enough).

Yeah. The buffer fill ratio attribute of the sensor will give you a good indication if you have a large enough sample size specified. The fill ratio should be near but never reach 1.0.

Ah, I just recognized, that the attribute Buffer usage ratio is 0.08 - so I might optimize this a little :wink: