Test of Exponential Moving Average calculation for temperature slope calculation #206
Replies: 16 comments 44 replies
-
I only have my phone with me at the moment, but is there a way to expose the ema as entity (at least in the alpha) to be able to look at charts in comparison with the temperature? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I'm seeing some rooms with "unknown" slope. I cannot think of any reason why a slope could be unknown, at least if the HA server has been running for a while and the temperature sensor is reporting? Because even if there's no "new" measurement available, the slope is zero, as it means that the temperature hasn't changed and therefor the sensor didn't report anything new. Might this be a bug that I should try to narrow down? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
With stepline: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
https://github.com/jmcollin78/versatile_thermostat/releases/tag/4.2.0.alpha4 WIth all your feedbacks. See you tommorrow (I will be off tomorrow). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello @maia , I see you have done a lot of work and thinking. That's fine. Here is some remarks :
Currently the slope is not calculated considering the past. I just use two last points : the last known and the current event. And globally I make d emaTemp / dt. Because the ema takes care of the past, I think this is sufficient to have something well,
I nothing special to do. If dt is 30 the slope will be 0 or near 0 automatically with the formula above. Between the two measure, I agree that we should recalculate the slope at each cycle as if a measure point have been set by the temp sensor. Then the magie will occurs without having anything special to do.
Because the alpha is depending of the last timestamp the 21° will be mostly ignored and only 20.5° will be taken into account. That is what we want. That is the beauty of the formula with an alpha depending of the dt. So for me there is nothing to do the ema calculation. It should stay fix until the next measure and be calculated depending of the dt. On the contrary the slope need to be adjusted even if the sensor don't send new temp event, because we can consider that no event means a stable temperature. I will fix that in the algorithm of the slope calculation. In my opinion it would be wrong to consider a fake measurement have been send just before a real measurement. In that case, dt with the previous will be very low, and the last real measurement will be not taken into account. That will introduce more delay for adjusting with the real temperature.
Given my explanation above, I think this is true for the slope (and missing as now) but especially not for the ema. You are referring to stock value which are coming at a constant rate, but this is not the case here and the alpha does the trick:
"Increase sharply", we are talking about a gap from 20.62 to 20.68 (+0.06°). This is real not sharply inmy opinion. Remember that temperature has a resolution of 0.1°, so the gap is half under the resolution. Why do you want to cancel this +0.06° "pick" ? You will just introduce more latency in the system and too much reduce the dynamic. It is visible in the curve you gave: I agree we can reduce the MAX_ALPHA (which was 0.9375), but 0.13 seems very, very too low (and so too smooth) for me. Maybe approx 0.5 is a good compromise. This makes an already strong filter (0.5 is the value I had before in the slope calculation).
Reducing the halflife is just a way to augment the alpha that you wish to drastically reduce. Is that not contradictory ? |
Beta Was this translation helpful? Give feedback.
-
Agree, but I'm trying to look forward: For #208 we might need a 60 minute slope and/or a 10 minute slope, which will require more than these two points you mention.
There is no "fake" measurement. :) If a sensor isn't reporting a new temperature, it can only have 2 reasons: a) the temperature didn't change and b) the sensor is offline. But with a low alpha we don't need to add a "fake" measurement anyway.
Not on an absolute basis. But the issue is that short spikes in temperature cause the EMA to be off for longer.
For window opening we just look at the slope and the slope turns to -0.05 in less than a minute after I opened the window. And also for future additional uses of the EMA I think we will mainly use the slope. Does the slope calculation already use the EMA values?
I don't like constants that are not rationally explainable. A MAX_ALPHA of 0.5 means that we assume that measurements that are older than 5 minutes were still correct 5 minutes ago – but that they were not correct less than 5 minutes ago:
Why would you think that a sensor does not report a changed temperature over 5 minutes?
The MAX_ALPHA only says how far ago the last measurement may be. In the screenshotted example with the open above the MAX_ALPHA would be irrelevant as the sensor reported a changed value multiple times per minute. So reducing the half life should reduce lag in such situations. My new suggestion (which I'd still need to test) is:
|
Beta Was this translation helpful? Give feedback.
-
https://github.com/jmcollin78/versatile_thermostat/releases/tag/4.2.0.alpha5 Please don't add comments in multiple page or code review. It is not easy to follow. Start here please. |
Beta Was this translation helpful? Give feedback.
-
Here is the new curve I got with the previous settings, on a full heating phase: We can clearly see the regulation and the ema following while smoothing the current temperature with a latency of 4 or 5 minutes. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
With the alpha6 release I have got this as slope: This look like promising. |
Beta Was this translation helpful? Give feedback.
-
As I only rent this place, I cannot change the system, unfortunately.
Ideally that's not necessary. I believe good algorithms manage to adjust to the surrounding. I've not given up hope yet that we find a solution.
I understand, if it needs a second loop. But what if the default main loop would run every minute, not just the temperature related calculations? Does that have any disadvantage for the other parts of the code?
Sure, if that's of any help I can provide you with data from different rooms (which use different temperature sensors too). Oh, and as I've not said it for a couple of days: Thanks for investing so much thought into this issue. :) EDIT: I've mentioned it a few times already, but I'm slowly more and more convinced: I think users would benefit from ONE setting that defines the speed at which rooms heat or loose temperature. And internally many other parameters are derived from that (thresholds, half lifes, cycle speeds,…). This prevents people from configuring something wrong and also gives you much more possibility to adjust settings from one version to the other. As an example, if you'd ever want to suggest a different open window threshold, all current users would have to reconfigure. But ideally they would not need to care if it's -0.05 or -0.10 or -0.15 because that's too much detail for them. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
content
ema_temp
in VTherm attributes,ema_temp
in auto_window detectionDO NOT USE if YOU ARE NOT INVITED TO TEST IT
This discussion was created from the release Test of Estimated Moving Average calculation for temperature slope calculation.
Beta Was this translation helpful? Give feedback.
All reactions