Hi! I have Wemos D1 Mini and an MPU 6050 sensor mounted on the wall, I wanna make it as an earthquake sensor device.
I’ve managed to set it up with the following code on ESPHome, but I don’t think it’s not good enough:
- platform: mpu6050
address: 0x68
update_interval: 100ms
accel_x:
name: "MPU6050 Accel X"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
accel_y:
name: "MPU6050 Accel Y"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
accel_z:
name: "MPU6050 Accel z"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
gyro_x:
name: "MPU6050 Gyro X"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
gyro_y:
name: "MPU6050 Gyro Y"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
gyro_z:
name: "MPU6050 Gyro z"
filters:
- sliding_window_moving_average:
window_size: 4
send_every: 1
- delta: 0.5
temperature:
name: "MPU6050 Temperature"
filters:
- sliding_window_moving_average:
window_size: 50
- exponential_moving_average:
alpha: 0.2
With this code, the value of each sensor while still is not 0. I’m aware that it does not come with calibration as written in documentation.
I tried adding derivative sensor on HA hoping that if the value changes from 0, it will trigger, but with the following automation it will only do the actions after movements stopped.
Another downside of derivative sensor AFAIK is that if the sensor is not going back to initial position, the value will offset.
trigger:
- platform: numeric_state
entity_id:
- sensor.derivative_gyro_x
- sensor.derivative_gyro_y
- sensor.derivative_gyro_z
- sensor.derivative_accel_x
- sensor.derivative_accel_y
- sensor.derivative_accel_z
above: 0
for:
hours: 0
minutes: 0
seconds: 1
condition: []
What’s the best way to do this?
TIA