Combine multiple binary_sensors in Gauge Card

Hey community!
I made a water level sensor for my Over-Head Tank using six ‘Float Reed Switches’ placed at different heights (100%, 80%, 60%, 40%, 20%, 5%). I then connected them to an ESP32 and wrote an esphome program that triggers a relay to switch on when the water level is at 5% and then Switches off at 100%.

This has been working flawlessly.

The issue I’m facing is that my parents and grandparents want to see (visualise) the Water Level (I really don’t understand why though). To solve this I thought I’d connect some RGB LEDs (WS2812B) to the ESP32 that’s running this same program. But this would mean if and when anyone needs to check the water level, they’d have to come to the ground-floor of our house every time. Now the people at home don’t have a problem with this but I wanted to make this viewable on the ‘Home Assistant Dashboard’.

I then used the ‘Entities Card’ to make this possible but I’m not satisfied with the result. A ‘Gauge Card’ would make so much sense but since these are ‘Binary Sensors’, there isn’t any option to combine many Binary Sensors to form a single sensor in ‘Gauge Card’. I would really appreciate some guidance.

If the above isn’t possible, is it then possible to remove the ‘on’ / ‘off’ state mentioned on the right of each ‘Entity Card’

Thank you.

Use a template sensor in ESPHome to combine the binary sensors into a numeric state:

It will look something like this:

sensor:
  - platform: template
    name: Tank Level
    unit_of_measurement: "%"
    lambda: |-
      if (id(binary_sensor_full).state) {
        return 100;}
      else if (id(binary_sensor_80pct).state) {
        return 80;}
      else if (id(binary_sensor_60pct).state) {
        return 60;}
      else if (id(binary_sensor_40pct).state) {
        return 40;}
      else if (id(binary_sensor_20pct).state) {
        return 20;}
      else if (id(binary_sensor_low).state) {
        return 5;}
      else {
        return 0;}
    update_interval: 60s

This will be exposed to Home Assistant as sensor.tank_level and you can use it in any sort of graph card you want.

1 Like

Thank you so much. This was the solution.

1 Like

I tried to return an ‘integer’ value to get rid of the decimal on the Gauge Card but I’m not able to figure It out.

Kindly guide me to return an ‘integer’ value so there’e no ‘decimal’ on the ‘Gauge Card’.

Thank you.

Would you mind sharing your code for this. Is it entered in the ESP yamal?

Im getting this error.

ambda contains reference to entity-id-style ID ‘binary_sensor.front_tank_sensor_front_tank_full’. The id() wrapper only works for ESPHome-internal types. For importing states from Home Assistant use the ‘homeassistant’ sensor platforms.
lambda: |-

Sorry, missed this. If you click on the entity then the cog icon in the pop-up you can set the decimal precision.