Skip to content

Instantly share code, notes, and snippets.

@aver-ua
Last active December 7, 2024 09:39
Show Gist options
  • Select an option

  • Save aver-ua/1d111b006ab88692ea070cf33ffeead8 to your computer and use it in GitHub Desktop.

Select an option

Save aver-ua/1d111b006ab88692ea070cf33ffeead8 to your computer and use it in GitHub Desktop.
ESPHome config for Topas Septic, Temperature (DS18B20) and Water Level Meter (ultrasonic AJ-SR04M )
esphome:
name: topas-meter
comment: "${device_description}"
friendly_name: Topas Meter
substitutions:
device_description: "Topas Septic Temperature and Water Level Meter"
device_name: "topas-meter"
water_warn_prc: "80" # water level in prc warning
diag_updt_interval: 60s
waterlevel_updt_interval: 60s
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption_key
ota:
platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Topas-Meter Fallback Hotspot"
password: !secret hotspot_password
captive_portal:
# DS18B20 Dallas sensor
one_wire:
- platform: gpio
pin: GPIO16
#dallas:
# - pin: 15
# update_interval: ${diag_updt_interval}
text_sensor:
# Uptime Human Readable
- platform: template
name: Uptime HR
id: uptime_human
icon: mdi:clock-start
number:
# receiving camera height in cm
- platform: template
id: rec_cam_height
name: Receiving Camera Height
icon: mdi:water-plus
optimistic: true
mode: slider
step: 10
entity_category: config
min_value: 100
max_value: 300
initial_value: 100
restore_value: yes
unit_of_measurement: cm
sensor:
# Uptime sensor.
- platform: uptime
name: Uptime
entity_category: "diagnostic"
id: esp_uptime
update_interval: ${diag_updt_interval}
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(esp_uptime).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
# WiFi Signal sensor.
- platform: wifi_signal
name: "WiFi Signal dB"
id: wifi_signal_db
entity_category: "diagnostic"
update_interval: ${diag_updt_interval}
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
device_class: ""
# Waterlevel sensor / AJ-SR04M
- platform: ultrasonic
trigger_pin:
number: 25
inverted: true
echo_pin:
number: 26
name: "Waterlevel cm"
id: water_level
update_interval: ${waterlevel_updt_interval}
pulse_time: 20us
timeout: 4m
filters:
# sensor works in meters. 0.25 - blind zone
- lambda: |-
if (x <= 0.25) return id(rec_cam_height).state-1;
return id(rec_cam_height).state-x*100;
unit_of_measurement: "cm"
- platform: copy
source_id: water_level
id: water_level_prc
name: "Waterlevel percent"
unit_of_measurement: "%"
filters:
- lambda: return x/id(rec_cam_height).state*100;
# DS18B20 Temperature
- platform: dallas_temp
name: "Temperature"
update_interval: ${diag_updt_interval}
- platform: internal_temperature
name: "ESP Temperature"
entity_category: "diagnostic"
# Enable Web server.
web_server:
port: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment