Home Elements Boards Recipes

Touch Element

The TouchElement enables creating Actions by using touch input feature of the ESP32 than detects changes in the capacity e.g. when a finger is nearby.

This is a hardware supported detection available on some GPIO without further hardware requirements. This allows really cheap input implementations using a 1cm² pad under a isolation foil.

The GPIO contact must not be touched directly.

The touch functionality is not available on ESP8266 processor so this element will not be part of a ESP8266 firmware.

When using an ESP8266 or other processors there are sensor boards using special chips or transistors to create a binary signal from a touch gesture. For these solutions a simple DigitalInput Element can be used as input element.

There are also touch sensors implementations available that use 2 pins to probe for the capacity resistance using a ADC. But there is only one ADC input in the ESP8266 processors available.

Connecting a Touch Sensor

A touch sensor is built by a simple electrically conductive area. This allows detecting a finger or a equivalent object nearby as this changes the capacity resistance. It is actually not required to create a electric contact with the finger and is recommended to add a isolating on to of the area.

The ESP32 processors supports a capacitive touch detection on most GPIOs in the chip that can be used to replace momentary buttons by simple pads. The value generated by the touch input is typically varying between 40 and 80 while lower numbers are created when the capacity is higher caused by the finger nearby. A reference value can be set to create the binary value that is HIGH(1) when touched and LOW(0) otherwise.

Element Configuration

pin* – the GPIO pin used for input.

reference – the reference value that is used to compare touch vs no-touch capacity values. The default setting is 65.

onHigh – These actions are emitted when the logical level is switched to 1.

onLow – These actions are emitted when the logical level is switched to 0.

onValue – These actions are emitted when the logical level is switched.

From the base element implementation the following properties are available for configuration:

title – Caption text for the element. Used by the element specific cards on the dash boards.

description – A line of text that gives a short description of the device used in the web UI.

room – The location of the device.

loglevel – This property holds the element specific log level. The default value is LOGGER_LEVEL_ERR == 1.

startup – This property can be used to start the element using a different initialization phase. Possible values are “sys”, “net”, “time”. See The Startup sequence.

* This parameter must be specified.

Configuration Example

This example shows how to configure this element:

{
  "touch": {
    "4": {
      "title": "touch",
      "description": "touch sensor",
      "pin": "4",
      "onvalue": "digitalout/led?value=$v"
    }
  },
  "digitalout": {
    "led": {
      "pin": "27",
      "invert": "1"
    }
  },
}

State

The state of the TouchElement Element available at runtime includes the current values:

active - Is set to true when the Element is active.

value - The current output value from the generated pulse.

Example State

{
  "touch/4": {
    "active":"true",
    "value":"0"
  },
}

See also

Tags

Element Input