Skip to content

Instantly share code, notes, and snippets.

@markusressel
Last active March 12, 2024 05:05
Show Gist options
  • 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
@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