Filters, dynamic parameters

Is it possible to set a filters parameters using a sensor output?

I want to get a average for a set of temperature readings over a pacific time and display in HA at the end of that time.

I’ve set up a duty_time platform:

  - platform: duty_time
    id: total_proof_time
    name: Total Proofing Time

The start time is the moment the temperature reaches a set temperature and the end time is when the Proofing switch is turned of. This all works and gives a time span in HA.

To get the average I’m using throttle_average

  - platform: template
    name: "Oven Average Temperature"
    id: oven_temp_average
    filters:
      throttle_average: !lambda: return id(total_proof_time);
    device_class: temperature
    state_class: measurement
    unit_of_measurement: "°C"

But its not compiling due to the

filters:
      throttle_average: !lambda: return id(total_proof_time);

line. I’ve tried so many different options here so beginning to wonder if it’s not possible to do.

ie:

lambda: return id(total_proof_time);
!lambda: "return id(total_proof_time);"
!lambda: return id(total_proof_time).state;
!lambda return id(total_proof_time);

The throttle average filter only accepts a time, not a lambda.

I reckon some globals might be an alternative solution.

When your monitoring period is triggered, start summing your number of observations in one global, and sum the total of all temperature observations in another.

When your monitoring period is triggered as ending, calculate the average from your two globals, publish it to a dedicated sensor, and reset your globals.

Not sure if this is the best approach, but I think it would work.

1 Like