Skip to content

Instantly share code, notes, and snippets.

@markusressel
Last active March 12, 2024 05:05
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save markusressel/e888544d4404fbed4c841ec83df638bb to your computer and use it in GitHub Desktop.
Save markusressel/e888544d4404fbed4c841ec83df638bb to your computer and use it in GitHub Desktop.
ESPHome sample configuration for an HX711 powered Smart Scale including Auto-Tare functionality.
Moved to https://github.com/markusressel/ESPHome-Smart-Scale
@cinghialino
Copy link

cinghialino commented Jul 15, 2021

Please, how do I find out what raw values the load sensors are giving me? this code does not publishes the raw data so the values at line 110 & 111 are arbitrary to you..

- -481989 -> 0 - 1339163 -> 88.3

@markusressel
Copy link
Author

Just remove the filters and you will get the raw sensor value. The calibration filter is a mapping, which means the original values provided by the Sensor are the numbers on the left.

@benek984
Copy link

Hi,
Auto tare and accuracy are awesome in this code. THANKS
Is there a way to add switch or button to tare manually?

@markusressel
Copy link
Author

Hi @benek984, I also had this thought quite a while ago but never got around to actually do it. Well, I have now 😄
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)

@mryli
Copy link

mryli commented Jul 20, 2021

Just made a bed occupancy sensor using the HX711. This has perfected the sensor. Absolutely awesome, Cheers for sharing!

@cinghialino
Copy link

can't find a way to exclude the filters and get the raw value from the sensors.
Can you please include an extra sensor with just the raw value of the load sensors? I would really appreciate it.

@markusressel
Copy link
Author

markusressel commented Jul 29, 2021

@cinghialino Sorry, my previous answer wasn't 100% correct. What you want is already in there, but marked as internal since - in most cases - its value doesn't need to be exposed to home assistant.

Without changing anything else, you can expose the raw value by not marking it internal:

    id: smart_scale_hx711_value_raw
    internal: True   <-- change this to False

I would strongly advise you to make it internal again after your calibration process, since it produces quite a bit of data for home assistant to constantly process.

@cinghialino
Copy link

cinghialino commented Jul 29, 2021

Thanks @markusressel

I changed as you suggested line 114 from True to False
but no additional sensor has been revealed in Home assistant, not even after deleting the sensor from the integration or restarting HA.

This may be a little over my current skill level. Thanks anyway.

@markusressel
Copy link
Author

@cinghialino I guess you also need to remove the whole on_value section then, maybe this overrides the default behaviour of a sensor.
No worries, if you keep on trying, you will get it to work eventually :D

@Zerwin
Copy link

Zerwin commented Dec 4, 2021

@cinghialino

sensor:
  # RAW Scale input
  - platform: hx711
    name: "HX711 Value"
    dout_pin: GPIO2
    clk_pin: GPIO3
    gain: 128
    unit_of_measurement: kg
    accuracy_decimals: 3
    update_interval: 5s

This works for me for the raw values, just be careful you use the correct pins

@Aasikki
Copy link

Aasikki commented Dec 10, 2021

I made a bed occupancy sensor for 8 legged bed's out of this.
https://gist.github.com/Aasikki/82bf0238fecb7328b18e2727902d7dca

@benek984
Copy link

this is my second time when I use this code once again THANK YOU FOR IT.
This time I use it to monitor DIESEL level in the tank for my diesel heater. Basically I have plastic tank hanged on the hx711 sensor. I decreased times of measurement from 0.2s to 60s as the value will not change that often. On full speed my diesel heater will consume between 100-150 ml of diesle per hour. Unfortunately, I see some strange behaviour. When there is no decrees in the value (heater is off) I see value drop to the certain level over the 30 min period and then go back again to the top value. See grafana screenshot from 4h period below:

Grafana_-_Home_Assistant

Any idea what can cause this?

@1liminal1
Copy link

1liminal1 commented Feb 24, 2022

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 :)

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
Copy link
Author

@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 🤓 (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
Copy link

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 :)

@markusressel
Copy link
Author

@Normanras
Copy link

This is really cool, thanks for setting it up! Did you wire the HX711 to the VIN/5v on your ESP device? I keep getting "HX711 is not ready to read values" in the ESPHome Logs and googling that error doesn't produce many results. Not many people have used this board with the ESPHome platform, so thanks for your experimentation!

@Mausbiber
Copy link

Mausbiber commented Sep 10, 2022

Hi,

I am trying to build a scale for an aquarium (I want to find out how much water evaporates) using 4 x load cells and a HX711 ADC converter.
I followed this example here for the wiring (I have the same load cells)

Now I have followed the example code in the esphome docs and I already get values back.
At least a success :slight_smile:

Here is my code:

sensor:
  - platform: dallas
    address: 0xee00000006ffb128
    name: "Aquarium Temperature"
    
  - platform: hx711
    name: "Aquarium Gewicht"
    id: smart_scale_hx711_value_raw
    dout_pin: GPIO16
    clk_pin: GPIO17
    gain: 128
    unit_of_measurement: kg
    accuracy_decimals: 3
    update_interval: 1s`

Next I wanted to calibrate the whole thing as indicated in the esphome docs.
But I can’t get any further here.

I have connected the 4 x load cells as described in the link and there is no weight at all, but I still get different raw values all the time.

Here is what the log says:

`[23:13:27][D][hx711:031]: 'Aquarium Gewicht': Got value 142727
[23:13:27][D][sensor:127]: 'Aquarium Gewicht': Sending state 142727.00000 kg with 3 decimals of accuracy
[23:13:28][D][hx711:031]: 'Aquarium Gewicht': Got value 142691
[23:13:28][D][sensor:127]: 'Aquarium Gewicht': Sending state 142691.00000 kg with 3 decimals of accuracy
[23:13:29][D][hx711:031]: 'Aquarium Gewicht': Got value 142741
[23:13:29][D][sensor:127]: 'Aquarium Gewicht': Sending state 142741.00000 kg with 3 decimals of accuracy
[23:13:29][D][api:102]: Accepted ::FFFF:C0A8:7FFE
[23:13:30][D][api.connection:861]: Home Assistant 2022.8.7 (::FFFF:C0A8:7FFE): Connected successfully
[23:13:30][D][hx711:031]: 'Aquarium Gewicht': Got value 142719
[23:13:30][D][sensor:127]: 'Aquarium Gewicht': Sending state 142719.00000 kg with 3 decimals of accuracy
[23:13:31][D][hx711:031]: 'Aquarium Gewicht': Got value 142671
[23:13:31][D][sensor:127]: 'Aquarium Gewicht': Sending state 142671.00000 kg with 3 decimals of accuracy
[23:13:32][D][hx711:031]: 'Aquarium Gewicht': Got value 142706
[23:13:32][D][sensor:127]: 'Aquarium Gewicht': Sending state 142706.00000 kg with 3 decimals of accuracy
[23:13:33][D][hx711:031]: 'Aquarium Gewicht': Got value 142632
[23:13:33][D][sensor:127]: 'Aquarium Gewicht': Sending state 142632.00000 kg with 3 decimals of accuracy
[23:13:34][D][hx711:031]: 'Aquarium Gewicht': Got value 142580
[23:13:34][D][sensor:127]: 'Aquarium Gewicht': Sending state 142580.00000 kg with 3 decimals of accuracy
[23:13:35][D][hx711:031]: 'Aquarium Gewicht': Got value 142630
[23:13:35][D][sensor:127]: 'Aquarium Gewicht': Sending state 142630.00000 kg with 3 decimals of accuracy
[23:13:36][D][hx711:031]: 'Aquarium Gewicht': Got value 142619
[23:13:36][D][sensor:127]: 'Aquarium Gewicht': Sending state 142619.00000 kg with 3 decimals of accuracy
[23:13:37][D][hx711:031]: 'Aquarium Gewicht': Got value 142586
[23:13:37][D][sensor:127]: 'Aquarium Gewicht': Sending state 142586.00000 kg with 3 decimals of accuracy
[23:13:38][D][hx711:031]: 'Aquarium Gewicht': Got value 142667
[23:13:38][D][sensor:127]: 'Aquarium Gewicht': Sending state 142667.00000 kg with 3 decimals of accuracy
[23:13:39][D][hx711:031]: 'Aquarium Gewicht': Got value 142539
[23:13:39][D][sensor:127]: 'Aquarium Gewicht': Sending state 142539.00000 kg with 3 decimals of accuracy
[23:13:40][D][hx711:031]: 'Aquarium Gewicht': Got value 142599
[23:13:40][D][sensor:127]: 'Aquarium Gewicht': Sending state 142599.00000 kg with 3 decimals of accuracy
[23:13:41][D][hx711:031]: 'Aquarium Gewicht': Got value 142565
[23:13:41][D][sensor:127]: 'Aquarium Gewicht': Sending state 142565.00000 kg with 3 decimals of accuracy
[23:13:42][D][hx711:031]: 'Aquarium Gewicht': Got value 142529
[23:13:42][D][sensor:127]: 'Aquarium Gewicht': Sending state 142529.00000 kg with 3 decimals of accuracy
[23:13:43][D][hx711:031]: 'Aquarium Gewicht': Got value 142524
[23:13:43][D][sensor:127]: 'Aquarium Gewicht': Sending state 142524.00000 kg with 3 decimals of accuracy
[23:13:44][D][hx711:031]: 'Aquarium Gewicht': Got value 142535
[23:13:44][D][sensor:127]: 'Aquarium Gewicht': Sending state 142535.00000 kg with 3 decimals of accuracy
[23:13:45][D][hx711:031]: 'Aquarium Gewicht': Got value 142517
[23:13:45][D][sensor:127]: 'Aquarium Gewicht': Sending state 142517.00000 kg with 3 decimals of accuracy
[23:13:46][D][hx711:031]: 'Aquarium Gewicht': Got value 142574
[23:13:46][D][sensor:127]: 'Aquarium Gewicht': Sending state 142574.00000 kg with 3 decimals of accuracy
[23:13:47][D][hx711:031]: 'Aquarium Gewicht': Got value 142515
[23:13:47][D][sensor:127]: 'Aquarium Gewicht': Sending state 142515.00000 kg with 3 decimals of accuracy
[23:13:48][D][hx711:031]: 'Aquarium Gewicht': Got value 142527
[23:13:48][D][sensor:127]: 'Aquarium Gewicht': Sending state 142527.00000 kg with 3 decimals of accuracy
[23:13:49][D][hx711:031]: 'Aquarium Gewicht': Got value 142562
[23:13:49][D][sensor:127]: 'Aquarium Gewicht': Sending state 142562.00000 kg with 3 decimals of accuracy
[23:13:50][D][hx711:031]: 'Aquarium Gewicht': Got value 142508
[23:13:50][D][sensor:127]: 'Aquarium Gewicht': Sending state 142508.00000 kg with 3 decimals of accuracy
[23:13:51][D][hx711:031]: 'Aquarium Gewicht': Got value 142530
[23:13:51][D][sensor:127]: 'Aquarium Gewicht': Sending state 142530.00000 kg with 3 decimals of accuracy
[23:13:52][D][hx711:031]: 'Aquarium Gewicht': Got value 142508
[23:13:52][D][sensor:127]: 'Aquarium Gewicht': Sending state 142508.00000 kg with 3 decimals of accuracy
[23:13:53][D][hx711:031]: 'Aquarium Gewicht': Got value 142544
[23:13:53][D][sensor:127]: 'Aquarium Gewicht': Sending state 142544.00000 kg with 3 decimals of accuracy
[23:13:54][D][hx711:031]: 'Aquarium Gewicht': Got value 142518
[23:13:54][D][sensor:127]: 'Aquarium Gewicht': Sending state 142518.00000 kg with 3 decimals of accuracy
[23:13:55][D][hx711:031]: 'Aquarium Gewicht': Got value 142501
[23:13:55][D][sensor:127]: 'Aquarium Gewicht': Sending state 142501.00000 kg with 3 decimals of accuracy
[23:13:56][D][hx711:031]: 'Aquarium Gewicht': Got value 142525
[23:13:56][D][sensor:127]: 'Aquarium Gewicht': Sending state 142525.00000 kg with 3 decimals of accuracy
[23:13:57][D][hx711:031]: 'Aquarium Gewicht': Got value 142504
[23:13:57][D][sensor:127]: 'Aquarium Gewicht': Sending state 142504.00000 kg with 3 decimals of accuracy
[23:13:58][D][hx711:031]: 'Aquarium Gewicht': Got value 142535
[23:13:58][D][sensor:127]: 'Aquarium Gewicht': Sending state 142535.00000 kg with 3 decimals of accuracy
[23:13:59][D][hx711:031]: 'Aquarium Gewicht': Got value 142555
[23:13:59][D][sensor:127]: 'Aquarium Gewicht': Sending state 142555.00000 kg with 3 decimals of accuracy
[23:14:00][D][hx711:031]: 'Aquarium Gewicht': Got value 142575
[23:14:00][D][sensor:127]: 'Aquarium Gewicht': Sending state 142575.00000 kg with 3 decimals of accuracy
[23:14:01][D][hx711:031]: 'Aquarium Gewicht': Got value 142577
[23:14:01][D][sensor:127]: 'Aquarium Gewicht': Sending state 142577.00000 kg with 3 decimals of accuracy
[23:14:02][D][hx711:031]: 'Aquarium Gewicht': Got value 142608
[23:14:02][D][sensor:127]: 'Aquarium Gewicht': Sending state 142608.00000 kg with 3 decimals of accuracy
[23:14:03][D][hx711:031]: 'Aquarium Gewicht': Got value 142667
[23:14:03][D][sensor:127]: 'Aquarium Gewicht': Sending state 142667.00000 kg with 3 decimals of accuracy
[23:14:04][D][hx711:031]: 'Aquarium Gewicht': Got value 142674
[23:14:04][D][sensor:127]: 'Aquarium Gewicht': Sending state 142674.00000 kg with 3 decimals of accuracy
[23:14:05][D][hx711:031]: 'Aquarium Gewicht': Got value 142793
[23:14:05][D][sensor:127]: 'Aquarium Gewicht': Sending state 142793.00000 kg with 3 decimals of accuracy
[23:14:06][D][hx711:031]: 'Aquarium Gewicht': Got value 142834
[23:14:06][D][sensor:127]: 'Aquarium Gewicht': Sending state 142834.00000 kg with 3 decimals of accuracy
[23:14:07][D][hx711:031]: 'Aquarium Gewicht': Got value 142847
[23:14:07][D][sensor:127]: 'Aquarium Gewicht': Sending state 142847.00000 kg with 3 decimals of accuracy
[23:14:08][D][hx711:031]: 'Aquarium Gewicht': Got value 142891
[23:14:08][D][sensor:127]: 'Aquarium Gewicht': Sending state 142891.00000 kg with 3 decimals of accuracy
[23:14:09][D][hx711:031]: 'Aquarium Gewicht': Got value 142935
[23:14:09][D][sensor:127]: 'Aquarium Gewicht': Sending state 142935.00000 kg with 3 decimals of accuracy

All these different values within 1 minute and there is no weight at all.
Why is this?
If the values are so extremely different, how can I calibrate the whole thing reasonably?
Above all, which of the many raw values do I use for 0 kg?

@markusressel
Copy link
Author

Please use the repository for questions and issues.
https://github.com/markusressel/ESPHome-Smart-Scale

@cayote64
Copy link

cayote64 commented Aug 23, 2023

I'm wondering if anyone can help.

I have used this with an ESP8266 board in an outside hedgehog box. It weighs the hogs as they are feeding. Everything works, however the zero reading drifts massively being outside. I have tried a previous auto tare which keeps the reading at 0g throughout the day, but the weight is quite a distance out once the temperatures drop on the night.

Can anyone include some code so that I can use a spare GPIO pin on the board so as the hog enters the box, the scales zero themselves before it reaches the main compartment ?

Current code is:

globals:

  • id: constant_weight
    type: float

`captive_portal:

sensor:

  • platform: hx711
    id: weight
    name: "HX711 Value2"
    dout_pin: GPIO14
    clk_pin: GPIO12
    gain: 128
    update_interval: 5s
    unit_of_measurement: g
    filters:
    calibrate_linear:
    - 68604 -> 0
    - 626959 -> 2030
    on_value:
    - if:
    condition:
    - lambda: |-
    static float last = 0.0;
    float diff = x - last;
    last = x;
    return x < 50.0 && diff < 1.0 && diff > - 1.0;
    then:
    - lambda: 'id(constant_weight) = x;'

  • platform: template
    name: Hog Weight2
    icon: mdi:scalee
    unit_of_measurement: g
    accuracy_decimals: 0
    lambda: 'return id(weight).state;'
    filters:
    - lambda: 'return x - id(constant_weight);'
    - lambda: 'return x >= 10.0 ? x : 0;'
    - delta: 0.5`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment