-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtering out extreme values #57
Comments
You could try this (I haven't tested this...)
The problem with this is that if the first value is a noise value then the following sane values will be ignored. I think I found the source of your filter example and there is an updated version in that page which should handle that situation a little better. Here is a modified code for that
This will handle the first noise value problem. It will revert to new "range of values" after getting three out of range values in a row. Let us know if either of these work. EDITED: First version compared the values before applying the pulse calculation. Should be fixed now. |
I found out by asking on the ESPHome discord that filter values are processed in order of entry in YAML and you can have as many as you like. So i ended up testing it like this last night.
I ran the pulse rate calc first as the values i was working with in the graphs in home assistant are after the calculation so I wanted to filter it after the calculation. This worked pretty well, i didn't get any 1 million W readings but i did get 1 96000W reading. So i think your suggestion of the new code is a good one so i am going to test this.
I am going with 30000W now as my panel is 125Amp max which is 24000W max draw so anything over 30000W should be well safe as being false. Thanks for the suggestions and i will report back if this works. |
Sorry, I made the comparing to previous values before doing the pulse rate calculation. I modified my code also. Please report your progres. :) |
Had the same problem, with rare very high spikes (>8kW), solved it with a filter: sensor:
- platform: pulse_meter
name: '${name} - Power consumption'
unit_of_measurement: 'W'
state_class: measurement
device_class: power
icon: mdi:flash-outline
accuracy_decimals: 0
internal_filter: 50ms I did not use an ESP32, have a NodeMCU12S. |
I still get the odd value with the max difference code. I will add in the internal_filter also. It has been much better though. I am still trying to pin point where the noise is coming from but not having much luck. |
That is very strange. Do you get only single spikes of crazy values or are there multiple crazy values in row? If the code from my last example works, you should get four crazy values in a row. Here is a sample what should happen. First row are the new-values calculated in the first line of the code (s prefix is sane value and c is a crazy value). Second row is the output of the filter. Third row is the value of the count_missed_t variable after each step.
As we can see there needs to be four crazy values in a row to produce crazy values. And if that happens, even after sane values start coming right after those, the output will be four crazy values in a row before sanes values are the "new normal" again. |
There is just one single crazy spike. I have attached a log from the esphome logging.
|
Makes no sense to me. You could try to add some logging or take this up with the ESPHome people. |
Dude, I'm so friggin' stupid. I never changed value of |
Did you leave it at 50000.0? I think it works better if you calculate the max wattage of your power board and set it to that. I am finding the internal_filter is working better then the filter code. |
Yes, I had it at 50000.0 ;) Tried the |
Interesting your spikes are always around 40,000, the internal_filter wouldn't catch that as it is not extreme enough. My spikes were much higher, around 100,000+ up to 1,000,000 often and a much wider value range, which the internal filter would catch as it is so extreme so the pulse would be very quick so be filtered out. 40,000 although a high value is a possible value so you will need the max difference calc to filter that one. Glad it seems to be working so far. |
I'm running on a D1 mini (esp8266) and also getting crazy values at random times. I wanted to add some thoughts on the above ideas. The The advantage of the lambda filter though, is that you are looking for the DIFFERENCE between the last known good reading and the current reading. However, you still seem to be configuring it based on the maximum possible load of your board, Surely |
I've managed to solve my crazy values problem! Firstly, the filter as described above with a value of 11,000.0 worked great at removing the truly crazy values. However now I wasn't distracted by the 6Mw 🤣 pulses, I was still getting random spikes around 1.5kw - 6kw over my base load around 200w. When you do the math that's a rogue pulse of 2.4s in the midst of a pulse rate of around 18s. That blew my theory that it was just noise in the PWM of the meter's LED. That's a distinct pulse unconnected with the meter's LED. My light detector is sealed off from external light, so what could it possibly be... Then it struck me! The cable connecting the light detector to the esp8266 ran right next to the radio communications module of the smart meter. It must be an RF induced pulse in the cable! So, I rerouted the cable to be maybe 5cm away and overnight I haven't seen any rogue pulses. It's early days in testing, but I think that was the problem all along. If I still get any interference I'll try adding a 100uf capacitor across the ground and digital output pins as suggested in another issue, which should soak it up. Just thought it was worth documenting this issue with RF interference here as I'm sure others will encounter it with their smart meter in close proximity, |
For me, an |
I tried using this in my own glow.yaml, but it seems like some syntax is wrong? Getting this error: while scanning a simple key Anyone able to assist? |
I added some spaces to the stuff below -lamda: and it started to compile, but now I get this: /data/cache/platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:135:16: error: expected unqualified-id before '(' token |
I had spikes, lots of spikes. Activating the internal filter cut off most insane ones but there was still a lot of noise left. The filter based on difference still improved the situation especially if MAX_DIFFERENCE was set low enough but even this did not solve the problem entirely. I could still see small spikes appearing. The solution was to decrease the sensitivity of the photodiode by turning the potentiometer on the board anti-clockwise. This removed all spikes and I was able to deactivate the filters. The signal is clean now. If you have noise in the signal from the photodiode, it may be an easy solution to adjust its sensitivity. This can be done especially if you use the given 3D-case, since it blocks very effectively all the interfering light that might come from outside. So the sensitivity can be rather low. |
I think this is the issue I'm also having. I will adjust the potentiometer when I get home. The software filters only reduce the values of the spikes, but doesn't actually remove the spikes themselves. I think mine is also just too sensitive. |
I solved this error by changing the function |
Hi all. I was having the same issue and came here for assistance. I have tried all sorts of things including internal filter and the extreme value calculator mentioned above. I was using GPIO12 and have just moved to GPIO26 and all my extreme values have completely disappeared. This is the only thing that worked for me. Cheers, Matt |
Hey, just adding my two cents here with another filtering method. The filter I put together is similar to those suggested above, but inverted in a way so that 'large' (1kw) changes have to be confirmed for some number of readings before being accepted. The code is adjustable for how many frames of confirmation you want to have (num_samples). This does skew the readings very slightly, but generally evens out over time -- i.e., if you go up 1500w, it won't register for a few frames, but then when it goes back down the drop won't register for the same number of frames. Its not perfect but it solved all the wacky readings and everything been consistent and reasonably accurate since I added this. A quick preliminary note, if your sensor has an adjustable sensitivity, make it as sensitive as you can. This filter is also combined with the following settings: internal_filter_mode: "EDGE" You'll want to adjust internal_filter to be compatible with your meters blink rate (i.e, divide the value by 4 if your meter blinks 4000 x per kw). 35ms works well for mine which is 1k blinks per kw. Adjust MAX_DIF and num_samples to a desired value to force consecutive readings to register, as described above.
Hope this helps someone! Regards, Louis |
Changing filer mode to pulse and lower the internal filer to 10 ms solved all my problems. No spikes during the last 72 h.
|
Had the similar problems, also solved it with an internal filter,
I have seen no spikes anymore since Nov 21. My measurement is very close to the meter. |
Had the same issue with random extreme spikes. Traced down the issue to the photodiode board itself. The comparator circuit lacks a hysteresis resistor/capacitor. Adding a 33kOhm resistor and 10nF capacitor between pins 5 and 7 of the comparator chip worked for me. Used 1206 size components and soldered them on the adjacent resistors. Also removed the capacitor connected to pin 5 because it was too large for my meter which uses 10.000 pulses/kWh instead of 1000. |
So by default I was getting a lot of crazy spikes (8 000 000 W), however the basic I have 500 imp flashes per kWh. I use Wemos D1 Mini with the sensor soldered onto 10 m CAT5e cable, so that might play a role as well. |
I also had a lot of these crazy spikes going way over what's possible on a single phase residential service (eg 80,000 watts). I have removed the impossible readings with
Going well so far, but I might need to increase the window size, we'll see. |
Hi,
|
I raised this issue some time ago, the problem with GPIO12/13 is they are touch pins and the wiring will sense this and give incorrect readings, I changed to 26 and it's been working perfectly since |
This weekend I plan to update the repository, if using GPIO26 is really better then I will be happy to adopt that advice in the V4.0.0 release. Which GPIO should people best use with a Wemos D1 or ESP8266? |
Will depend on the board, but most ESP32's, GPIO13 seem to be touch pins
https://lastminuteengineers.com/esp32-pinout-reference/
|
The Wemos D1 and the ESP8266 shouldn’t be an issue as they don’t have touch pins
|
FYI: I'm currently working on a refactor of the project where the default pin for the ESP32 boards will from now on be GPIO26. |
Before using the software filters it is important to try to get your inputs free of external noise. Try twisting your sensor cables between the sensor and the controller. Then use your software filter to step on anything that gets through. I had the same issue and for me twisting the wires and using a relatively large value on my internal filter time (but less than a realistic pulse period) solved my issue. Recently though I made some changes and I now have the spikes back again, which are occuring at the same time my aircons turn on/off, due to the large surges that would occur at these times. I have to go back and get things back to normal again it will be fine. |
Could internal_filter be added to the settings panel just like the Puls rate - imp/kW is now added? That way you could change the internal filter value and still get the updates from github. |
Please create a new issue for that. ./Klaas |
I'm trying and failing to work out the internal filter sizes to set for 2 systems I have setup but simply cannot get my head around the calculation used to work it out and how you can get the 78ms as the answer. My Glow's are both monitoring meters on solar so the max possible pulse rate will be much lower than a system monitoring grid input. |
Let's assume your main breaker flips at |
I made this modification and it helps to reduce 400kW spikes, but it doesn't remove them all. I have to install esphome add-on and then make custom firmware to add this line: sensor:
now there is no spikes any more |
I seem to be getting some noise on my sensor and I get very extreme values when this happens. These readings are usually over 100,000 W up to over 1 million some times.
I have found a lambda filler that has a max difference value but am not smart enough to combine the current lambda filter with this one and I can't find in the esphome docs if I can have two lambda filters and it process in order or not.
This is the filter I have found
filters:
- lambda: |-
float MAX_DIFFERENCE = 50000.0; // adjust this!
static float last_value = NAN;
if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE)
return last_value = x;
else
return {};
And I need to combine it with the current filter of
The text was updated successfully, but these errors were encountered: