Home Assistant polling esphome for one value?

I’m trying to build a scale with esphome. The idea is that the Home Assistant polls one valid reading from the esphome device.

So, while standing on the scale, one could press a button and then get one value to be logged in the home assistant.

I found the binary_sensor class, but it seems to generate an on/off switch instead of a click.
The hx711 scale sensor readint is set to internal. Is there some kind of on_click functionality there?

Also, how would I “publish” a reading? I set the sensor itself to internal so that I can still run the filter and integrations.

Some pointers would be nice.

# Load cell sensor
sensor:
  - platform: hx711
    name: "Gewicht"
    id: Gewicht
    dout_pin: D1
    clk_pin: D2
    gain: 128
    accuracy_decimals: 1
    update_interval: 10ms
    unit_of_measurement: "kg "
    internal: True 
    filters:
      - multiply: -1
      - sliding_window_moving_average:
          window_size: 50
      - calibrate_linear:
         - 292711 -> 0
         - 2438880 -> 85

# Display readings on led display
display:
    platform: tm1637
    id: tm1637_display
    clk_pin: D6
    dio_pin: D5
    lambda: |-
      it.printf(0, "%2.1f", id(Gewicht).state);

binary_sensor:
  - platform: homeasistant
    name: "Save Reading"

Use the binary sensor “on click trigger”

To publish the load cell value to a template sensor:

1 Like
binary_sensor:
  - platform: homeassistant
    entity_id: input_boolean.state_home
    name: "Save Reading"
    on_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - sensor.hx711.publish:
          state: Gewicht

I seem to missunderstand the way to publish the reading from the documentation.

Now I got it so far that it a. compiles and b. shows a proper button. However, it does not seem to work and publish the value as I’d like:

sensor:
  - platform: hx711
    name: "Gewicht Sensor"
    id: Gewicht
    dout_pin: D1
    clk_pin: D2
    gain: 128
    accuracy_decimals: 1
    update_interval: 1s
    unit_of_measurement: "kg "
    internal: True
    filters:
      - multiply: -1
      - sliding_window_moving_average:
          window_size: 1
      - calibrate_linear:
         - 292711 -> 0
         - 2438880 -> 85

  - platform: template
    name: "Gewicht Andreas"
    id: gewicht_andreas
   

# Example configuration entry
display:
    platform: tm1637
    id: tm1637_display
    clk_pin: D6
    dio_pin: D5
    lambda: |-
      it.printf(0, "%2.1f", id(Gewicht).state);

binary_sensor:
  - platform: homeassistant
    entity_id: input_boolean.state_home
    name: "Save Reading"
    on_click:
      min_length: 50ms
      max_length: 350ms
      then:
        sensor.template.publish:
          id: gewicht_andreas
          state: !lambda 'return(id(Gewicht).state);'

I have now the following working:

cover:
  - platform: template
    name: "Gewicht Andreas"
    id: speichere_gewicht_andreas
    stop_action:
      sensor.template.publish:
        id: gewicht_andreas
        state: !lambda 'return(id(Gewicht).state);'

This shows up in home assistant and when I click the stop button, the value is updated as expected. However it is supposed to work with binary_sensor:

binary_sensor:
  - platform: homeassistant
    entity_id: binary_sensor.save_reading
    name: "Save Reading"
    on_press:
      sensor.template.publish:
        id: gewicht_andreas
        state: !lambda 'return(id(Gewicht).state);'

However this does not work and results in a failed to call service error… And I don’t see why?

Attached bellow are the home assistant settings.
Full code:

sensor:
  - platform: hx711
    name: "Gewicht Sensor"
    id: Gewicht
    dout_pin: D1
    clk_pin: D2
    gain: 128
    accuracy_decimals: 1
    update_interval: 1s
    unit_of_measurement: "kg "
    internal: True
    filters:
      - multiply: -1
      - sliding_window_moving_average:
          window_size: 1
      - calibrate_linear:
         - 292711 -> 0
         - 2438880 -> 85
  - platform: template
    name: "Gewicht Andreas"
    id: gewicht_andreas

display:
    platform: tm1637
    id: tm1637_display
    clk_pin: D6
    dio_pin: D5
    lambda: |-
      it.printf(0, "%2.1f", id(Gewicht).state);

cover:
  - platform: template
    name: "Gewicht Andreas"
    id: speichere_gewicht_andreas
    stop_action:
      sensor.template.publish:
        id: gewicht_andreas
        state: !lambda 'return(id(Gewicht).state);'

binary_sensor:
  - platform: homeassistant
    entity_id: binary_sensor.save_reading
    name: "Save Reading"
    on_press:
      sensor.template.publish:
        id: gewicht_andreas
        state: !lambda 'return(id(Gewicht).state);'