Last active
September 14, 2023 15:26
-
-
Save ccormier/e8c8e03506d7d8923951594e95b74571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
name: salt_sensor | |
platform: ESP8266 | |
board: d1_mini | |
wifi: | |
ssid: !secret ssid | |
password: !secret ssid_password | |
manual_ip: | |
static_ip: <enter your own> | |
gateway: <enter your own> | |
subnet: <enter your own> | |
dns1: <enter your own> | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: "ESP Test" | |
password: "<enter your own>" | |
captive_portal: | |
# Enable logging | |
logger: | |
# Enable Home Assistant API | |
api: | |
encryption: | |
key: !secret api_encryption_key | |
ota: | |
password: !secret api_password | |
web_server: | |
port: 80 | |
sensor: | |
- platform: ultrasonic | |
id: ultrasonic1 | |
trigger_pin: D6 | |
echo_pin: D5 | |
name: "Ultrasonic Sensor" | |
filters: | |
# Sensor offset to match TOP of bin | |
- offset: -0.01 | |
- median: | |
window_size: 5 | |
send_every: 5 | |
send_first_at: 1 | |
- exponential_moving_average: | |
alpha: 0.1 | |
send_every: 1 | |
on_value: | |
then: | |
- component.update: capacity | |
update_interval: 1h | |
- platform: template | |
name: "Capacity" | |
accuracy_decimals: 0 | |
unit_of_measurement: "%" | |
id: capacity | |
lambda: |- | |
// Distance from top of bin to max full | |
static float threshold_full = .16; | |
// Distance from top of bin to empty - just above water line | |
static float threshold_empty = .57; | |
static float capacity = threshold_empty - threshold_full; | |
if (id(ultrasonic1).state) { | |
float current_level_adjusted = id(ultrasonic1).state - threshold_full; | |
float capacity_percent = (capacity - current_level_adjusted) / capacity * 100; | |
if (capacity_percent > 100) { | |
capacity_percent = 100; | |
} else if (capacity_percent < 0) { | |
capacity_percent = 0; | |
} | |
return capacity_percent; | |
} else { | |
return {}; | |
} | |
update_interval: never | |
on_value: | |
then: | |
- component.update: my_display | |
font: | |
- file: "fonts/ariel.ttf" | |
id: my_font | |
size: 28 | |
i2c: | |
sda: D1 | |
scl: D2 | |
display: | |
- platform: ssd1306_i2c | |
model: "SSD1306 128x64" | |
address: 0x3C | |
id: my_display | |
update_interval: never | |
lambda: |- | |
it.printf(11, 20, id(my_font), "%.0f%%", id(capacity).state); | |
if (id(capacity).state >= 0 || id(capacity).state <= 120) { | |
int bottom_graph = id(capacity).state * 0.01 * 50; | |
//int bottom_graph = 50 * 0.01 * 50; | |
int top_graph = 50 - bottom_graph; | |
it.rectangle(84, 6, 30, top_graph); //top graph | |
it.filled_rectangle(84, 6 + top_graph, 30, bottom_graph); //bottom graph | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment