Convert cm to % HC-SR04

Never mind, I figured out the constant. It’s 95*1.25 = 118.75

For anyone else who needs a calculation similar to this here is the final template code:

  • platform: template
    sensors:
    oil_status:
    friendly_name: “Oil Status”
    unit_of_measurement: “%”
    value_template: “{{ (118.75 - states(‘sensor.sonoff_oil_level’)|float * 1.25) |round(1) }}”

Thanks for your help.

5 Likes