Hi Jimmy, the reason I used pulse_meter is that it reports the pulse frequency in pulses/min on every pulse recieved.pulse_counter reports pulses within a specified period of time in pulses/min. So they are not that different; I chose to use pulse_meter as it offers better data resolution (the sensor receives more pulses the faster the wind blows, so it catches more data of wind gusts).
I have never had any trouble with inconsistent or errant wind data from this sensor using pulse_meter. If you are seeing a gust, know that one way or the other your ESP is recording many pulses. So whether there is interference, or if your wiring is not correct, I am not aware of any issues with pulse_meter on the ESP32 using my setup and pin config. Is it possible you were handling the sensor and turning the anemometer during this time period? I have provided myself with bogus data in this way and caused confusion before.
Per your error Couldnt find ID "g_WindSpeedMin_Reset", it appears that this variable is not defined in any of the code provided by kluszczyn. I suspect it may be a template switch that allows the user to reset the WindSpeedMin in home assistant. Perhaps he forgot to attach as switches are in a different area of the yaml. So you may want to add some code like such:
@kluszczyn, thank you for sharing your config and very detailed solutions! For the time being I use statistics sensors in home assistant to handle gust calculation, but your code looks very nice for a native solution in ESPhome.
Thanks for the additional info @devjklein - would you be able to post your complete code for this please?
Iām still having issues with it reporting gusts of 76mph, on a still day! I suspect I have the math messed up somewhere!
did you got your wrong windspeed-data fixed? I have exactly the same problem with getting extremely high speed-data for short periods of time. Iāve tried to search for others with this problem but canāt find any, expected you in this thread.
This is my wind-speed-graph. More or less the same picture as you described in your post.
sensor:
- platform: pulse_meter
pin:
# PULUP-Widerstand 10kOhm
number: GPIO25
mode: INPUT_PULLUP
id: wind_speed
unit_of_measurement: 'm/s'
name: "Aktuelle Windgeschwindigkeit (m/s)"
icon: 'mdi:weather-windy'
#internal_filter: 13us
timeout: 5s
filters:
- sliding_window_moving_average:
window_size: 15
send_every: 15
#espHome pulse_meter gibt den Wert in pulses/min aus / Laut Datasheet bedeutet 1 pulse/sec = 2,4km/h
# Wir rechnen also: 2,4km/h / 60 / 3,6 / 2 (60 weil pulses/min -> pulses/sec; 3,6 weil km/h -> m/s; 2 weil 2 Ticks pro Umdrehung)
- multiply: 0.005555556
This is my ESPHome Code-Snippet for calculating the wind speed in m/s (I also have a sensor for km/h - It multiplys the value of the m/s sensor with 3.6 for getting the speed in km/h).
I tried to play around with the internal_filter and the sliding_window_moving_average - but nothing helps.
Any tips what could be wrong?
My setup is an ESP32-DevKit-V1 + SparkFun Weather-MeterKit (windspeed, wind direction, rain gauge) + BME280 + ESPHome 2022.9.2
This is a very strange behaviour. Up until a week ago I did not notice any anomalies in my own data, until I had these odd spikes in my statistics sensor of all places:
Even more confusing is the fact that the raw data from my wind meter does not exhibit these spikes. So I am not sure if this could be related to your issue or not.
First, can you confirm the picture you shared is the chart from your wind meter, without any averages applied? Second, can you provide a zoomed in view of the moment the spike occurs? And finally, are you able to capture a log of the esphome device while these are occuring? These are not things I have access to as I have not been having consistent spikes, save the three spikes on my mean statistics sensor.
I do have a long run (approx. 5m) of cable between the sensor and the ESP, I wonder if it needs a pull up resistor or the ESP being mounted closer to the sensor?
Edit: Changing from pulse_meter to pulse_counter seems to deal with this, now getting consistant 0mph readings - now just need some wind to test it properly!
I can imagine that a long run of cable could introduce noise, that makes sense. But I do not understand why pulse_counter would eliminate this issue, as the ānoisyā pulses should still be coming in.
Perhaps there is a difference in the way the two platforms count pulses? I know they added internal_filter_mode to pulse_meter, but I didnāt find that necessary for my use case. pulse_counter uses rising and falling edge, but without examining the signal coming to your esp on an oscilloscope, it could be tricky to determine the kind of noise that is occuring.
My recommendation is to get the esp as close to the sensor as possible, in my setup I use a long power run up an unused chimney, and the esp is mounted in a waterproof PVC box on the roof, close to the sensors. There is a cable run up the mast to the sensors, but iirc itās as short as possible, maybe 3m?
I wouldnāt think that 5m would be an issue; are there any sources of electrical interference in your area? One diagnosis I would be interested in is attempting to connect the sensor to the esp with the shortest run possible and determining if this improves the signal quality.
To solve this issue we should remove as many variables and then gradually reintroduce those conditions until we observe the issue.
There is a constant value of 240km/h for 10sec until the next value was send. Although the esp is configured to send a value every 5sec. (I played around a bit in the config, so it has changed since my last post). I tried to remove the sliding_moving_avarage and switched it to a calibration with a heartbeatā¦:
Unfortunately I canāt provide a log from the moments these spikes had happened. Is there a way to save the log-messages from the esp to a file or do I have just the live-logs inside the home assistant-esphome-addon? Because I donāt have a clue how to predict such events it seems very hard to get the log from just that minutesā¦
My setup is near exactly the same as @devjkleinās. So I donāt think that the cables are the issue.
I could try to change the pulse_meter to a pulse_counter like @jimmyeao but as mentioned in this thread before theyāre a good arguments for taking the pulse_meter for that purpose.
I searched a bit if there ore other known problems with pulse_meter. Somehow I landed on https://github.com/esphome/esphome/pull/3321 and tried the customized pulse_meter out (I really donāt know if this PR is affecting this issue at all):
The only difference from my config is the heartbeat filter. I do not have time at the moment to investigate in detail, but I am wondering if that is causing the esp to send bad data? Can you check the logs from your esp?
Thought I would add something to this thread regarding spikes in readings off an ESP32. I run a number of ESP projects and the latest one happened to be the weather station using the Misol equipment many here also use and I subsequently saw additional pulses being received when not expected.
It was while researching the Espressif documentation of these devices I learnt that a decoupling capacitor should be placed on the pin being used for sampling data. By adding a 0.1uF capacitor between the pin in question and ground (at the ESP32 itself), all issues with random pulses being detected were eliminated.
I have some 5+ metres of wire linking the anemometer and wind vane to the ESP32 and I use the pulse counter in ESPHome. Hope this information helps someone.
Hey @IanC
thanks for coming back here and share your knowledge.
Indeed Iām still having problems with random data-spikes, although I optimized my configuration to get at least a little ācleanerā data know.
Just one question: You wrote, that the decoupling capacitor has to be placed between the pin being used for data and ground.
I searched a bit for decoupling capacitors and learned that such a capacitor has to placed between the power-source and ground. So, in my case (ESP32-DevKit-V1) between the 3.3V pin and ground.
Did you meant that in your post or did I misunderstood something?
Sorry for the late reply as Iāve been away on holiday for the xmas period.
The capacitor needs to be directly connected between the GPIO pin you are using and ground. Iāll attach a photo which shows the capacitor attached to a D1 Mini. Hope that helps you.
indeed, that was the trick. Thank you very very much for the tip.
Since I soldered the Capacitor in, the random spikes are gone and now I have clean and plausible data. Nice!
Now Iām in the details: although you all (or most of you) use the calibration divided by two (because of two ticks per rotation), iām using the original calibration from the datasheet (2.4km/h per 1 Rotation per second) and it seems to be quite accurate in comparision to my local weather data provider. Iām wondering if there are different versions of the Spakfun like anemometers on the market. Some using the 2.4-calibration, others the 1.2. Maybe the datasheet we all use is just for one specific version of the sensor.
And last but not least for everyone whos interested: to avoid the situation, that the Wind sensor gets stuck at a value > 0 km/h when using the sliding window moving average in esphome and no new wind data comes in from the sensor: I just configured a little automation inside HA, which tests every few seconds if the value of the windspeed-meter has not changed for more than 10 seconds. If that condition turns true, i simply set the value of the sensor to zero via a little script inside of HA.
Its not perfect but better than nothing
Hereās how I dealt with the wind calculations. I do not rely on counting pulses per rotation, I measure the duration between pulses instead. It also shows how I dealt with calculating gusts according to the standards by the world meteorogical organization.