denver
March 1, 2022, 9:52am
1
Im trying to filter out excessive spikes in data coming from my BME680.
Ive fitted 4k7 pull up resisters to the data lines and that has helped but I still get the problem every now and then.
I have been looking for a way to catch this information and eliminate it and found in this issue code that would help.
opened 03:52PM - 18 Oct 19 UTC
closed 12:39PM - 21 Oct 19 UTC
integration: sensor
<!-- Thanks for reporting a bug for this project. READ THIS FIRST:
- Provide … as many details as possible. Simply saying "X gives bug" or "X gives error" is not enough!
- Paste logs, configuration sample and code into the backticks (```).
- Read through the template carefully and fill out all missing details.
- Please also search for similar issues in this issue tracker first and read through the ESPHome FAQ.
DO NOT DELETE ANY TEXT from this template! Otherwise the issue may be closed without a comment.
-->
Follow up to Issue #741 (sorry).
**Operating environment/Installation (Hass.io/Docker/pip/etc.):**
<!--
Please provide details about your environment below this line. -->
Hassio, docker, ESPHome add-in 1.13.6
**ESP (ESP32/ESP8266, Board/Sonoff):**
<!--
Please provide details about which ESP you're using below.
-->
WEMOS D1 R3
**Affected component:**
<!--
Please add the link to the documentation at https://esphome.io/index.html of the component in question.
-->
Sensor / BME680
**Description of problem:**
I am getting occasional bad data from the I2C interface. I cannot filter it out **largely** because the filter_out filter works on the full precision of the value and the 'delta' filter posts data when it exceeds the data not the inverse.
Whilst the filter added by PR https://github.com/esphome/esphome/pull/765 allows for filtering of a rounded value, the bad data is *not consistent* enough (i.e. not always the same wrong value) for this to completely filter bad data out. The data value is though, outside an expected range or the difference between it and the last good value is too great.
I suggest one of these filters would solve the problem;
* A DeltaMax filter - specify a maximum difference between the last good value and the new value (rate-of -change limit). For instance, you might only expect a temperature to change by a small amount, certainly not 10 degrees inside a house in 60s, so a limit of change of 10 would filter out a bad value as it is usually an extreme value. This also accounts for occasions where a value could be at either end of the range.
* A within-range filter - only post data if within a specified range. if measuring the temperature of the house, you can estimate a valid range. If outside the range discard. This is less useful I'd suggest.
**Problem-relevant YAML-configuration entries:**
please see #741
```yaml
sensor:
- platform: bme680
temperature:
name: "BME680 Temperature"
state_topic: emon/bme680_1/Temperature
retain: false
discovery: false
oversampling: 16x
accuracy_decimals: 1
filters:
- filter_out: 195.8
```
**Logs (if applicable):**
<!--
Please copy the debug log here. If possible, also connect to the ESP over USB and copy those logs into the backticks.
-->
```
[21:14:33][D][bme680.sensor:314]: Got temperature=195.8°C pressure=2005.6hPa humidity=0.0% gas_resistance=nanΩ
```
**Additional information and things you've tried:**
I am now trying to find a way to update a sensor in HA to display the count_missed results_t.
This guy updated the logs with
ESP_LOGW("main", "Missed Temperature Data %d", count_missed_t);
But I would prefer to replace this line with something that would update a sensor in HA. Ive created a sensor in ESPhome that works but I’m having trouble updating data to it and would be grateful for some help as not very good with C++
So far I’ve added to my original ESPhome code:
- platform: template
name: "Lounge Temperature missed"
id: l_temp_missed
lambda: |-
return id(count_missed_t);
update_interval: 60s
Ive tried creating a global variable count_missed_t and tried sensor.template.publish but have ended up confused with it all.
Any ideas on how I could do this.
Mikefila
(Mike Fila)
March 1, 2022, 2:57pm
2
Try placing the template under text_sensor:
rather than sensor:
.
denver
March 1, 2022, 4:41pm
3
I have tried that but its updating the sensor that’s not working, I think I’m over complicating it.
At the end of the day all I was hoping to do is write a line or two of code in lambda to replace the
ESP_LOGW("main", "Missed Temperature Data %d", count_missed);
in the code below to create and update a HA sensor instead of logging a message in the logs. The HA sensor would then show a count of any errors in the temperature reading.
sensor:
- platform: bme680_bsec
temperature:
name: "L Temperature"
id: l_temperature
accuracy_decimals: 2
sample_rate: lp
filters:
- lambda: |-
float MAX_DIFFERENCE = 2.0;
static float last_value = NAN;
static int count_missed = 0;
count_missed = 0;
if (isnan(last_value) || std::abs(x - last_value) < MAX_DIFFERENCE) { count_missed = 0;
return last_value = x;
} else {
count_missed += 1;
ESP_LOGW("main", "Missed Temperature Data %d", count_missed);
return {last_value};
}