Page 1 of 1

Dom + SR04 incorrect distance

Posted: Wednesday 10 April 2024 22:32
by FredZ
Hello all

I've just setup a D1 mini (4M) with an SR04 attached running Tasmota. This is functioning as expected.
It sends data via MQTT and the MQTT server (mosquito) reports the distance correctly.
However Dom reports the distance incorrectly. It seems as though it moves the decimal point.

16cm is reported as 1.6cm

I've used MQTT as I couldn't work out how to setup a dummy device properly.

Version: 2024.4
Build Hash: 731719420
Compile Date: 2024-01-30 21:16:34
dzVents Version: 3.1.8
Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
On Debian 11
mosquitto version 2.0.11

Any assistance would be most helpful.

Regards

Fred

Re: Dom + SR04 incorrect distance

Posted: Wednesday 10 April 2024 23:25
by waltervl
What kind of mqtt integration are you using for talking Tasmota with Domoticz?

Mqtt Autodiscover? Mqtt mapper python plugin? Tasmotateach script?

It seems you use mqtt Auto Discover. What is the mqtt config topic for this water level device.
Should be somewhere in the Tasmota topic.

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 0:02
by psubiaco
You can write a simple script that, event triggered, that when the distance sensor is updated, it updates a second distance sensor with value/10 to convert mm to cm.
This can be useful expecially for a water tank , so you can use the script to convert the distance (in mm) to the water tank level in cm
(e.g. if distance between sensor and water is 350mm and between sensor and tank floor is 150cm, water tank level = 150-350/10=115cm)
If you need help to write a similar script, I can help you.

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 3:53
by FredZ
What kind of mqtt integration are you using for talking Tasmota with Domoticz?
Tasmoticz
Autodiscovery of Tasmota Devices for Domoticz
It seems you use mqtt Auto Discover. What is the mqtt config topic for this water level device.
Should be somewhere in the Tasmota topic
Topic = Water_Level
Full Topic = %prefix%/%topic%/
You can write a simple script that, event triggered...
I simply don't have the skill set to be writing my own name let alone any kind of script. Sorry.

Regards

Fred

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 7:52
by waltervl
Do you have a link to the description/instruction of Tasmoticz
Autodiscovery of Tasmota Devices for Domoticz?

As I am not aware of this.

You could try to set tasmoticz to send mm instead of cm. There is a factor 10 somewhere... And it is not in Domoticz, if Domoticz gets value 15 it is displayed as 15 cm.

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 9:47
by FredZ
Do you have a link to the description/instruction of Tasmoticz
Autodiscovery of Tasmota Devices for Domoticz?
https://github.com/joba-1/Tasmoticz

What I am confused about is that the MQTT server (mosquito) is receiving the correct value from the Tasmota client, and somehow Domoticz is reading/interpreting it wrong.

Now I'm not sure if the mqtt server is providing the data to Dom properly or if Dom is reading it wrong, and I don't know how to test/check that.

It may be worth my while setting up a dummy device therefore eliminating the need for mqtt, but I don't know how to do that.

It should be noted that I do have numerous other temp/hum/switch/relay devices connected to Dom via mqtt and they all work as expected.

Regards

Fred

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 20:00
by waltervl
You better make an issue on the tasmoticz python plugin as that seems to do something wrong.

Looking on this line in the plugin https://github.com/joba-1/Tasmoticz/blo ... ta.py#L233

You should use cm as unit instead of mm

Re: Dom + SR04 incorrect distance

Posted: Thursday 11 April 2024 21:31
by FredZ
Thanks for the reference.
As a result I have managed to resolved the issue.
There is a line in the script

Code: Select all

        if subtype == 27:
            # Domoticz distance needs cm but gets mm
            return 0, str(float(value)/10)           
All I did was to remove the /10 from the line so it now reads

Code: Select all

        if subtype == 27:
            # Domoticz distance needs cm but gets mm
            return 0, str(float(value))
This was because the comment "Domoticz distance needs cm but gets mm" is actually incorrect.

I so much appreciate your input and assistance with this problem.

Regards

Fred