Adding support for the JSN-SR04T Ultrasonic sensor
Closed this issue · 8 comments
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
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.
Hi, you can drag and drop our files here in your message or pasting them.
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:
- platform: RPI
echo_pin: 21
trigger_pin: 20
sample_size: 10
update_interval: 10 # seconds 10,30,60, 300 (5min) , 900 (15min), 3600 (1h) , 10800 (3h), 21600 (6h) , 43200 (12h)
mqtt_sub_dir: height
function: ultrasonic
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
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!
Thanks.
It's fixed. + i added a timeout
See HISTORY.md file for more info.
Thanks so much !!!