Add tank percentage to Mopeka Integration

Any insight on creating a template to convert inches into percentage for arbitrary tank sizes? I’m trying to measure a tank that is full at 6.50 inches. This would also be useful when I get some more sensors to monitor my fresh water tank level. Is there a simple way to do this?

somewhat like this. i did this with 2 sensors because i did want to know the “level” of the water so i can validate with a ruler. also, my sensor is an ultrasonic sensor that sits at the top of the tank. just modify accordingly

template:
  - sensor:
      - name: "House Water Tanks Level"
        unique_id: house_water_tanks_level
        device_class: distance
        unit_of_measurement: in
        state_class: measurement
        icon: mdi:arrow-expand-vertical
        state: >
          {% set sensor_height = 88.75 %}
          {% set full_height = 83.75 %}
          {{ sensor_height|float(0) - states('[YOUR SENSOR HERE')|float(0) }}
      - name: "House Water Tanks Percent"
        unique_id: house_water_tanks_percent
        unit_of_measurement: '%'
        state_class: measurement
        state: >
          {% set full_height = 83.75 %}
          {{ (states('sensor.house_water_tanks_level')|float(0) / full_height|float(0) * 100) | round(1) }}

Hm, that didn’t seem to do it. I plugged in my full height percentage as 94%, but it gave me a reading of 3.5% Definitely not lining up with how full my tank is according to the Mopeka app (85% currently). My sensor sits on the bottom of the tank.

I also just noticed that the Mopeka app is displaying a different fuel height than what is being reported in HA. The app shows 5.2in, but HA shows 3.3. I’m not sure what is going on there.

oh. i thought your were looking for something generic. i used this to approximate the pressure dial on the tank.

template:
  - sensor:
    - name: "House Gas Tank Percent"
      unique_id: house_gas_tank_percent
      unit_of_measurement: '%'
      state_class: measurement
      state: >
        {% set full_height = 90 %}
        {{ (states('YOUR_SENSOR')|float(0) / (full_height|float(0) / 2.54) * 100) | round(1) }}

you may need to adjust for the unit of measure.

I’m just trying to find a template that I can modify to work for various tank sizes outside of propane tanks. HA displays the sensors tank level in inches (which apparently is not correctly lining up with the app). I just need to display the inches as percentages. 6.50in being full.

I’m also not very good at these template sensors, and I don’t understand the math formula here. I feel very stupid in that regard…

No matter what I input, I can’t get the percentage in HA to line up with the app. Can anyone else confirm if their sensors are displaying the same amount in inches on both the app and HA?

image

got it. those 2 values should match or be very close to each other. not sure why HA vs App would be different. but a template percentage based on what HA is reading would be like this:

template:
  - sensor:
    - name: "House Gas Tank Percent"
      unique_id: house_gas_tank_percent
      unit_of_measurement: '%'
      state_class: measurement
      state: >
        {{ (states('YOUR_SENSOR')|float(0) / 6.5 * 100) | round(1) }}

just plug in whatever the name of your sensor. This part including the “sensor.” part:
image

Thank you for the help on this. I’ve let my frustration get the better of me on this.

I’ve plugged in my sensor into the code you provided, but it’s only showing the tank level at 50.8%. I’m guessing this is due to the difference in measurements between HA and the app.

correct. not sure why you’re seeing a different value in HA vs the app. maybe it’s a connection issue and the 3.3 in HA is an old value (not being updated)?

I tried disconnecting the sensor from HA and the app. It seems to be connecting fine, and updating. It still reads 5.2in in the app when I have it configured for Diesel fuel and a tank height of 6.50in.

If I change the type of fuel/liquid to something else from the list like heating oil or even unknown, then the app shows 3.3in, the same as HA.

I’m wondering if this is due to how the Mopeka app calculates the different fuel types. From my understanding, the sensor only sends the tank level in inches, and it’s up to the Mopeka app to do the calculations on if you’re measuring propane, water, or diesel and then output the correct reading in percent or inches, depending on how you want to view it.

The HA integration probably does none of these calculations and just passes through the raw number.

yes, but the level in HA should match what the app shows. then it’s up to HA or the app to do something w/ that level. when you change fuel types, does the level change in HA like it does in the app? it should

The level doesn’t change at all in HA when I change the fuel types in the app. It always shows the 3.3in in HA. I came across a post on the Victron community forum where it was mentioned that the communication protocol has changed from the old sensors to the new universal sensors. I’m wondering if this has something to do with it.

https://community.victronenergy.com/questions/223695/mopeka-pro-check-universal-cerbogx-support.html

that may be the issue. i would try one last thing - remove the integration from HA, restart, and add it again. see if it picks up the reading.

I actually tried that, and it didn’t seem to make a difference unfortunately.

Quick update on my progress with this. I setup esphome and the mopeka integration on a spare ESP32 board to see if there were differences in the sensors readings. The esphome integration reports back in mm, but when I do the conversion it comes out to be exactly what the native HA integration reports in inches.

So the raw sensor data is correct, but still does not line up with the mopeka app readings when commodity types of diesel or gas are selected. However when you select either propane, heating oil. Anhydrous NH3, or unknown it will then report the same value as the raw sensor value. There’s even a different value when selecting water.

So at this point I can only assume that the mopeka app is doing some sort of calculations behind the scenes for the different commodity types. Since these sensors are ultrasonic based, the waves would naturally move through different mediums(liquids) at different rates and would have to be compensated for.

This is where I’m at a dead end with this. My knowledge in this area is just not that extensive. I’ve emailed mopeka directly to see if I can get an answer as to how the app does these calculations. Time will tell I guess.

For reference, there is an issue that was raised 2 weeks back to add support for more fluid types to the mopeka-iot-ble library. Just have to wait to see what comes of it. So for anyone wanting to use the universal sensors in HA to track things other than propane; you’re going to be out of luck until this gets resolved.

so to be clear, the value you see in HA (whether with the mopeka integration or thru the ESPHome one) matches the app now? to be specific, i’m asking about the level, not the percentage. i agree that the percentage will vary because the app is taking into account the type of fuel/density/etc against the ultrasonic reading it’s getting to calculate a percentage. but the level should be the same in the app and HA. ps if you’re getting readings in mm, divide by 25.4 to get inches. maybe this helps.

Only when I’m measuring certain fluid types does it show the same level in inches. If I choose diesel, or gas it will show a different level (in inches) in the app than what the sensor is actually reporting. I get the same behavior between the HA integration or using esphome.