LIS2DH12 Sensor
Component/Hub
Section titled “Component/Hub”The lis2dh12 sensor platform allows you to use your ST LIS2DH12 ultra-low-power tri-axial
accelerometer (datasheet)
with ESPHome via the I²C bus.
LIS2DH12 is a high-performance accelerometer with selectable resolution (12-bit, 10-bit, or 8-bit), tap/double-tap (click) detection, free-fall detection, activity/inactivity detection, and 6D orientation recognition.
This component provides acceleration data in m/s², orientation information, and event detection. XYZ axes can be calibrated and transformed to match the physical orientation of the sensor.
# Example I2C configurationlis2dh12_i2c: range: 4G resolution: high output_data_rate: 100Hz update_interval: 10sConfiguration variables
Section titled “Configuration variables”-
update_interval (Optional, Time): The interval for updating acceleration sensors. Defaults to
10s. -
range (Optional, string): The range of the sensor measurements. One of
2G,4G,8G,16G. Defaults to2Gwhich means it picks up accelerations between-2gand2g. -
resolution (Optional, string): ADC resolution mode. One of
high(12-bit),medium(10-bit),low(8-bit). Defaults tohigh. -
output_data_rate (Optional, string): Output data rate. One of
1Hz,10Hz,25Hz,50Hz,100Hz,200Hz,400Hz,1620Hz,5376Hz. Defaults to100Hz. -
calibration (Optional):
- offset_x (Optional, float): X-axis zero position calibration, in m/s². From -4.5 to 4.5. Defaults to
0. - offset_y (Optional, float): Y-axis zero position calibration, in m/s². From -4.5 to 4.5. Defaults to
0. - offset_z (Optional, float): Z-axis zero position calibration, in m/s². From -4.5 to 4.5. Defaults to
0.
- offset_x (Optional, float): X-axis zero position calibration, in m/s². From -4.5 to 4.5. Defaults to
-
transform (Optional):
- mirror_x (Optional, boolean): Mirror X-axis. Defaults to
false. - mirror_y (Optional, boolean): Mirror Y-axis. Defaults to
false. - mirror_z (Optional, boolean): Mirror Z-axis. Defaults to
false. - swap_xy (Optional, boolean): Swap X and Y axis. Defaults to
false.
- mirror_x (Optional, boolean): Mirror X-axis. Defaults to
-
All options from I²C Device. Default address is
0x19.
Sensor
Section titled “Sensor”Acceleration data is available through sensors configuration.
You can use shorthand notation like acceleration_x: "Acceleration X" or use regular notation. For
regular notation only the name is required. All options from Sensor.
sensor: - platform: lis2dh12_base acceleration_x: Accel X acceleration_y: Accel Y acceleration_z: Accel ZConfiguration variables
Section titled “Configuration variables”- acceleration_x (Optional): X-axis acceleration, m/s².
- acceleration_y (Optional): Y-axis acceleration, m/s².
- acceleration_z (Optional): Z-axis acceleration, m/s².
Binary Sensor
Section titled “Binary Sensor”Four binary sensors available for use. Internal 500 ms debounce is applied for all sensors. For every sensor name is required. All other options from Binary Sensor. Shorthand notation also can be used.
binary_sensor: - platform: lis2dh12_base tap: Single tap # shorthand notation for the sensor double_tap: Double tap # -- "" -- freefall: Freefall # -- "" -- active: # regular notation for the sensor to be able name: Active # to use filters and other options filters: - delayed_off: 5000ms # example of prolongation of movement detection signalConfiguration variables
Section titled “Configuration variables”- tap (Optional): Single tap (click) detection.
- double_tap (Optional): Double tap (double-click) detection.
- freefall (Optional): Free-fall detection.
- active (Optional): Movement detection.
Text Sensor
Section titled “Text Sensor”Text sensor provides 6D orientation information based on the dominant gravity axis. Uses 6D position recognition mode with ~60° threshold per ST DT0097 application note.
text_sensor: - platform: lis2dh12_base orientation: OrientationConfiguration variables
Section titled “Configuration variables”- orientation (Optional): 6D orientation. Can be one of
Face Up,Face Down,Portrait Up,Portrait Down,Landscape Left,Landscape Right.
Automations
Section titled “Automations”on_tap trigger
Section titled “on_tap trigger”This automation will be triggered when single tap is detected.
lis2dh12_i2c: # ... on_tap: - then: - logger.log: "Tapped"on_double_tap trigger
Section titled “on_double_tap trigger”This automation will be triggered when double tap is detected.
lis2dh12_i2c: # ... on_double_tap: - then: - logger.log: "Double tapped"on_freefall trigger
Section titled “on_freefall trigger”This automation will be triggered when free-fall is detected.
lis2dh12_i2c: # ... on_freefall: - then: - logger.log: "Freefall detected"on_active trigger
Section titled “on_active trigger”This automation will be triggered when device detects changes in motion.
lis2dh12_i2c: # ... on_active: - then: - logger.log: "Activity detected"on_orientation trigger
Section titled “on_orientation trigger”This automation will be triggered when device orientation is changed with respect to the gravitation field vector g.
lis2dh12_i2c: # ... on_orientation: - then: - logger.log: "Orientation change detected"