Bubble spirit level Lovelace card?

Hello!

I’m looking for a bubble spirit level Lovelace card to visualise roll/pitch of my MPU6050 gyro + accelerometer.

At the moment, I use 2 separate gauges (for roll & pitch):

But I prefer a bubble spirit level, if such is available, i.e. something like this:

(the round part alone would be sufficient)

Are you aware of such a Lovelace card for Home Assistant? Thanks for sharing! :slight_smile:

2 Likes

Neat request.

2 Likes

Thank you! :+1:

It was not intended as a request but a question if some Lovelace card like this exists (and I haven’t found it yet, not even in HACS).

If this should now become a request, do I have to add something here in this thread? Or should I request it in another sub-forum or even on GitHub? (where I have an account, too)

It is a request now, since no one has built this. Ask a mod, perhaps, to move the thread to either the custom integrations category, or the WTH / feature requests categories.

Dear Moderators,

Can you please move this thread to a more appropriate sub-forum? It seems as it is now a feature request. Thank you so much! :slight_smile:

Hello!
Can you please share any guidance on how you connected and configured your MPU6050 and got the data into HA?

I have HA on a floating house and I would like to use this to measure the pitch & roll of the house. I’d like to connect an MPU6050 to my Raspberry Pi running HA, but no idea where to start (I’m new to HA)

Many thanks in advance !
Tom

Here you go:

1 Like

The MPU6050 is connected to an ESP32, which is connected (via USB) to a Raspberry Pi 4 (that obviously runs Home Assistant), which is connected to a Teltonika RUXT11. :wink:

This is the relevant excerpt of the ESPHome config for the ESP32:

# Project-specific stuff below

# i2c
i2c:
  sda: 21
  scl: 22
  scan: true
  id: i2c_bus_a

# MPU6050 accelerometer/gyroscope sensor 
sensor:
  - platform: mpu6050
    address: 0x68

    accel_x:
      id: accel_x
      name: "MPU6050 Accel X"
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    accel_y:
      id: accel_y
      name: "MPU6050 Accel Y"
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    accel_z:
      id: accel_z
      name: "MPU6050 Accel z"
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    gyro_x:
      name: "MPU6050 Gyro X"
      id: gyro_x
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    gyro_y:
      name: "MPU6050 Gyro Y"
      id: gyro_y
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    gyro_z:
      name: "MPU6050 Gyro z"
      id: gyro_z
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    temperature:
      name: "MPU6050 Temperature"
      filters:
       - sliding_window_moving_average:
          window_size: 10
          send_every: 5

    update_interval: 250ms

  - platform: template
    id: roll
    name: roll
    accuracy_decimals: 2
    lambda: |-
      return  (atan( id(accel_y).state / sqrt( pow( id(accel_x).state , 2) + pow( id(accel_z).state , 2) ) ) * 180 / PI) ;
    update_interval: 250ms

  - platform: template
    id: pitch
    name: pitch
    accuracy_decimals: 2
    lambda: |-
      return  (atan(-1 * id(accel_x).state / sqrt(pow(id(accel_y).state, 2) + pow(id(accel_z).state, 2))) * 180 / PI);
    update_interval: 250ms

It’s not as nice as a spirit bubble but works for the time being:

Obviously, the car needs to be considerably higher at its end (roll), whereas left/right is ok (pitch). :slight_smile:

The HA lovelace card code follows:

- title: Level
    path: level
    icon: mdi:spirit-level
    badges: []
    cards:
      - type: gauge
        entity: sensor.esp32_ha2_pitch
        min: -20
        max: 20
        needle: true
        name: Pitch
        unit: °
      - type: gauge
        entity: sensor.esp32_ha2_roll
        name: Roll
        unit: °
        min: -20
        max: 20
        needle: true

People might be interested in this, too:
https://van-automation.com/adding_van_tilt_sensor.html

I have the same scenario but am curious if you manage to expose the sensors to HA by reading them over USB not Wi-Fi. I see the log over USB but cannot get the entity to HA

I never thought about this. It just works with the MPU6050 connected to the ESP32 that is connected to the RPi via USB.

It does not in your case? Do you see if the ESP32 is recognised by the RPi when plugged in? (dmesg | grep usb)

Maybe your RPi needs a better electric plug (with more power to supply the ESP32 etc. sufficiently)?

I had a go at making one if that’s any help?:

image
image

2 Likes

Hi, could this being done even on the standalone ESP via its own Web output?
When i am traveling my Home Assistant remains at home, and the ESP with its Weboutput could still being used in the car.

Hi, an old topic but have just been looking for a bubble-level card to make a Van tilt sensor visual.

This works great!

Thanks for sharing.

1 Like

Thanks! It wasn’t too difficult to make, I spent longer trying to find one! I did make some improvements, mainly around auto resizing so I’ll update it.

I’m using it to monitor mutliple beehives that have a gyro in the roof.

Happy to test any new versions. I don’t know what the requirements are but would think this would be a useful addition to have available via HACS.

The beehive sounds interesting. Impressive.

Thanks again.

Just got some time to tinker with this bubble card again.

I’m using an ESP-32 and a MPU6050 Accelerometer to show the level of a motorhome.
The ESP32 is overkill but I’m building a Home Assistant dashboard to show other sensors also connected to the ESP. I stumbled on using the Z axis signal from the MPU to act as a bump sensor. Not got into it but it could feed into a trigger for an alarm.

Seems to work well so far. I wondered if you ever got chance if you could make a vertical version of the bar level. More for cosmetic purposes.
The only other feedback is that it seems full scale is across 1 Degree. I guess I can scale externally to make less sensitive.
Thanks again. Really useful component.

Hi,

I’ve added a multiplyer - for my beehives I need to know if they are a few degrees off so it’s a it sensitive, try adjusting the multiplyer (Default is 5):

type: custom:realistic-bubble-level-card
x_entity: sensor.beehive_1_1_y_axis
y_entity: sensor.beehive_1_1_x_axis
multiplier: 5
title: Position

The bar should go vertical if you add horizontal to the card:

type: custom:styled-bar-bubble-level-card
x_entity: sensor.apiary_hive_1_position_x
horizontal: false

I also fixed the scaling so it should auto scale and nicely fit cards: