I made a sensor about a year ago and cant remember how i made it and need to change it a little.
what i want is to have a template sensor either in esphome or HA that gives me
oil level percentage with 0 decimal places at the minute i have is a bit messy, 3 sensors doing the job that i think a clever person an do in 1.
currently. in esphome
sensor:
- platform: ultrasonic
trigger_pin: D6
echo_pin: D5
name: "Ultrasonic Sensor"
update_interval: 10s
- platform: ultrasonic
trigger_pin: GPIO12
echo_pin: GPIO14
name: "Oil Tank Level Percent"
update_interval: 10s
icon: mdi:oil
filters:
- offset: -0.15
- lambda: return (1.0 - (x/1.0)) * 100.0;
unit_of_measurement: "%"
esphome defaults to 2 places so i have a working template sensor in HA but its a sensor too many
- platform: template
sensors:
Oil Tank Percent:
entity_id: sensor.oil_tank_level_percent
value_template: {{ states('sensor.oil_tank_level_percent') | float | round(0) }}%