Esphome sensor data from a01nyub ultrasone distance meter not always updating in HA

As it says in the topic.
Using a nodemcu esp8266 board with a a01nyub sensor measuring the waterlevel in an underground rainwater collector tank.
Want to use this to create automations using automatic valves to fill to tank when level is to low after a dry spell so I can continue using the water flush toilets.

Problem is data from the sensor is not always updated. It is ok after I reboot the board or redeploy/install an update but after a while it just stops sending data to HA. The logs from the esp device still say it is sending a value every 20 seconds

[21:01:17][D][sensor:093]: 'Distance': Sending state 1.56800 m with 3 decimals of accuracy
[21:01:37][D][sensor:093]: 'Distance': Sending state 1.56800 m with 3 decimals of accuracy

The section in my espconfig :

uart:
    rx_pin: D4  
    baud_rate: 9600
    debug:
sensor:
  - platform: a01nyub
    id: a01nyub_sensor
    name: "Distance"
    unit_of_measurement: 'm'
    accuracy_decimals: 3
    filters:
      - throttle: 5s
      - heartbeat: 5s
      - quantile:
         window_size: 7
         send_every: 4
         send_first_at: 3
         quantile: .9
      - debounce: 0.1s

switch:
  - platform: gpio
    name: "Relay"
    pin: D2

  - platform: restart
    name: "Ultrsoon Restart"

Played around with the filters quite a lot and even ran without them.
Right now the value in HA hasn’t been updated for more than 24 hours (while it did rain quite bit) and I know if a press the restart button it will be fine for a while.

EDIT :

Now after a reboot of the device I get this in the logs

[21:41:19][D][sensor:093]: 'Distance': Sending state 1.50400 m with 3 decimals of accuracy
[21:41:39][D][sensor:093]: 'Distance': Sending state 1.50400 m with 3 decimals of accuracy

So it seems the sensor somehow “gets stuck” and keeps sending the same value so HA is indeed not updated and I gets going again after a reboot.

Anyone with a tip on where to look or a solution? Could the sensor be faulty?
Workaround could be to automate the reboots from HA but don’t want to go that route just yet.

What version of ESPHome are you running? There is an update for this sensor coming out with 2023.11.7. I am running 2023.11.6 which seems to be the latest available non-dev version.

I’m trying to use this sensor without success. In my case I’m using an ESP32 and I have never received any value.
The sensor works because in Arduino I’m able to receive the value. I have connected the UART Output (TX) cable from the sensor to the pin GPIO16:

esp32

I’m using this code:

uart:
   rx_pin: GPIO16
   baud_rate: 9600
 
 sensor:
   - platform: "a01nyub"
     name: "Distancia sensor-aigua"
     unit_of_measurement: 'm'
     accuracy_decimals: 3
     filters:
       - throttle: 5s
       - heartbeat: 5s
       - quantile:
          window_size: 7
          send_every: 4
          send_first_at: 3
          quantile: .9
       - debounce: 0.1s

I don’t know what can I do…

I’m running ESPHome 2023.11.6. Good to hear it will be fixed in the next release.

Probably ok but make sure you have the Tx from the sensor connected to your Rx pin. The Rx wire from the sensor is not connected in my case.

I my case (with the nodemcu) I had to change the UART Rx pin from the default to D4 because esphome uses the UART for debugging. So I am now using GPIO0 (D4) instead of the one marked Rx on the board (GPIO3) because that wouldn’t work for me. https://diyusthad.com/2020/05/nodemcu-esp8266-pinout.html
Could be the same problem with the ESP32

I have tried changing the TX cable in several pins with no result.

Where have you seen these values?

In my log I don’t see anything:

image

Where have you seen these values?

In the logs from the esp device.
Is the sensor properly powered? If it is the smal led starts blinking on my esp8266 indicating it is receiving data over UART.
You could aso set the uart debugging on like this :

....
uart:
    rx_pin: D4  
    baud_rate: 9600
    debug:
...

Finally using GPIO23 it works. Now I’m going to analyse the problem that you are comment. I will come back with my feedback.

1 Like

Switched to the dev version of the esphome add-on yesterday and can indeed confirm this fixes the problem with the “stuck” values.

(and yes, it was/is raining again in Belgium)

image

1 Like

Yesterday I left the sensor running all night and this morning it was still working fine. But this afternoon I found the ESP32 board with a constantly blinking TX led and HA has not received any new data for hours.

I am going to study your suggestion about the “dev version of ESPHome”. I am a newcomer to HA.

What do you think about this link?

https://community.home-assistant.io/t/dfrobot-ultrasonic-sensor-iuntegration/546769/3

That link is to an old thread before the sensor support was added, so no longer relevant.
It is now supported but the current version, 2023.11.06, contains a bug where the value sometimes is no longer updated. This will be fixed in the next release, 2023.11.07 (or 2023.12.01 I guess). If you don’t want to wait for this release you could run the dev version of the esphome addon where this bug is already fixed. You would have to remember to switch back to the non dev version in a couple of days/weeks when the next release is there.

OK. I have followed your instructions and I have updated the ESP32 software.

The system is now working. I will analyse the situation tomorrow. Thank you for your time.

18 hours later, still working!!!

1 Like