Send data by pressing a button

hello, I’m new to esphome, I can’t find what command to use in an esp32 to send data when pressing a button, I need to have a scale and that the HA only takes the weight when a physical button is pressed in the place, so in the database I have the confirmed weight of the operator. thanks greetings .
Cesar

I am not sure of your use case - the simpler method would have your button and temp sensors just as normal in ESPHome, then have an automation in HA that does whatever you want with the current temperature when the button is clicked.

If you really want a sensor only published when a button is pushed, create a template sensor with a ridiculously long update interval (maybe 0s disables updates??). This sensor would just mirror the real temperature sensor. Use some lambda in an ESPHome on_click automation to publish that sensor on button push.

You can set the button and the “real” temp sensor as disabled_by_default: true to stop them publishing to HA.

This is all much more complicated than just reacting to a button press in HA.

You can start by posting the relevant yaml config, this way, we can see what, and how your devices are configured, and make some recommendations.

Nevertheless, if it’s an actual temp sensor connected to Esphome Device, you can mark it for internal use, then create a template sensor for the temperature and update that sensor when you press the button.

thank you very much Daryl, I analyze your help, specifically I need to have a scale and that the HA only takes the weight when a physical button is pressed in the place, so in the database I have the confirmed weight of the operator… thank you very much for your help
Cheers
Cesar

Did you get something to work? If not, post your yaml as Coolie suggested. Don’t forget to format your post correctly, especially code which should be quoted as per this article:

Good morning Daryl and Culi, I’m waiting for you to get me the components so I set up the scale or balance and see how it works, my query was advanced, since I didn’t find or I don’t realize how to make it send the weight when I press a switch on the scale or balance… soon I hope to publish the yaml
thank you very much greetings
Cesar

I suggest you start by getting the button and sensor working in ESPhome, then look at the automation documentation and attempt the template sensor as well.

In your yaml you will need:

  • the weight sensor, with disabled_by_default set to true
  • the button (GPIO Binary Sensor), also with disabled_by_default set to true + an on_press event to trigger publishing the template sensor
  • a template (Text) sensor that returns the value of your weight sensor
1 Like