Is there a way to selectively limit what's recorded to History by an ESPHome device?

I created a scale that fits the base of my daughter’s crib and sends the measurement through a Wemos D1 Mini to HA.

I’m looking to accomplish a few things:

  1. Record values only when the scale is registering a value above a certain point (i.e. zero). In other words, only record the data while the scale is being used.

  2. Not record thousands of billions of entries, one for every second, while the scale is at zero load. I’d prefer to avoid needing to turn it on and off (alas, automation.)

So, as the device is set to update every 1 second, I imagine MySQL is being spammed with useless data.

Ideas?

Can you filter the results on esphome so that it doesn’t update so often? https://esphome.io/components/sensor/index.html#sensor-filters

The delta filter would seem to be appropriate for this use case.

Set the delta value to slightly higher than the noise you see on the signal.

Yes yes…this is exactly what will do it. So, if I set a delta that’s half way between 0 and her current weight, then until the scale is registering MORE than that number, it won’t pass information on to HA. Brilliant. Now to test it. Thanks guys!

1 Like

Be careful.

If you set the delta to half the current weight you may only get one inaccurate update.

Say your daughter weighs 6kg (as an example, I have no idea how much kids weigh), so you set the delta to 3.

You get nothing while the scale hovers around 0. Then your daughter is placed in the cot. The sacle jumps to 4 for the first reading then goes on to 8 then settles at 6. You will only get the 4kg reading. This is fine for a presence sensor but no good for accurate weight measurement.

If you set the delta just higher than the peak noise value you should only get updates when the scale changes value and you will get more accurate readings.

The issue is that your reading resolution to equal to whatever you set the delta value to.

Hmm…well, she weighs 8 lbs.

So what I’m trying to avoid is having to have her hang out on the scale for 30 seconds until I get a reading. Rather, I’d have the sensor constantly reading the values, but only sending values if the new value exceeds the previous value by a certain amount. Yes?

So, if I set the delta to .5 for example, if I put her on the scale, the first reading might be 2.3 until she settles on the scale. If the delta was .5, then there would be no additional reading sent unless the next value was either 2.81 or 1.79, which would be .5 greater or less than the previous value.

So let’s say she settles at 8lbs, but registers first 2.3, then 4.8, and so on. I could see that there might be a problem if a sampling were to be recorded within .5 of her actual weight as the settled weight would not exceed the previous value by the delta…so it seems that setting the delta as low as possible but not so low that minor variances in measurement would trigger readings, would be the best?

Maybe 0.1 would be the best.

Yes, you want to set the delta slightly beyond the the maximum peak to peak noise.

Leave the sensor sending values for an hour or so with no filter then using a graph of those values estimate the p-p noise:

noise

Set the delta slightly higher than this value.

Crap, one more problem. The values coming from the combinator range from negative 181733 to 283900 but are then converted into lbs. I’m not sure if the delta looks at the large number or the lb number.

sensor:
  - platform: hx711
    name: "HX711 Value"
    dout_pin: D7
    clk_pin: D6
    gain: 128
    update_interval: 1s
    filters:
      - calibrate_linear:
          - -181733 -> 0
          - -283900 -> 8
      - delta: 0.1
    unit_of_measurement: lb

To make things even more complicated, this is what’s passing through the sensor:

[22:38:19][D][hx711:031]: 'HX711 Value': Got value -188143
[22:38:20][D][hx711:031]: 'HX711 Value': Got value -188156
[22:38:21][D][hx711:031]: 'HX711 Value': Got value -188189
[22:38:22][D][hx711:031]: 'HX711 Value': Got value -188215
[22:38:23][D][hx711:031]: 'HX711 Value': Got value -188198
[22:38:24][D][hx711:031]: 'HX711 Value': Got value -188184
[22:38:25][D][hx711:031]: 'HX711 Value': Got value -188193
[22:38:26][D][hx711:031]: 'HX711 Value': Got value -188219
[22:38:27][D][hx711:031]: 'HX711 Value': Got value -188249
[22:38:28][D][hx711:031]: 'HX711 Value': Got value -188197
[22:38:29][D][hx711:031]: 'HX711 Value': Got value -188169
[22:38:30][D][hx711:031]: 'HX711 Value': Got value -188165

…and that’s with nothing happening to the scale…so I had to estimate and choose a round-about-range for the calibration filter.

I’ve eliminated the calibration filter so I can grab a history of values to find the peak as you suggested.

After that, I can use this measurement to set the delta using the big fat numbers and hopefully get what I’m going for…with a little algebra I suppose.

I’m not sure either. I think it’s the raw value.

1 Litre of water weighs 1kg. A light bucket and a measuring cup is an easy way to get some calibration values. No Idea what that is in freedom units, you’ll have to work that out.

Oh I got that part down. I have some known weighted items that help me find the starting and ending values to use in the calibration filter. It’s a linear change on the load sensor, so I don’t have to worry about strange curves, so as long as I know the reading when nothing is on the scale and the reading when a known weight is on it, then I can calibrate.