Bar Gauge Incorrect Reading

I have a bar gauge showing my oil tank level. It is supposed to emulate roughly my watchman gauge which shows 1 to 10. However the bar gauge shows 9 instead of 10 after being filled up. I think this is because anything less than 100% full will show 9, I guess it needs to show a range, so from 1250ltr (full tank) to 1000ltr show 10, 999ltr to 850 ltr show 9 etc.

What have I got wrong below?

- platform: mqtt
  name: "Oil Tank Depth"
  state_topic: "rtl_433/0/144204529"
  value_template: "{{ value_json.depth }}"
  unit_of_measurement: cm
- platform: mqtt
  name: "Oil Tank Bars"
  state_topic: "rtl_433/0/144204529"
  value_template: "{{ value_json.depth | int // 14 + (value_json.depth | int % 14 != 0) | int }}"
  unit_of_measurement: ' '
oil_tank_bars_remaining:
  friendly_name: "Oil Tank Bars Remaining"
  value_template: "{{ 10 - states('sensor.oil_tank_bars') | int }}"

According to our original conversation and the equation you supplied with the graph in this post:

Maximum is 1400mm. The depth property returns mm as discussed in that lengthy conversation. So unless you lied originally, it’s working fine.

Hi @petro

Thank you, I don’t think you need to be quiet so rude, I did not lie by any means.

But it clearly is NOT working correctly otherwise I would not have posted. I am not very familiar with programming or YAML and was only asking for a little assistance.

As I stated in my original post it is 1400mm in height which equates to 1250ltr. It is showing 9 now and should be 10.

What is your reading on the oil tank depth?

@petro

Uh, why is oil_tank_depth only 7 cm? That should be in above 127cm for the calculations to produce 10. All the calculations are based on depth being the height of the oil in the tank.

EDIT. well anyways, I think your units are named poorly and thats why the equation was tailored wrong from the begining. Normally, depth is the amount of liquid remaining. Looking at your last post, I’m going to assume you have it as the amount of oil missing in cm. So with that being said, change the equations to

- platform: mqtt
  name: "Oil Tank Bars Remaining"
  state_topic: "rtl_433/0/144204529"
  value_template: >
    {% set actual_depth = 140 - value_json.depth | int %}
    {{ value_json.depth | int // 14 + (value_json.depth | int % 14 != 0) | int }}
  unit_of_measurement: ' '

and change your other sensor to

oil_tank_bars:
  friendly_name: "Oil Tank Bars"
  value_template: "{{ 10 - states('sensor.oil_tank_bars_remaining') | int }}"

@petro,

Sorry I should have said the depth is the depth from the top of the tank as its an ultrasonic sensor which is seated in the top reading down. Apologises.

@petro

Now it shows the following:

image

Which appears to be a reverse of what was showing previously. But still 9 bars not 10.

Yah, typos all around on my last post. This is what they should be:

- platform: mqtt
  name: "Oil Tank Bars Remaining"
  state_topic: "rtl_433/0/144204529"
  value_template: >
    {% set actual_depth = 140 - value_json.depth | int %}
    {{ actual_depth  | int // 14 + (actual_depth  | int % 14 != 0) | int }}
  unit_of_measurement: ' '
oil_tank_bars:
  friendly_name: "Oil Tank Bars"
  value_template: "{{ 10 - states('sensor.oil_tank_bars_remaining') | int }}"

Hi @petro

That is working. Thank you very much for your help.

Wishing you Happy Holidays.

1 Like

Hi!
I have similar setup as @pep987 with a watchman oil sensor and rtl433 and mqtt.

Using the calculation from his previous post the bar level is 1 out. e.g. on the watchman gauge it’s 7 but HA is reporting 6.

I tried the updated code by @petro and the values are reversed e.g. 3

    name: "Oil Tank Bars"
    state_topic: "oiltank/level"
    #value_template: "{{ value_json.depth | int // 14 + (value_json.depth | int % 14 != 0) | int }}"
    value_template: >
      {% set actual_depth = 140 - value_json.depth | int %}
      {{ actual_depth  | int // 14 + (actual_depth  | int % 14 != 0) | int }}

The commented out code is the one that displays 6 on the gauge in lovelace and the code provided in this thread shows 3 instead of 7, so this would be correct in terms of difference.

Here is the sensor code

    oil_tank_bars_remaining:
      friendly_name: "Oil Tank Bars Remaining"
      value_template: "{{ 10 - states('sensor.oil_tank_bars') | int }}"

For reference my tank is set to 138cm high and the json payload that comes in to MQTT looks like this…

{
  "time" : "2019-12-24 09:25:58",
  "model" : "Oil Watchman",
  "id" : 123456789,
  "flags" : 128,
  "maybetemp" : 24,
  "temperature_C" : 8.33333,
  "binding_countdown" : 0,
  "depth" : 50
} 

Also the depth reading is in cm, and is from the top of the tank pointing to the surface of the oil.

Thank you in advance to anyone that is able to assist with this! :slight_smile:

1 Like

It’s just so odd to me that these devices return the depth from the top of the tank to the surface of the oil. Maybe oil tank sensors don’t work when submerged in oil? I donno, either way, it just seems odd.

@pep987 Happy Holidays to you too. Glad you got it working.