Skip to content

Instantly share code, notes, and snippets.

@peyanski
Created May 28, 2025 09:55
Show Gist options
  • Save peyanski/d64a17c4b8e5c23040e78ff6fcd1b9fb to your computer and use it in GitHub Desktop.
Save peyanski/d64a17c4b8e5c23040e78ff6fcd1b9fb to your computer and use it in GitHub Desktop.
# Uncomment the two lines below if you want to have a web server with sensor readings
#web_server:
# port: 80
sensor:
- platform: ultrasonic
id: Distance
trigger_pin: 5
echo_pin: 4
name: "Distance"
update_interval: 1s
pulse_time: 20us
timeout: 6m
# this is a template function to return percentage where 20cm = 100% , 6m = 0%
- platform: template
name: "% Full"
lambda: |-
if ((id(Distance).state) <= 0.200) {
return 100;
}
else if ((id(Distance).state) >= 6.000) {
return 0;
} else {
return (100 - ((id(Distance).state) - 0.200) / 5.80 * 100);
}
update_interval: 1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment