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 }}"
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.
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 }}"
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.
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…
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.