esphome / esphome/feature-requests

Modify ultrasonic sensor code to include the temperature for more precision

Open
#2,212 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

I would like to have temperature in ultrasonic distance sensor code for better precision.
I have done a little research and in its code now the speed of sound is set to 343 m/s = 19.8°C.
By default it would also be around 20°C but the arg would take the temperature (and maybe the format, default °C)
This is the formula for calculating the speed of sound in air:
![image](https://user-images.githubusercontent.com/55651520/233961019-7c983f4b-5409-406b-bd2f-dd289eb3c3c5.png)

Source for that: https://www.omnicalculator.com/physics/speed-of-sound#speed-of-sound-in-air

**Please describe your use case for this integration and alternatives you've tried:**

I'm building a device, which checks the water level of a water well. I want it to calculate: water height, volume of the well (in Liters and %), time to empty (so that water pump can shut down safely) and time to fill.
Everything is based on the distance so if the reading is off , the true capacity will be off.

It is possibe to make it now, but only as filters: - lambda, but its messy. You have to extract the round-trip-time from the distance (with the hardcoded temperature of 19,8°C) and then multiply it by the real speed of sound, RTT and temperature.

**Additional context**

Example config:
sensor:
- platform: ultrasonic
trigger_pin: D1
echo_pin: D2
name: "Ultrasonic Sensor"
update_interval: 1s
calc_temp: 5 or _blank_ (defaults to 20°C) or id(tempsens).state (or something like it, directly from sensor)

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named in the request. Start by locating the ultrasonic platform configuration and its temperature-related sensor input, then compare the requested default and °C option with the cited speed-of-sound formula. Done means ultrasonic distance calculations can use the configured temperature while preserving the current default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
yaml
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.