Connecting a bathroom scale to homeassistant

Hi everyone, I want to hack a scale and use esp8266 and hx711 to automatically pass measurements to home assistant, where I would display it as a sensor.
I know esphome has a HX711 component but I don’t want to update home assistant every time interval. Instead, I want to make sure that a few conditions are met before updating:

  1. The wight was close to zero in the previous measurement.
  2. The weight is above some minimum value.
  3. The weight is somewhat stable: I want to take measurements every 100-250ms and filter out a result if it is too far from the last 2-5 measurements. This is to make sure the object is stabilized.

Are there a built-in methods that achieve something similar, so I can use the hx711 component, or do I need to write the code myself?
Also, if the answer is to use lambdas, then how can I access past results, and how to publish manually to home assistant?
Bonus question, this should run on battaries, so if you think incorporating a switch or use some other technique saves energy, I’d like to know.

Thanks in advance

The platform is a sensor and therefore supports all the sensor filters. There is even an example in the HX711 configuration. There is a lambda filter there, so you can write whatever you want with the current value. You might be able to make a global variable for storing the last value.

With your three conditions, my guess is that you would never get a signal however. Both points two and three will contradict point one. I think in point one, the intent is to only report values after you’ve stepped on it, not before. I also assume you only want one value reported per time stepping on scale.
But this is all tricky.

One thought is to have a button you can press that will publish the data only once to home assistant when it is stabilized.

1 Like

This might be also used to wake up the unit from a deep sleep. You could have two buttons, a wake button and a report button.

Thank!
Using a global var (array) is a good suggestion for getting the condition exactly the way I want it.

So using lambda calls, if I set the update_interval to say 0.25s, this would reflect the sampling and not the publishing, correct?
In this case there’s probably a method for sending a signal to home assistant, or maybe it just publishes what I return (if I return?), anyways I’ll look it up :slight_smile:. thanks for your help

p.s. regarding point 1, I didn’t specify my plan accurately, and ofcourse you’re right in pointing out the current contradiction.

If you publish a sensor, it will push all values according to update_interval unless you use one of the filters that modifies it.

If you want to decouple the sensor reading and publishing completely, I’d recommend using a template sensor that publishes to home assistant, and keep the hx711 sensor internal to esphome. You can use the hx711 sensor with logic to push values to the template sensor when you want to publish.

I understand. Great, thank you