MPU6050 compass sensor reading vehicle passing - without using data in HA

So I have MPU 6050 sensor connected to HA via ESPHOME. trying to get a trigger signal when a large metal object - a vehicle passes - to trigger cameras etc in homeassistant.

I could probably to the calculations in homeassistant - but it seems very unnecessary to sent all compass data to HA instead of just letting the esp make the calculations in the arduino unit. So what is the best approach to do that - and any suggestions on what to meaure.

Tried google - alot - to find example code in best practices on how to use the sensor in this manor.

So this is how its setup now. But I would instead like the arduino not to send the data to HA and instead just send a “vehicle_trigger = 1/0”

i2c:
  sda: D1
  scl: D2
  frequency: 100kHz
  scan: False

sensor:
  - platform: dht
    pin: D5
    temperature:
      name: "FG6 Temperature"
    humidity:
      name: "FG6 Humidity"
    update_interval: 60s
    
  - platform: adc
    pin: A0
    name: "FG6 Ljus"
    update_interval: 10s
    filters:
      - calibrate_linear:
        - 0.0 -> 0.0
        - 1.0 -> 1023
    unit_of_measurement: '%'

  - platform: mpu6050
    address: 0x68
    accel_x:
      name: 'MPU6050 Accel X'
    accel_y:
      name: 'MPU6050 Accel Y'
    accel_z:
      name: 'MPU6050 Accel z'
    gyro_x:
      name: 'MPU6050 Gyro X'
    gyro_y:
      name: 'MPU6050 Gyro Y'
    gyro_z:
      name: 'MPU6050 Gyro z'
    temperature:
      name: 'MPU6050 Temperature'
    update_interval: 2s

binary_sensor:
  - platform: gpio
    pin: D5
    name: "FG6 gyroint"
#    device_class: motion

The MPU6050 doesn’t include a magnetometer, so I am unclear as to how you are going to do your detection.

Some MPU6050 breakouts do include a magnetometer connected via I2C, but I don’t know that ESPHome can access that data.

I agree with Daryl @zoogara, however there are four different magnetometer sensors in esphome. Why not use one of them? (There is even one built into esp32, but it may not be up to the job) ESPHome — ESPHome

So… I figured these readings that are created from the mpu6050 would be distorted by a vehicle passing??

2022-10-27 01_30_55-Konfiguration – Home Assistant

No. Not unless it was solid lead maybe. The MPU6050 uses MEMS technology to detect movement. It’s a solid state device that uses gravity and acceleration forces to physically bend tiny levers inside a microchip.

Here’s a video about it: How MEMS Accelerometer Gyroscope Magnetometer Work & Arduino Tutorial - YouTube

darn, I bought the wrong sensors for my purposes. thanks for the links ill try getting another one. Would any of the three versions on the esphome page above be more or less suitable?

I would do some Googling to see which the most sensitive or has the fastest response.

Meanwhile the MPU6050 is a good sensor, not so useful in ESPHome maybe - but you can make some pretty cool things with them. Here’s some shameless self promotion, if you know anyone who has a caravan or RV.

You probably mixed the MPU6050 up with the MPU9250. They look very similar, however only the 9250 has 9dof and therefore a magnetometer.
I played around with the 9250, but getting it to work isn’t easy. The chip has to be calibrated which is quite complicated.

So I can find the GY-271 using QMC5883L on amazon for about 18 euro / 5pcs. I’m thinking its ok if they are a bit uncalibrated - I just need them to go “bananas” when something big metal passes?

Yeah I wouldn’t’t think calibration matters, just need to take a reading, then if the value changes outside a set range then call that a detection.

Yeah, calibration probably isn’t necessary for your use case. I was actually trying to build a compass with it🙃.

What about the hall sensor on an esp32? Its probably to weak, right?

Think so… read that the normal hall sensors are too weak. Im ordering them and well see. Still need to make some smart esphome code that does not spam homeassistant with a million compass readings and only sends “motion” or “no motion”.

thanks for the tip about rv-usage … actually have that need as well so the mpu6050 will go into that project :slight_smile:

So… perhaps I could ask for some bright ideas. I would like this sensor not to send instant compass data to homeassistant but instead process the compass data internally and only provide a binary sensor information equivalent to “X-axel has changed more then a certain percentage set binary switch to true” - which would indicate that vehicle has passed. Haven’t found any good examples of that type of capabilities in the esphome code library. I’m thinking this would save alot of data I dont need in the HA.

2022-11-21 22_08_16-Window
… Help? :slight_smile: right now its looking as the screenshot - but with working compass data… something glitchy when screenshot was done.