This works (almost) perfectly:
When waking up, the sensor averages the voltage calculated after (11 updates x 1.3 seconds =) 14.3 seconds and pushes one value out before going back into deep sleep. So that there is only one value pushed out before the end of the “run_duration” of 20 seconds and going back into deep sleep.
I use this code because the first value read after waking up is often off. (The window_size in my code is just one that works for me.)
HOWEVER.
When I keep the ESP out of deep sleep in order to ota, a new value is pushed to HA every 14.3 seconds or so.
I would like to push a value to HA only every hour or so when awake for ota (and keeping one averaged value whenever waking up from deep sleep as it works now.)
I Googled around without succes. I tried adding a ‘heartbeat’ of 15 minutes without succes: nothing is sent to HA before going back to sleep.
Here is my code as it is now:
Thanks for your reply.
(The skip_initial before the moving average will not change anything to the frequency of pushing a new value every 14.3 seconds while doing OTA and keep awake for testing other sensors settings, will it?)
Will give that throttle filter a try after a good night’s sleep.
100% agree with your proposal to change from sliding_window_moving_average: to median:. Done. skip_initial still to add after more testing.
I have now added the throttle: filter. There indeed seems to be no second value passed forward to HA after my famous 14.3 seconds when deep sleep remains switched off (through the ‘well known’ script with input_boolean evaluation). But I am still confused about the wording in the ESPHome documentation:
When this filter gets an incoming value, it checks if the last incoming value is at least specified time period old.
It gives me (!) the impression that this will pass forward the first value (x) coming from the sensor (and do nothing with the median filter after that but wait until the throttle time is passed). Or will it first calculate the median and then consider that as first incoming value (y) for the throttle? Otherwise it is useless to add the median: filter. I cannot make that out from what I see in the logs and HA: a value is passed forward but which one? x or y?
My confusion held me from using throttle: in the first place and made me starting this thread .
You need to think of filters like there is the raw incoming data, and then they pass through one at a time in the order you’ve put them in.
When you have multiple filters, the input of a later one is the output of the previous one. They build on top of each other. Well this is how I understand them to work.
So the throttle fliter would be looking at the incoming median values. The median is looking at the multiplied values etc.
From the docs.
“Filters are processed in the order they are defined in your configuration.”