ESPhome + HX711 load sensor - values keeping creeping up

I’m using a D1 Mini with a HX711 and 4 load cells to monitor my daughter’s bed to see if she falls out at night. It’s working but the values keep slowly creeping up. When I set it up 48 hours ago the empty bed was showing 58 pounds. Now the empty bed shows 72 pounds. You can see the values slowly creeping up, even when she is sleeping in the bed in the history graph

I wired everything following this diagram

And here is my esphome code

sensor:
  - platform: hx711
    name: "Kass Bed Sensor"
    dout_pin: D0
    clk_pin: D1
    update_interval: 3s
    filters:
      - calibrate_linear:
          - 11150 -> 0
          - 4950 -> 4.28125
    unit_of_measurement: pounds

Any idea how to fix this?

1 Like

I found something that would fix this, but I’m not experienced enough to understand this solution.

I kind of understand what they are getting at, I think it’s meant to check the sensor value at a given time and make that value the new “0”, which makes sense, but I’m not good enough with ESPhome code to get it to work. Can someone help me with my code to get this to set the scale to “0” at noon each day?

This can also happen if you are using under rated load cells - maybe go up a size? You could also measure the output of the cells using a multimeter, that will tell you if the issue is there or in the HX711.

I don’t think it’s under rated load cells. I bought the same ones that someone used on a bed sensor for him and his wife I’m just measuring a crib with a 30 pound kid in it. If anything they would be oversized.

Im also wondering how to tare with esphome and couldn’t get the code in the github link working at least not on first try. Did you ever have luck with this?

I never found a solution. I kind of dealt with it for a while as the “creep up” wasn’t too bad. My kid has now outgrown the need to monitor the bed.

1 Like

Ok, thanks for the reply anyway!
For anyone else, I pretty much copy pasted the code here ESPHome sample configuration for an HX711 powered Smart Scale including Auto-Tare functionality. · GitHub and it works.

1 Like

This doesn’t work. It did for about a day, but then wouldn’t change from zero

Which of these do you have enabled?

There are two new switches in the configuration:

switch.smart_scale_continuous_tare_enabled
    lets you enable/disable the auto tare functionality
switch.smart_scale_manual_tare_action
    lets you initiate a one-time "instant" tare
    the switch will automatically disable itself after the tare is done (within a second or so)

I just had the auto tare enabled.

Did speak to the dev about it on that link. Ive switched back to the simple version. I guess if there is too much variance it doesn’t work?

This worked for a few hours (as in I could see weight variations) but now its just stuck at 0kg no mater if I’m on the bed or not.

I can see the raw values change in the logs if I get on the bed. But not the filtered values.

as you can see here. the auto tare seems to be zeroing it out. But no idea why?

Please let me know when you seen the log and ill delete most of it. Its pretty long :slight_smile:

Click to see Log

[10:05:18][D][sensor:125]: 'bed_scale_hx711_value_raw': Sending state 158218.32812 kg with 3 decimals of accuracy
[10:05:18][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:18][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:18][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:19][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:19][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:19][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:20][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:20][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:21][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:21][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:22][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:22][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:23][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:23][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:24][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:24][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:25][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:25][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:26][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:26][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:27][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130354.00000  with 1 decimals of accuracy
[10:05:27][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:27][D][hx711:031]: 'bed_scale_hx711_value_raw': Got value 213875
[10:05:27][D][sensor:125]: 'bed_scale_hx711_value_raw': Sending state 186283.00000 kg with 3 decimals of accuracy
[10:05:27][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:28][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:28][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:29][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:29][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:29][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:30][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:30][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:31][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:31][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:32][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:32][D][esp32.preferences:114]: Saving preferences to flash...
[10:05:32][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:33][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:33][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:34][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:34][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:35][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:35][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:36][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:36][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:37][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130364.00000  with 1 decimals of accuracy
[10:05:38][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:38][D][hx711:031]: 'bed_scale_hx711_value_raw': Got value 213830
[10:05:38][D][sensor:125]: 'bed_scale_hx711_value_raw': Sending state 213952.00000 kg with 3 decimals of accuracy
[10:05:38][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:38][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:38][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:39][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:39][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:39][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:40][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:40][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:41][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:41][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:42][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:42][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:43][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:43][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:44][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:44][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:45][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:45][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:46][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:46][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:47][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130374.00000  with 1 decimals of accuracy
[10:05:47][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:47][D][hx711:031]: 'bed_scale_hx711_value_raw': Got value 214174
[10:05:47][D][sensor:125]: 'bed_scale_hx711_value_raw': Sending state 213959.67188 kg with 3 decimals of accuracy
[10:05:47][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:48][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:48][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:49][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:49][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:49][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:50][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:50][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:51][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:51][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:52][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:52][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:53][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:53][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:54][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:54][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:55][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:55][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:56][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:56][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:57][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130384.00000  with 1 decimals of accuracy
[10:05:57][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:57][D][hx711:031]: 'bed_scale_hx711_value_raw': Got value 132310
[10:05:57][D][sensor:125]: 'bed_scale_hx711_value_raw': Sending state 186771.32812 kg with 3 decimals of accuracy
[10:05:57][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:58][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:05:58][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:05:59][D][sensor:125]: 'Bed Scale': Sending state 0.00000 kg with 2 decimals of accuracy
[10:05:59][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:05:59][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:00][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:00][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:01][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:01][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:02][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:02][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:03][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:03][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:04][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:04][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:05][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:05][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:06][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:06][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy
[10:06:07][D][sensor:125]: 'Smart Scale Auto Tare Difference': Sending state -130394.00000  with 1 decimals of accuracy
[10:06:07][D][sensor:125]: 'Smart Scale Initial Zero': Sending state 0.00000  with 1 decimals of accuracy

@markusressel

Author

markusressel commented 3 hours ago

@benek984 I have also seen weird behavior, I just wasn’t able to debug this yet.
@1liminal1 No need to remove it, just make it collapsible :nerd_face: (I have edited your comment)
Yes there seems to be some weird behavior after some time.

There are multiple things that might cause this, because the code

  1. tries to calibrate the raw value to a reasonable scale, which needs different initial values for each hardware (natural variation)
  2. tries to automatically adjust this initial calibration on the fly if “nobody is on the scale”, and this detection depends on a somewhat reasonable initial calibration value
  3. values below “0.1KG” (which, again, is a mapped value based on the calibration) are always mapped to 0

I think the most likely is that the automatic adjustment of the initial calibration value shifts over time, leading to strange results after longer durations.

@1liminal1

1liminal1 commented 1 hour ago

Yeah ok, thanks for that info.

Ive changed it back to the simple version with no tare. Just have to live with it I guess :slight_smile:

@1liminal1

These HX711 amplifiers are poorly designed.
To improve their stability connect E- with GND; moreover make sure the E+ is 1V below supply voltage.
If you supply the board from 3.3V don’t expect any stability because the internal regulator based on PNP transistor tries to regulate to roughly 4V.
So, connect the module supply to 5V and see if that helps. You may need series 1k resistors between some ESP chip pins because they may not like 5V signals.

Unfortunately this did not help. Connected -E to GND and E+ shows 4.1v. The value is still drifting over time. My load sensor is 300g.

You can’t get away from it. It is inherent in these cheap strain gauges. Some are better than others but all need to be calibrated regularly.

The signal is extremely small, so even the bonding glue ageing can cause a change.

https://www.omega.co.uk/literature/transactions/volume3/strain3.html

1 Like