Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peyanski/c583073713920cbaf27f6b1b4eac2e09 to your computer and use it in GitHub Desktop.
Save peyanski/c583073713920cbaf27f6b1b4eac2e09 to your computer and use it in GitHub Desktop.
# A resistor is needed on R19 pad
# Uncomment the two lines below if you want to have a web server with sensor readings
#web_server:
# port: 80
uart:
tx_pin: 5
rx_pin: 4
baud_rate: 9600
sensor:
- platform: "jsn_sr04t"
id: Distance
name: "Distance"
update_interval: 1s
# this is a template function to return percentage where 25cm = 100% , 6m = 0%
- platform: template
name: "% Full"
lambda: |-
if ((id(Distance).state) <= 0.250) {
return 100;
}
else if ((id(Distance).state) >= 6.000) {
return 0;
} else {
return (100 - ((id(Distance).state) - 0.250) / 5.75 * 100);
}
update_interval: 1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment