Skip to content

Instantly share code, notes, and snippets.

@VynDesign
Last active September 5, 2023 14:19
Show Gist options
  • Save VynDesign/ed873454e090ece7ea2238679753e8d7 to your computer and use it in GitHub Desktop.
Save VynDesign/ed873454e090ece7ea2238679753e8d7 to your computer and use it in GitHub Desktop.
Water Softener ESPHome Config
esphome:
name: water-softener
esp32:
board: esp32dev
framework:
type: arduino
globals:
# distance between bottom of tank and sensor position is 0.91m
- id: sensor_height
type: float
initial_value: '0.91'
# distance between salt max fill line and sensor position is 0.16m
- id: distance_offset
type: float
initial_value: '0.16'
# distance between bottom of tank and max fill line is 0.75m
- id: max_fill_height
type: float
initial_value: '0.75'
sensor:
- platform: ultrasonic
id: "salt_level_distance"
trigger_pin: GPIO17
echo_pin: GPIO18
name: "Salt Level Distance"
update_interval: 10s
unit_of_measurement: "m"
- platform: copy
source_id: "salt_level_distance"
name: "Salt Level Distance From Max Fill Line"
filters:
# Calculates distance, in centimeters, of the difference between the max fill lineheight of the salt and the current level
- lambda: return (x - id(distance_offset)) * 100;
unit_of_measurement: "cm"
- platform: copy
source_id: "salt_level_distance"
name: "Remaining Salt Level"
filters:
# Calculates height, in centimeters, of salt pellets remaining in the tank
- lambda: return (id(sensor_height) - x) * 100;
unit_of_measurement: "cm"
- platform: copy
source_id: "salt_level_distance"
name: "% Remaining Salt Level"
filters:
# Calculates % of salt pellets remaining in the tank
- lambda: return (id(sensor_height) - x) * (100/id(max_fill_height));
unit_of_measurement: "%"
#boilerplate ESPHome/HA stuff removed
square: false
columns: 1
type: grid
cards:
- type: gauge
entity: sensor.remaining_salt_level_2
name: Water Softener Salt Level
needle: true
severity:
green: 35
yellow: 17
red: 0
- square: false
columns: 2
type: grid
cards:
- type: tile
entity: sensor.salt_level_distance_from_max_fill_line
name: Salt Used
- type: tile
entity: sensor.remaining_salt_level
name: Salt Remaining
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment