[SOLVED] Is it possible to have the numeric value of an ESPHome touch sensor in a sensor entity in HA?

Hello,
I built myself a bed occupancy sensor using this guide, but I only use one, larger pad which is about the size of two A4 sheets of paper:

It uses the ESP32 touch sensor component of ESPHome and works really well.

Can I have the raw (numeric) value of such a touch sensor (the number that it shows in the log while using setup_mode: true) in a HA sensor entity and if yes, how?

I want to monitor the readings over longer periods while testing, and a sensor entity would be perfect for that as I could use the built-in average and chart features of HA

How can I export such an entity to HA from ESPHome ?

Thanks for your help
Aaron

Might be also interresting for your endeavour

@orange-assistant
Thanks for your help,
The problem is that I the post you linked is for FSRs but the sensor I use is basically a pressure-dependant capacitor, and I don’t know if (and if yes, how) it’s possible to access the numeric value of the ESP32 touch component in a lambda for use in such an entity

Best regards
Aaron

1 Like

Doesn’t look like the value is exposed except in the logger, as you’ve found.

You might be able to leave it in setup_mode and use on_message trigger to publish the value to a sensor.

Not sure how that would perform.

1 Like

How could I get the numeric value?
My log lines look like this:

[13:58:08][D][esp32_touch:126]: Touch Pad 'Bettsensor' (T8): 6

Where I only need the value at the end (in this case it’s 6)

I don’t know top of head. I’d have to sit down and tinker. And I’d probably be asking They Who Shall Not Be Named for help on spitting off the last numeric characters assuming that is available in the message (const char * ) part you can access with on_message.

The approach I’d be trying would roughly be:

  1. Set up the on_message trigger
  2. Set up a template sensor
  3. Use a lambda in the on_message to parse off the value.
  4. Publish the value to the template sensor.

I know that’s not very detailed but it’s all I can offer just now;)

The sample code from this post should do what you want.

2 Likes

Nice. I’m curious as to how you discovered get_value().

Did you dig into the api or source code?

That was too long ago to recall for sure but I usually start with the API to look for such things and go from there.

1 Like