Help NEEDED with value_template & dynamic icons

Hi Magren

Everything is holding up fine. I’ve used a Wemos D1 mini and flashed it with Tasmota as I want all my devices to communicate with MQTT to HA, and I also like the Tasmota Web interface. I’ve not used the normal HC-SR04 ultrasonic sensor. I opted to go for the waterproof version (JSN SR04T) which basically looks the same as your park distance control sensor on your car bumper. Completely waterproof.

I’ve printed a small mounting holder for this and glued the sensor into this holder which then gets mounted right at the top in the middle of the tank at the highest level. So, the JSN-SR04T cannot measure a distance less than 20cm, but in my case that was no issue as the top of my tank where the sensor is mounted is just on about 20 cm above highest water level, so it worked out fine.

SO my WemosD1 is mounted in a box with the sensor attached with about 1.8meter of wire to the tank and have been working flawlessly for about 2 years now. The sensor is sometimes completely wet with condensation but still reports my levels 100% correctly

My final code:

############################################################
# Wemos D1 Sensor linked to HC-SR04 for Water Tank Level
#                 and DHT11 for Humidity & Temperature
############################################################
platform: mqtt
name: "Water_Tank_Level_From_Top"
state_topic: "tele/sonoffD1_1/SENSOR"
value_template: "{{ value_json.SR04.Distance }}"
unit_of_measurement: "cm"

################################################################
#
# Home Assistant  - Tank Level Controller with Temp & Humidity
#
# Tank Info:
#   Tank Total Height = 180cm (Bottom to Sensor Mount Height)
#   Sensor level from Top of Tank to Overflow level = 20cm
#   Outlet Pipe above Bottom = 10cm
#   Usable Water Level Distance = 140cm (Outlet Pipe to Overflow)
#
################################################################

platform: template
sensors:
  water_level_percentage:
    unit_of_measurement: '%'
    value_template: >-
      {% set water_level = states('sensor.water_tank_level_from_top') | float %}
      {% if water_level < 21 %}100.0
      {% elif 21 <= water_level < 174 %}
        {{ ((10-((water_level -21)/17))*10) | round(1) }}
      {% else %}0
      {% endif %}

Hope this helps but let me know if you need more info

Jackie

3 Likes