esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Ultrasonic sensor jsn_sr04t does not measure less than 250mm #5775

Open kristi5 opened 3 months ago

kristi5 commented 3 months ago

The problem

I am using jsn_sr04t in mode 1 (continous measurement via serial) to measure water level in tank.

Shortest measured range in my sensor is around 220mm but any measurement below 250mm is not reported by the component. Instead the log contains lot of lines with Invalid data read from sensor.

The component should consider any measurement which passed checksum control as valid and the measurement should be provided to HA.

Which version of ESPHome has the issue?

2024.4.2

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

esp01_1m

Component causing the issue

jsn_sr04t

Example YAML snippet

No response

Anything in the logs that might be useful for us?

I have plenty of following lines in log

[20:07:43][W][jsn_sr04t.sensor:044]: Invalid data read from sensor: FF.00.E0.DF
[20:07:43][W][jsn_sr04t.sensor:044]: Invalid data read from sensor: FF.00.E0.DF
[20:07:43][W][jsn_sr04t.sensor:044]: Invalid data read from sensor: FF.00.E0.DF
[20:07:43][W][jsn_sr04t.sensor:044]: Invalid data read from sensor: FF.00.E0.DF

Additional information

Checked the code and there is fixed constant limiting that all measurements below 250 are considered as invalid.

Why the measurement is considered as invalid when the checksum control passed?

zagi988 commented 3 months ago

As far as I know, since I've been using it with custom sensor - it doesn't measure under 20 cm. Why it shows unknown under 25 instead of just showing 20 when under 20, I don't know. But yeah, it's an issue.

adam-kulagowski commented 3 months ago

There several revisions and datasheets for this sensor. According to them the minimum range is from 20cm up to 25cm. However as long as the checksum is OK I believe we should allow lower values between 20 and 25 cm. @jesserockz should I make a PR for this?

adam-kulagowski commented 3 months ago

Last minute update: in my case sensors sometimes throws a value lower than 25cm when there is an issue w/ measurement (garbage, echo etc). So for me, 25cm limit works just fine, so I withdraw the idea of PR.

kristi5 commented 3 months ago

According to me its not invalid data as the log msg suggest while the checkum is OK.

My water tank has highest level around 20cm from the top where the sensor is located. My experience is that sensors are returning 20cm for whatever shorter measurement which is still OK but no measurement at all is not ok.

In my case i will not get any measurement from the sensor (in HA its reported as unknown) and it may last for days or months unless the level in the tank drops below 25cm or more from the top.

So when i will not get any measurement from the sensor then i do not know if the tank is full or sensor stop working or is unavailable.

Any suggestion how to handle this no-measurement state in esphome?

kristi5 commented 3 months ago

If sensor sometimes throws wrong measurement (but with correct checksum) due to some echoes or unstable water level then filtering those values is task for sensor filters. The esphome sensor component jsn_sr04t should provide any valid (CRC OK) value anytime it is received from the hardware. Rest should be handled by the user inside yaml file.