I am using tasmota_sensors on WEMOS D1 mini pro
GPIO4 = SR04 Tri/TX
GPIO5 = SR04 Ech/RX
Rule1
on tele-SR04#distance do backlog var1 %value%; event checklimit=%value%; event senddistance endon
on event#checklimit>138 do var1 138 endon
on event#checklimit<28 do var1 28 endon
on event#senddistance do backlog Calcres 1; SCALE1 %var1%, 138, 28, 0, 100; event pubdata endon
on event#pubdata do counter1 %var1% endon
138 cm is the low lvel; 28 cm is the maximum level. Has to be adjusted according to the situation.
With the counter trick the counter value is automatically published with tele/xxx/SENSORS