DCL777 / sensors2mqtt

Universal Sensor data transporter over MQTT. Sensor like water flow sensor (=pulse-counter), DS18B20 , INA219, 4-20mA, PMS5003, ...
GNU General Public License v3.0
6 stars 0 forks source link

Adding support for the JSN-SR04T Ultrasonic sensor #1

Closed geccko closed 2 years ago

geccko commented 2 years ago

Is it possible to add support for the JSN-SR04T Ultrasonic sensor ? I created a new file for this sensor, could you merge it?

Thanks

DCL777 commented 2 years ago

Yes, i can add it. Can you send me the file? Witch mode do you use? i would prefer UART TX & RX to be compatible with my structure.

geccko commented 2 years ago

Hi @DCL777

How do I send you the file? Thanks

DCL777 commented 2 years ago

Hi, you can drag and drop our files here in your message or pasting them.

geccko commented 2 years ago

Hi,

Here is the file that I added under the "sensors/Generic_Ultrasonic" directory. I used a JSN-SR04T, for example: https://aliexpress.com/item/1005003683104654.html

And the config: Sensors: Generic_Ultrasonic:

RPI_Generic_Ultrasonic.txt

DCL777 commented 2 years ago

Hi, I added it and changed it a little bit to be in-line with the other sensors. I don't have a sensor yet. Can you test it?
All feedback is welcome. Is the output stable? Since Linux is not a real-time platform, i could happened that there is an additional delay.
If it's not stable enough, we should look to the RS232 mode to have a accurate measurement. Kind regards, Dries

geccko commented 2 years ago

Hi @DCL777.

Thanks very much for including this sensor. I made some changes to the code:

Line 79 change to: distance = (pulse_duration_average * self.scale_factor)

Line 82 check identation and change to: if distance > self.output_value_min and distance < self.output_value_max:

Line 80 change to: distance = round(distance, self.decimal_points)

It's seems to be working perfectly and the output is very stable, I will continue testing it.

2022-07-19 20:33:21,376 - INFO - MQTT: homeassistant/ultrasonic/height 0 2022-07-19 20:33:30,008 - INFO - EVENT = 30 2022-07-19 20:33:31,211 - INFO - MQTT: homeassistant/ultrasonic/height 336.24 2022-07-19 20:33:40,009 - INFO - EVENT = 10 2022-07-19 20:33:41,246 - INFO - MQTT: homeassistant/ultrasonic/height 395.89 2022-07-19 20:33:50,009 - INFO - EVENT = 10 2022-07-19 20:33:51,031 - INFO - MQTT: homeassistant/ultrasonic/height 25.11 2022-07-19 20:34:00,009 - INFO - EVENT = 60

Kind regards!

DCL777 commented 2 years ago

Thanks. It's fixed. + i added a timeout See HISTORY.md file for more info.

geccko commented 2 years ago

Thanks so much !!!