Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Node configuration ##
- # Source https://gist.github.com/markusressel/e888544d4404fbed4c841ec83df638bb
- # markusressel/esphome_hx711_smart_scale.yaml
- esphome:
- name: scale-01
- platform: ESP8266
- board: esp12e
- globals:
- - id: scale_01_initial_zero
- type: float
- restore_value: yes
- # NOTE: make sure to align this value to the one used in "calibrate_linear" below!
- initial_value: '-31060' #'-481989'
- - id: scale_01_auto_tare_enabled
- type: bool
- restore_value: yes
- initial_value: 'true'
- - id: scale_01_auto_tare_difference
- type: float
- restore_value: yes
- initial_value: '0'
- - id: scale_01_manual_tare_flag
- type: bool
- restore_value: no
- initial_value: 'false'
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- #wifi:
- # fast_connect: True # needed for hidden SSID
- #networks:
- # - ssid: 'YourSSID'
- # bssid: '00:00:00:00:00:00'
- # password: 'YourPassword'
- #hidden: true
- #manual_ip:
- # static_ip: 192.168.5.49
- # gateway: 192.168.5.1
- # subnet: 255.255.255.0
- api:
- password: "YourApiPassword"
- # Enable logging
- logger:
- level: ERROR
- ota:
- password: "06e5dcb2cfe4950d74460306be7606c1"
- status_led:
- pin:
- number: GPIO2
- inverted: True
- switch:
- ## Switch to enable/disable the auto tare feature
- - platform: template
- id: smart_scale_01_continuous_tare_enabled
- name: "Smart Scale 01 Continuous Tare Enabled"
- lambda: |-
- return id(scale_01_auto_tare_enabled);
- turn_on_action:
- - lambda: |-
- id(scale_01_auto_tare_enabled) = true;
- turn_off_action:
- - lambda: |-
- id(scale_01_auto_tare_enabled) = false;
- ## Switch used to initiate a manual tare
- - platform: template
- id: smart_scale_01_manual_tare_action_switch
- name: "Smart Scale 01 Manual Tare Action"
- lambda: |-
- return id(scale_01_manual_tare_flag);
- turn_on_action:
- - lambda: |-
- id(scale_01_auto_tare_difference) = id(scale_01_initial_zero) - id(smart_scale_01_hx711_value_raw).state;
- - switch.turn_off: smart_scale_01_manual_tare_action_switch
- turn_off_action:
- - lambda: |-
- id(scale_01_manual_tare_flag) = false;
- ## Sensor Configuration ##
- sensor:
- # template sensors from global variables
- - platform: template
- id: smart_scale_01_initial_zero
- name: "Smart Scale 01 Initial Zero"
- lambda: |-
- return id(scale_01_initial_zero);
- update_interval: 1s
- - platform: template
- id: smart_scale_01_auto_tare_difference
- name: "Smart Scale 01 Auto Tare Difference"
- lambda: |-
- return id(scale_01_auto_tare_difference);
- update_interval: 1s
- # sensors imported from home assistant
- - platform: homeassistant
- id: homeassistant_scale_01_initial_zero
- entity_id: input_number.smart_scale_01_initial_zero
- on_value:
- then:
- - lambda: |-
- id(scale_01_initial_zero) = x;
- # RAW Scale input
- - platform: hx711
- id: smart_scale_01_hx711_value_raw
- internal: True # <-- change this to False to see raw data
- dout_pin: MISO #D0
- clk_pin: SCK #D1
- gain: 128
- unit_of_measurement: g
- accuracy_decimals: 6
- update_interval: 0.2s
- filters:
- - sliding_window_moving_average:
- window_size: 3
- send_every: 1
- on_value:
- then:
- - sensor.template.publish:
- id: smart_scale_01_hx711_value
- state: !lambda 'return id(smart_scale_01_hx711_value_raw).state;'
- - if:
- condition:
- and:
- - lambda: 'return id(scale_01_auto_tare_enabled);'
- # current smart scale value is below approx. 10KG (raw value -275743) aka nobody is standing on the scale
- - lambda: 'return id(smart_scale_01_hx711_value).state < 10.0;'
- then:
- - if:
- condition:
- # current raw scale value is below expected zero value
- - lambda: 'return id(smart_scale_01_hx711_value_raw).state < (id(scale_01_initial_zero) - id(scale_01_auto_tare_difference));'
- then:
- # INcrease Auto-Tare offset to slowly align real zero value with expected zero value
- - lambda: |-
- id(scale_01_auto_tare_difference) += 1.0;
- else:
- # DEcrease Auto-Tare offset to slowly align real zero value with expected zero value
- - lambda: |-
- id(scale_01_auto_tare_difference) -= 1.0;
- # Mapped value to g
- - platform: template
- id: smart_scale_01_hx711_value
- name: "Smart Scale 01 HX711 Value"
- internal: False
- filters:
- # apply auto_tare difference
- - lambda: 'return x + id(scale_01_auto_tare_difference);'
- # apply rough calibration
- - calibrate_linear:
- # retrieve these values by evaluating the raw values with loads of known mass.
- # note that a bigger difference between measurements usually results in higher resolution,
- # 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)
- #- -481989 -> 0
- #- 1339163 -> 88.3
- - -31060 -> 0.00000
- #- -39684 -> 1.00000
- - -16974 -> 10.00000
- - 59674 -> 50.00000
- - 349441 -> 200.00000
- - 441888 -> 250.00000
- - 733483 -> 400.00000
- - 926142 -> 500.00000
- - 1310869 -> 700.00000
- - 1694630 -> 900.00000
- - 1886776 -> 1000.00000
- # map values below 0.1 to 0 (to decrease value changes due to random fluctuation)
- - lambda: |-
- if (x <= 0.1) {
- return 0.0;
- } else {
- return x;
- }
- unit_of_measurement: g
- accuracy_decimals: 6
- update_interval: 0.2s
- force_update: True
Add Comment
Please, Sign In to add comment