#19865·esphome

dfrobot_sen0395: Time conversion bug in output_latency (milliseconds treated as seconds)

Author: zhan-plCreated Sep 28, 2026Updated Sep 28, 2026

The problem

There is a time conversion/math bug in the dfrobot_sen0395 component regarding the output_latency settings. The component seems to pass the time value to the sensor incorrectly, leading to integer overflow and massive delays.

Expected behavior: Setting delay_after_disappear: 5.0s should set the sensor's latency to 5 seconds.

Actual behavior: When setting delay_after_disappear: 5.0s, ESPHome correctly parses it as 5000 ms. However, this value (5000) is then incorrectly treated as seconds by the component/sensor logic. The sensor calculates steps for 5000 seconds (at 25ms per step). Since it's a 16-bit register, the value maxes out at 65535. 65535 * 0.025s = 1638.375s.

As a result, the sensor gets locked in the "presence detected" state for over 27 minutes.

Workaround found: If I set delay_after_disappear: 5ms in the YAML, the component passes "5" to the sensor, which then correctly applies a 5-second latency.

Relevant YAML configuration:

dfrobot_sen0395:
  uart_id: uart_bus
  id: my_sen0395

button:
  - platform: template
    name: "Set Config"
    on_press:
      - dfrobot_sen0395.settings:
          output_latency:
            delay_after_detect: 0s # This gets converted to 0.000s in logs
            delay_after_disappear: 5.0s # This causes the 1638s bug

Logs:

[D][uart_debug:157]: >>> "setLatency 0.000 1638.375"
[I][dfrobot_sen0395.commands:222]: Updated output latency config:
[I][dfrobot_sen0395.commands:222]:   Signal that someone was detected is delayed by 0.000 s.
[I][dfrobot_sen0395.commands:222]:   Signal that nobody is detected anymore is delayed by 1638.375 s.

Which version of ESPHome has the issue?

2026.9.0

What type of installation are you using?

Home Assistant Add-on

What platform are you using?

ESP32

Component causing the issue

dfrobot_sen0395

YAML Config

yaml
esphome:
  name: esp-mmw-biurko2
  friendly_name: esp-mmw-biurko2

esp32:
  board: esp32dev
  framework:
    type: arduino
    advanced:
      sram1_as_iram: true


# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Mmw-Biurko Fallback Hotspot"
    password: "xxxx"

captive_portal:
    

uart:
  id: uart_bus
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  debug:
    direction: BOTH
    dummy_receiver: false
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

dfrobot_sen0395:
  uart_id: uart_bus
  id: my_sen0395

binary_sensor:
  - platform: dfrobot_sen0395
    name: "Detected"
    device_class: motion

  - platform: gpio
    name: "Detected via GPIO"
    device_class: motion
    pin:
      number: GPIO5
      mode: INPUT_PULLDOWN

switch:
  - platform: dfrobot_sen0395
    dfrobot_sen0395_id: my_sen0395
    type: turn_on_led
    name: LED

button:
  - platform: template
    name: "Load my settings"
    on_press:
      - dfrobot_sen0395.settings:
          factory_reset: False
          detection_segments:
            - [15cm, 100cm]
          output_latency:
            delay_after_detect: 0.1s
            delay_after_disappear: 10s
          sensitivity: 5

  - platform: template
    name: "Restore SEN0395"
    on_press:
      - dfrobot_sen0395.settings:
          factory_reset: True

Anything in the logs that might be useful for us?

txt
[D][uart_debug:157]: >>> "setLatency 0.000 1638.375"
[I][dfrobot_sen0395.commands:222]: Updated output latency config:
[I][dfrobot_sen0395.commands:222]:   Signal that someone was detected is delayed by 0.000 s.
[I][dfrobot_sen0395.commands:222]:   Signal that nobody is detected anymore is delayed by 1638.375 s.

Additional information

As a temporary workaround, I am currently using the following settings (using milliseconds instead of seconds to bypass the conversion bug):

output_latency:
  delay_after_detect: 0ms
  delay_after_disappear: 5ms