I don’t seem to get a JSN-SR04T distance sensor to work. I have tried with both a ESP8266 board and a atom lite esp32 and none of them work. I have also bought an extra JSN-SR04T sensor if the first one was faulty but I get the same result.
> [01:06:35][D][ultrasonic.sensor:036]: 'garden_watertank_distance' - Distance measurement timed out!
> [01:06:35][D][sensor:093]: 'garden_watertank_distance': Sending state nan m with 2 decimals of accuracy
If I connect a HC-SR04 sensor it works perfectly
> [00:57:40][D][ultrasonic.sensor:040]: 'garden_watertank_distance' - Got distance: 0.057 m
> [00:57:40][D][sensor:093]: 'garden_watertank_distance': Sending state 0.05677 m with 2 decimals of accuracy
When I ordered my JSN-SR04T sensors from Amazon, I received a very similar looking AJ-SR04M, it said JSN-SR04T on the box but in the box was an AJ-SR04M. Couldn’t get it to work, asked Amazon for a replacement and received the same incorrectly labled boxes again - had to order from a different vendor.
I couldn’t get the code to work just using the pin numbers, it worked fine on my old sensor (forgot what it’s called) but I had to change it to this
I struggled also with this sensor. I discovered that I also purchased a AJ-SR04M sensor and that this device ISN’T the same as the JSN-SR04T which is documented in ESPHOME.
In the ESPHOME documentation they give 2 modes as an option. I succeeded in making mode 1 work with my Home Assistant. But instead using a 47K resistor (ESPHOME documentation), I used 120k resistor at R19 as documented by probots for the automatic mode.
I think the mode 2 option isn’t possible with the AJ-SR04M as the trigger signal will be sent as a 0x05 (ESPHOME documentation) while the sensor would expect a 0x01 signal before returning the distance.
This is a real bummer because this mode would allow reducing power consumption.
Therefore, support for this slightly different sensor would be great!
do you have the possibility to send me the exact yaml you are using for the sensor. I have soldered on a 120k resistor to put it into mode 1 but still can’t get it to work.
i used jsn-sr04m, as it is available when ever you get jsn-sr0t, and i used it with d1 mini and esp32 wroom too, here is the configuration with d1 mini
switch:
- platform: restart
name: "water_level_sensor reboot"
text_sensor:
- platform: wifi_info
ip_address:
name: sensor IP Address
ssid:
name: ESP Connected SSID
- platform: version
name: "ESPHome Version"
entity_category: diagnostic
uart:
tx_pin: GPIO5
rx_pin: GPIO4
baud_rate: 9600
sensor:
- platform: "jsn_sr04t"
name: "water-depth"
id: water_level
update_interval: 10s
unit_of_measurement: "ft" # Set the unit to feet
accuracy_decimals: 2 # Ensure the output has 2 decimal places
filters:
- lambda: |-
if (x < 0.2 || x > 4.50) {
return NAN; // Return NaN for out-of-range values
}
float value_in_feet = x * 3.28084; // Convert meters to feet
return int(value_in_feet * 100 + 0.5) / 100.0; // Round to 2 decimal places
- platform: template
name: "%"
# if value in metters ( as if sensor is placed above your tank full level 0.27 meter, (as minimum range is 0.2 meter, so it should be atleast 0.2 m above))
# and if full tank depth when it should be considered empty, is 1.22 meter, adjust height as you need it.
# if converted in feet as above, then % should be calculated from feets
unit_of_measurement: "%"
lambda: !lambda |-
if ((id(water_level).state) <= 0.886){
return 100;
}
else if ((id(water_level).state) >= 4.0){
return 0;
} else {
return (100 - ((id(water_level).state - 0.866) / 3.114) * 100);
}
update_interval: 10s
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 60s
- platform: uptime
name: uptime
filters:
- lambda: return x / 3600;
unit_of_measurement: "h"
update_interval: 60s
- platform: template
name: "Free Heap Memory"
lambda: |-
return ESP.getFreeHeap() / 1024.0; // Convert bytes to KB
unit_of_measurement: "KB"
update_interval: 5h
- platform: template
name: "Chip ID"
lambda: |-
return (float)ESP.getChipId();
update_interval: 12h
accuracy_decimals: 0
entity_category: diagnostic
Because when I connect the JSN to the pin D5 and D6 (I haven’t added any resistor) I cannot get any distance measure. I have also discovered that I have a AJ-SR04M board. Do I must add the resistor or is there any way to do it without them?