How to run platform statistics average after running platform statistics median?

Hi all,
I need to filter unreasonable measurement values of a sensor and utilise the platform: statistics state_characteristic: median function. That runs successfull and does the trick.
Now I need to smoothen the median-processed measurement values and would like to run platform: statistics state_characteristic: average on top of the output of the median function.
However I get the following error message where z1_cur_power_median is the output of the median function:
`Invalid config for [sensor.statistics]: Entity ID z1_cur_power_median is an invalid entity ID for dictionary value @ data[‘entity_id’]. Got ‘z1_cur_power_median’. (See ?, line ?).´

How can I fix this?
How can I convert the output of the median function into an entity, so that the average function accepts the input?

Thanks for your support

Use sensor.z1_cur_power_median not z1_cur_power_median as the entity_id.

Hi @tom_l,
thank you for your response.
That would have been too good. Unforetunately I now get the following error message:

Invalid config for [sensor.statistics]: The configured characteristic 'average' is not supported for the configured source sensor. Got OrderedDict ([('platform', 'statistics'), ('name', 'z1_cur_power_median_averaged') ('unique_id', 'z1_cur_power_median_averaged'), ('entity_id', 'sensor.z1_cur_power_median'), ('state_characteristic', 'average'), ('max_age', OrderedDict([('minutes', 3)]))]). (See ?, line ?).

Do you have another hint/idea how to cascade/daisy-chain the statistics state_characteristic one after the other?

Your support is very much appreciated!

Share your configuration for the statistics sensor.

here is what I have in the config.yaml for the z1_cur_power (there is an identical set for z2_cur_power):

sensor:
  - platform: statistics
    name: "z1_cur_power_median"
    unique_id: z1_cur_power_median
    entity_id: sensor.zaehler_z1_cur_power_1
    state_characteristic: median
    max_age:
      seconds: 10

  - platform: statistics
    name: "z1_cur_power_median_averaged"
    unique_id: z1_cur_power_median_averaged
    entity_id: sensor.z1_cur_power_median
    state_characteristic: average
    max_age:
      minutes: 3

  - platform: integration
    source: sensor.zaehler_z1_cur_power_1
    name: z1_cur_power_integrated
    unit_prefix: k
    round: 2

Does that help to figure out what needs to change to make it work?

Change this:

to:

state_characteristic: mean

Or average_linear if you want time in each state taken into account (not just the values).

Valid state characteristics are listed here: https://www.home-assistant.io/integrations/statistics/#numeric-source-sensor

OMG … It’s pretty hard to recognise what a fool I am… :see_no_evil:

You probably want average_linear if your sensor does not update at an constant time interval.

1 Like

Sorry, for bothering you!
And many thanks for your guidance!

1 Like