Dom + SR04 incorrect distance Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Dom + SR04 incorrect distance

Post 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
Attachments
Tasmota.png
Tasmota.png (18.3 KiB) Viewed 1165 times
mqtt.png
mqtt.png (60.21 KiB) Viewed 1165 times
dom1.png
dom1.png (22.99 KiB) Viewed 1165 times
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Dom + SR04 incorrect distance

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
psubiaco
Posts: 222
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: Dom + SR04 incorrect distance

Post 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.
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dom + SR04 incorrect distance

Post 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
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Dom + SR04 incorrect distance

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dom + SR04 incorrect distance

Post 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
User avatar
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Dom + SR04 incorrect distance

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Dom + SR04 incorrect distance

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest