MQTT - Percentage WatchMan Oil Sensor

Hi All,

I have a WatchMan Oil sensor that the Depth in cm is being read using MQTT. I have the SDR on a PI1 in my garage. The HA sensor for this is

    - name: "Oil Depth"
      state_topic: "rtl_433/pi-rtl433/devices/Oil-SonicSmart/137137042/depth_cm"
      unit_of_measurement: "cm"
    - name: "Oil Temperature"
      state_topic: "rtl_433/pi-rtl433/devices/Oil-SonicSmart/137137042/temperature_C"  
      unit_of_measurement: "C"

This works fine but for ease of use I’d like to be able to calculate % (for wife reasons!). Which is where I’m stuck

I’ve tried the below sensor code and variations of it.

    - name: "Oil Percent Actual"
      state_topic: "rtl_433/pi-rtl433/devices/Oil-SonicSmart/137137042"
      value_template: "{{ 115 - (value_json.depth_cm) * 11.31 / 1300 * 100 | int }}"
      unit_of_measurement: '%'

Any guidance for where I’m going wrong? I’ve tried adding /depth_cm to the state topick. The sensor shows in HA but shows the value is unknown.

The values of 115 etc aren’t correct for my tank but I can tweak those after.

image

These are the values I see via MQTT Explorer.