SHOW:
|
|
- or go back to the newest paste.
| 1 | ## Node configuration ## | |
| 2 | # Source https://gist.github.com/markusressel/e888544d4404fbed4c841ec83df638bb | |
| 3 | # markusressel/esphome_hx711_smart_scale.yaml | |
| 4 | ||
| 5 | esphome: | |
| 6 | - | name: smart_scale |
| 6 | + | name: scale-01 |
| 7 | platform: ESP8266 | |
| 8 | - | board: nodemcuv2 |
| 8 | + | board: esp12e |
| 9 | ||
| 10 | globals: | |
| 11 | - | - id: initial_zero |
| 11 | + | - id: scale_01_initial_zero |
| 12 | type: float | |
| 13 | restore_value: yes | |
| 14 | # NOTE: make sure to align this value to the one used in "calibrate_linear" below! | |
| 15 | - | initial_value: '-481989' |
| 15 | + | initial_value: '-31060' #'-481989' |
| 16 | ||
| 17 | - | - id: auto_tare_enabled |
| 17 | + | - id: scale_01_auto_tare_enabled |
| 18 | type: bool | |
| 19 | restore_value: yes | |
| 20 | initial_value: 'true' | |
| 21 | ||
| 22 | - | - id: auto_tare_difference |
| 22 | + | - id: scale_01_auto_tare_difference |
| 23 | type: float | |
| 24 | restore_value: yes | |
| 25 | initial_value: '0' | |
| 26 | ||
| 27 | - | - id: manual_tare_flag |
| 27 | + | - id: scale_01_manual_tare_flag |
| 28 | type: bool | |
| 29 | restore_value: no | |
| 30 | initial_value: 'false' | |
| 31 | ||
| 32 | wifi: | |
| 33 | - | fast_connect: True # needed for hidden SSID |
| 33 | + | ssid: !secret wifi_ssid |
| 34 | - | networks: |
| 34 | + | password: !secret wifi_password |
| 35 | - | - ssid: 'YourSSID' |
| 35 | + | |
| 36 | - | bssid: '00:00:00:00:00:00' |
| 36 | + | #wifi: |
| 37 | - | password: 'YourPassword' |
| 37 | + | # fast_connect: True # needed for hidden SSID |
| 38 | - | hidden: true |
| 38 | + | #networks: |
| 39 | # - ssid: 'YourSSID' | |
| 40 | # bssid: '00:00:00:00:00:00' | |
| 41 | # password: 'YourPassword' | |
| 42 | #hidden: true | |
| 43 | #manual_ip: | |
| 44 | # static_ip: 192.168.5.49 | |
| 45 | # gateway: 192.168.5.1 | |
| 46 | # subnet: 255.255.255.0 | |
| 47 | ||
| 48 | api: | |
| 49 | password: "YourApiPassword" | |
| 50 | ||
| 51 | # Enable logging | |
| 52 | - | password: 'YourOtaPassword' |
| 52 | + | |
| 53 | level: ERROR | |
| 54 | ||
| 55 | ||
| 56 | ota: | |
| 57 | password: "06e5dcb2cfe4950d74460306be7606c1" | |
| 58 | ||
| 59 | status_led: | |
| 60 | pin: | |
| 61 | number: GPIO2 | |
| 62 | - | id: smart_scale_continuous_tare_enabled |
| 62 | + | |
| 63 | - | name: "Smart Scale Continuous Tare Enabled" |
| 63 | + | |
| 64 | switch: | |
| 65 | - | return id(auto_tare_enabled); |
| 65 | + | |
| 66 | - platform: template | |
| 67 | id: smart_scale_01_continuous_tare_enabled | |
| 68 | - | id(auto_tare_enabled) = true; |
| 68 | + | name: "Smart Scale 01 Continuous Tare Enabled" |
| 69 | lambda: |- | |
| 70 | return id(scale_01_auto_tare_enabled); | |
| 71 | - | id(auto_tare_enabled) = false; |
| 71 | + | |
| 72 | - lambda: |- | |
| 73 | id(scale_01_auto_tare_enabled) = true; | |
| 74 | turn_off_action: | |
| 75 | - | id: smart_scale_manual_tare_action_switch |
| 75 | + | |
| 76 | - | name: "Smart Scale Manual Tare Action" |
| 76 | + | id(scale_01_auto_tare_enabled) = false; |
| 77 | ||
| 78 | - | return id(manual_tare_flag); |
| 78 | + | |
| 79 | - platform: template | |
| 80 | id: smart_scale_01_manual_tare_action_switch | |
| 81 | - | id(auto_tare_difference) = id(initial_zero) - id(smart_scale_hx711_value_raw).state; |
| 81 | + | name: "Smart Scale 01 Manual Tare Action" |
| 82 | - | - switch.turn_off: smart_scale_manual_tare_action_switch |
| 82 | + | |
| 83 | return id(scale_01_manual_tare_flag); | |
| 84 | turn_on_action: | |
| 85 | - | id(manual_tare_flag) = false; |
| 85 | + | |
| 86 | id(scale_01_auto_tare_difference) = id(scale_01_initial_zero) - id(smart_scale_01_hx711_value_raw).state; | |
| 87 | - switch.turn_off: smart_scale_01_manual_tare_action_switch | |
| 88 | turn_off_action: | |
| 89 | - lambda: |- | |
| 90 | - | id: smart_scale_initial_zero |
| 90 | + | id(scale_01_manual_tare_flag) = false; |
| 91 | - | name: "Smart Scale Initial Zero" |
| 91 | + | |
| 92 | sensor: | |
| 93 | - | return id(initial_zero); |
| 93 | + | |
| 94 | - platform: template | |
| 95 | id: smart_scale_01_initial_zero | |
| 96 | name: "Smart Scale 01 Initial Zero" | |
| 97 | - | id: smart_scale_auto_tare_difference |
| 97 | + | |
| 98 | - | name: "Smart Scale Auto Tare Difference" |
| 98 | + | return id(scale_01_initial_zero); |
| 99 | update_interval: 1s | |
| 100 | - | return id(auto_tare_difference); |
| 100 | + | |
| 101 | - platform: template | |
| 102 | id: smart_scale_01_auto_tare_difference | |
| 103 | name: "Smart Scale 01 Auto Tare Difference" | |
| 104 | lambda: |- | |
| 105 | - | id: homeassistant_initial_zero |
| 105 | + | return id(scale_01_auto_tare_difference); |
| 106 | - | entity_id: input_number.smart_scale_initial_zero |
| 106 | + | |
| 107 | ||
| 108 | # sensors imported from home assistant | |
| 109 | - platform: homeassistant | |
| 110 | - | id(initial_zero) = x; |
| 110 | + | id: homeassistant_scale_01_initial_zero |
| 111 | entity_id: input_number.smart_scale_01_initial_zero | |
| 112 | on_value: | |
| 113 | then: | |
| 114 | - | id: smart_scale_hx711_value_raw |
| 114 | + | |
| 115 | - | internal: True |
| 115 | + | id(scale_01_initial_zero) = x; |
| 116 | - | dout_pin: D0 |
| 116 | + | |
| 117 | - | clk_pin: D1 |
| 117 | + | |
| 118 | - platform: hx711 | |
| 119 | - | unit_of_measurement: kg |
| 119 | + | id: smart_scale_01_hx711_value_raw |
| 120 | - | accuracy_decimals: 3 |
| 120 | + | internal: True # <-- change this to False to see raw data |
| 121 | dout_pin: MISO #D0 | |
| 122 | clk_pin: SCK #D1 | |
| 123 | gain: 128 | |
| 124 | unit_of_measurement: g | |
| 125 | accuracy_decimals: 6 | |
| 126 | update_interval: 0.2s | |
| 127 | filters: | |
| 128 | - sliding_window_moving_average: | |
| 129 | - | id: smart_scale_hx711_value |
| 129 | + | |
| 130 | - | state: !lambda 'return id(smart_scale_hx711_value_raw).state;' |
| 130 | + | |
| 131 | on_value: | |
| 132 | then: | |
| 133 | - sensor.template.publish: | |
| 134 | - | - lambda: 'return id(auto_tare_enabled);' |
| 134 | + | id: smart_scale_01_hx711_value |
| 135 | state: !lambda 'return id(smart_scale_01_hx711_value_raw).state;' | |
| 136 | - | - lambda: 'return id(smart_scale_hx711_value).state < 10.0;' |
| 136 | + | |
| 137 | condition: | |
| 138 | and: | |
| 139 | - lambda: 'return id(scale_01_auto_tare_enabled);' | |
| 140 | # current smart scale value is below approx. 10KG (raw value -275743) aka nobody is standing on the scale | |
| 141 | - | - lambda: 'return id(smart_scale_hx711_value_raw).state < (id(initial_zero) - id(auto_tare_difference));' |
| 141 | + | - lambda: 'return id(smart_scale_01_hx711_value).state < 10.0;' |
| 142 | then: | |
| 143 | - if: | |
| 144 | condition: | |
| 145 | - | id(auto_tare_difference) += 10; |
| 145 | + | |
| 146 | - lambda: 'return id(smart_scale_01_hx711_value_raw).state < (id(scale_01_initial_zero) - id(scale_01_auto_tare_difference));' | |
| 147 | then: | |
| 148 | # INcrease Auto-Tare offset to slowly align real zero value with expected zero value | |
| 149 | - | id(auto_tare_difference) -= 10; |
| 149 | + | |
| 150 | id(scale_01_auto_tare_difference) += 1.0; | |
| 151 | - | # Mapped value to KG |
| 151 | + | |
| 152 | # DEcrease Auto-Tare offset to slowly align real zero value with expected zero value | |
| 153 | - | id: smart_scale_hx711_value |
| 153 | + | |
| 154 | - | name: "Smart Scale HX711 Value" |
| 154 | + | id(scale_01_auto_tare_difference) -= 1.0; |
| 155 | ||
| 156 | # Mapped value to g | |
| 157 | - platform: template | |
| 158 | - | - lambda: 'return x + id(auto_tare_difference);' |
| 158 | + | id: smart_scale_01_hx711_value |
| 159 | name: "Smart Scale 01 HX711 Value" | |
| 160 | internal: False | |
| 161 | filters: | |
| 162 | # apply auto_tare difference | |
| 163 | - lambda: 'return x + id(scale_01_auto_tare_difference);' | |
| 164 | - | - -481989 -> 0 |
| 164 | + | |
| 165 | - | - 1339163 -> 88.3 |
| 165 | + | |
| 166 | # retrieve these values by evaluating the raw values with loads of known mass. | |
| 167 | # note that a bigger difference between measurements usually results in higher resolution, | |
| 168 | # so measure 0 Kg and the highest known mass you have (like f.ex. your own weight, measured by a normal scale with good accuracy) | |
| 169 | #- -481989 -> 0 | |
| 170 | #- 1339163 -> 88.3 | |
| 171 | - -31060 -> 0.00000 | |
| 172 | #- -39684 -> 1.00000 | |
| 173 | - -16974 -> 10.00000 | |
| 174 | - | unit_of_measurement: kg |
| 174 | + | - 59674 -> 50.00000 |
| 175 | - | accuracy_decimals: 2 |
| 175 | + | - 349441 -> 200.00000 |
| 176 | - | update_interval: 0.2s |
| 176 | + | - 441888 -> 250.00000 |
| 177 | - 733483 -> 400.00000 | |
| 178 | - 926142 -> 500.00000 | |
| 179 | - 1310869 -> 700.00000 | |
| 180 | - 1694630 -> 900.00000 | |
| 181 | - 1886776 -> 1000.00000 | |
| 182 | # map values below 0.1 to 0 (to decrease value changes due to random fluctuation) | |
| 183 | - lambda: |- | |
| 184 | if (x <= 0.1) {
| |
| 185 | return 0.0; | |
| 186 | } else {
| |
| 187 | return x; | |
| 188 | } | |
| 189 | ||
| 190 | unit_of_measurement: g | |
| 191 | accuracy_decimals: 6 | |
| 192 | update_interval: 0.2s | |
| 193 | force_update: True |