Created
May 28, 2025 09:55
-
-
Save peyanski/d64a17c4b8e5c23040e78ff6fcd1b9fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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
Hello,
Please find attached the screenshots, yaml and the log. I am using HASS OS v2025.9.1 with esphome as addon installed v2025.8.3
Using D1 Mini and AJ_SR04M. Did the wiring as per your pdf and also copied the code. But the sensor I only giving nan as output.
Kindly help what am I doing wrong here.
Very much hoping for your reply.
Thanks in advance.
Yaml
LOG