home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.17k stars 29.85k forks source link

LD2410 state gets stuck, does not change anymore #89138

Closed user45876 closed 4 months ago

user45876 commented 1 year ago

The problem

After some hours, a day at most, the state of the motion and occupation sensor in HA gets stuck. This seems to be new since core 2023.3.1, before it would go to 'unavailable'.

Also, reloading helped before bit now reloading needs a core restart.

What version of Home Assistant Core has the issue?

2023.3.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

LD2410_BLE

Link to integration documentation on our website

https://www.home-assistant.io/integrations/ld2410_ble

Diagnostics information

Will provide after next failing, enabled debug logging.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @930913, mind taking a look at this issue as it has been labeled with an integration (ld2410_ble) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `ld2410_ble` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign ld2410_ble` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


ld2410_ble documentation ld2410_ble source (message by IssueLinks)

pawlikmichal commented 1 year ago

Hello. With 2023.3.0 I have the same problem.

user45876 commented 1 year ago

What is weird: I am using two LD2410C, both visa identical but proxies and with identical FW. One is running for days, one needs a Homeassistant for restart every some hours but works flawlessly after that.

Are you guys using ESPHome bt proxies as well!?

pawlikmichal commented 1 year ago

Yes, I'm using ESPHOME BT proxy. I will try to use another one LD2410B and will find if it behave the same way.

wip58 commented 1 year ago

Hi there, I am experiencing the same problem - LD2410B dropping out after several hours - randomly (never making through the night). LD2410 becomes unavailable. Same issue on both firmwares (1.07 and newest 2.something). I am using BT proxy on Olimex POE. Any suggestion how to rectify this are welcome :)

user45876 commented 1 year ago

So I read a little in issues regarding esphome btproxies. There was one, where the suggestion was, that with lower loglevels, it would work longer: https://github.com/esphome/issues/issues/3951#issuecomment-1362760623 . OTOH, we should rise the loglevels, not lower them ;)

But it seems to be related to btproxies, right? For me, a restart of HA core. insta-solves it reliably for some hours, maybe a day. Powering a btproxy off and on again does nothing, however. Kinda weird.

pawlikmichal commented 1 year ago

In my case deleting and adding integration again works for some hours, sometimes minutes.

wip58 commented 1 year ago

In my case deleting and adding integration again works for some hours, sometimes minutes.

Exactly same here.

andreasbuff commented 1 year ago

Yes, unfortunatly I am having same "freeze" after some hours problem. When HA is rebooted, HLK-LD2410 becomes available for some hours again.... then same problem starts over. HA Version 2023.3.3. Supervisor 2023.03.1

I have a suspicion that the problem comes from the BLE proxy (ESPHome). I read somewhere that the LD2410 only supports 1 BLE connection. The problem is probably that there are multiple BLE proxies (overlapping BLE-Trackers) around in my area. As soon as the LD2410 has established a connection to one of the BLE proxies, it "disappears" for the others. If, for some reason, another BLE tracker then takes over the lead, the device suddenly "stands still" in the HA -> which can be seen as "freeze". The problem is therefore probably in the firmware of the LD2410 itself (not allowing multiple BLE connections) or in the BLE proxy that no longer enables this connection? (I'm not an expert, but maybe that's also in the definition of BLE itself?)

Dont get me wrong. Both the BLE-Proxy for HA and the LD2410 integration are really big Inventions in the last months, but if my suspicion turns out to be right, I am afraid, we have to chose between one or the other :-(

clspeter commented 1 year ago

Same here, LD2410B status hang after few hour with only 1 esp32 BT proxy.

Microclisma commented 1 year ago

Same problem here, and I also have just an ESP32 repeater. Restarting the addon is enough to make it work again anyway. No need to completely restart HA.

user45876 commented 1 year ago

Ah, this could be gold - restarting esphome is enough? Will test that on the naxt hang. Because constant core restarts are not great, esphome restarts however might be ok.

pawlikmichal commented 1 year ago

Restarting ESP32 isn't necessary. Only restarting integration can help, but not every time, Sometimes You need to delete device and add it again.

user45876 commented 1 year ago

Ok, misunderstood that, thanks for clarifying. For me, it wants a core restart after reloading a LD sensor from inside integrations.

andreasbuff commented 1 year ago

Same problem here, and I also have just an ESP32 repeater. Restarting the addon is enough to make it work again anyway. No need to completely restart HA.

Hello, thank you and I am glad, that you can confirm, that it is not BLE Proxy itself. Could it be that you (or in your environment) is another BLE-Tracker, such as Smart Phone? What I also tried was: I Used a Tracker-APP on Smart-Phone. Then "connect" to my LD2410. As long I was using this connection, the LD2410 was "unavailable" in the HA-LD2410 Device-Map.... When I released the connection and rebooted the LD2410 the connection reapeared and was "available". Hence if one Tracker is connected to the LD2410 it is no longer available for another BLE-Tracker....

pawlikmichal commented 1 year ago

No, I'm not using another tracker.

MasonVX commented 1 year ago

I have the same problem and it is something in HA or in the plugin. I use an HA Yellow with no ESPHome as proxy or something. After restart HA it works for a view hours. Then it stops and it does not recover. After the connection to HA breaks, I can connect to the sensor via the app on my mobile phone, so the sensor is still running.

user45876 commented 1 year ago

That is a good datapoint, thank you. This is exactly the behaviour I am seeing with esphome bluetooth proxies as well.

MasonVX commented 1 year ago

I forgot to mention since HA Yellow has no Bluetooth, I have a CM4 Module with Bluetooth, so technically it‘s Raspi4 Bluetooth. The LD2410C ist directly connected to the power lines of an usb cable which itself is powered by a USB Power Supply. The device is about 15cm distance to the Yellow

alexanderznamensky commented 1 year ago

I can confirme (my case):

HLK-LD2410B is working without freezing in case of direct connection to bluetooth of Raspberry Pi (in that time device is not appered in mobile application). If it connected through ESPHome BLE proxy (I have two ESP32 proxy), then connection is brocken after limited period of time.

I think @andreasbuff is right and the LD2410 only supports 1 BLE connection.

Korki67 commented 1 year ago

Hi there,

same issue here. This is my workaround which does work:

Regards, Horst

user45876 commented 1 year ago

Horst, that is great. I will try. I am converting my sensors to D1 Mini ones, which are also small and cheap but it is a bummer, since the 'naked' LD2410C are so amazingly small.

For me, sensors get stuck - they just do not change anymore. Maybe just reloading them every othger hour might work.

captshadab commented 1 year ago

Hi there,

same issue here. This is my workaround which does work:

  • id: '9999999999999' alias: occupancy_reload description: '' trigger:

    • platform: state entity_id:

    • binary_sensor.hlkld2410b####_occupancy to: unavailable for: hours: 0 minutes: 1 seconds: 0 condition: [] action:

    • service: homeassistant.reload_config_entry data: {} target: entity_id: binary_sensor.hlkld2410b####_occupancy mode: single

Regards, Horst

this is forcing to restart home assistant or else the integration wont start. the integration is not behaving like other integration where we can reload

user45876 commented 1 year ago

On a side note and rather OT, I have migrated all my LD2410C to esphome and ESP8266 and added a BH1750 light sensor, as the on device one is rather bad - it is more reliable and also has the (imo huge) benefit of being able to tune the LD2410 'in situi' with the app via bluetooth.

This is my config:

esphome:
  name: presence-1
  friendly_name: Presence 1

esp8266:
  board: d1_mini

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "xyz"

ota:
  password: "abc"

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

button:
  - platform: restart
    name: "Restart"

i2c:
  frequency: 400kHz

sensor:
  - platform: bh1750
    name: "Illuminance"
    update_interval: 60s
    device_class: "illuminance"
    unit_of_measurement: "lx"

uart:
  id: uart1
  tx_pin: TX
  rx_pin: RX
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
  timeout: 30s
  max_move_distance : 6m
  max_still_distance: 6m
  g0_move_threshold: 50
  g0_still_threshold: 0
  g1_move_threshold: 50
  g1_still_threshold: 0
  g2_move_threshold: 40
  g2_still_threshold: 40
  g3_move_threshold: 30
  g3_still_threshold: 40
  g4_move_threshold: 20
  g4_still_threshold: 30
  g5_move_threshold: 15
  g5_still_threshold: 30
  g6_move_threshold: 30
  g6_still_threshold: 20
  g7_move_threshold: 30
  g7_still_threshold: 20
  g8_move_threshold: 30
  g8_still_threshold: 20

binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
user45876 commented 1 year ago

Hi there, same issue here. This is my workaround which does work:

  • id: '9999999999999' alias: occupancy_reload description: '' trigger:

    • platform: state entity_id:

    • binary_sensor.hlkld2410b####_occupancy to: unavailable for: hours: 0 minutes: 1 seconds: 0 condition: [] action:

    • service: homeassistant.reload_config_entry data: {} target: entity_id: binary_sensor.hlkld2410b####_occupancy mode: single

Regards, Horst

this is forcing to restart home assistant or else the integration wont start. the integration is not behaving like other integration where we can reload

This is unfortunately true for me, as well.

captshadab commented 1 year ago

Hi there, same issue here. This is my workaround which does work:

  • id: '9999999999999' alias: occupancy_reload description: '' trigger:

    • platform: state entity_id:

    • binary_sensor.hlkld2410b####_occupancy to: unavailable for: hours: 0 minutes: 1 seconds: 0 condition: [] action:

    • service: homeassistant.reload_config_entry data: {} target: entity_id: binary_sensor.hlkld2410b####_occupancy mode: single

Regards, Horst

this is forcing to restart home assistant or else the integration wont start. the integration is not behaving like other integration where we can reload

This is unfortunately true for me, as well.

Has the issue started with March core update. I just received it today and it's a menace

Korki67 commented 1 year ago

Dear all,

I made the script with the UI, let it run manually and it worked. Later, I also saw it is not working automatically. The trigger seems not to work. Sure a workaround is bad and we all wait for the good solution.

Anyhow, my LD2410 just got "unavailable" and the script which I did adjust before was working nicely. This is the updated code:

- id: '9999999999999'
  alias: occupancy_reload
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.hlk_ld2410b_####_occupancy
    to: unavailable
    for: 00:02:00
  condition: []
  action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: binary_sensor.hlk_ld2410b_####_occupancy
  mode: single

Hope it is working for you now ...

Cheers, Horst

Korki67 commented 1 year ago

it extends the life but fails just later ... only restarting HA helps .... does anybody have better ideas?

captshadab commented 1 year ago

it extends the life but fails just later ... only restarting HA helps .... does anybody have better ideas?

Yes I do And mine is working since last 48 hrs

I will create a post and explain what I did

user45876 commented 1 year ago

As I said above and sorry for not helping in the issue directly - I have kind of given up and migrated to small boxes containing an ESP8266, the LD2410 and a BH1750. Reliable and better light sensor.

captshadab commented 1 year ago

it extends the life but fails just later ... only restarting HA helps .... does anybody have better ideas?

90100

Korki67 commented 1 year ago

I can confirme (my case):

HLK-LD2410B is working without freezing in case of direct connection to bluetooth of Raspberry Pi (in that time device is not appered in mobile application). If it connected through ESPHome BLE proxy (I have two ESP32 proxy), then connection is brocken after limited period of time.

I think @andreasbuff is right and the LD2410 only supports 1 BLE connection.

Hi Andreas, could you past an example how to access the LD2410 from a Raspi once the LD2410 is connected to the Raspi via Bluetooth? Regards, Horst

Ultrawipf commented 1 year ago

Same or similiar related issue happens here since the 2023.4 version of homeassistant here.

Previously it would sometimes become unavailable but reconnect, since the 2023.4 version (2023.4.6, supervised, OS 10.0, raspberry pi 4) it does not reconnect automatically and gets stuck in the unavailable state and requires manually reloading the extension until it stops working after the next disconnect again.

Adding an automation that reloads when it becomes unavailable works as a workaround.

1liminal1 commented 1 year ago

Can you provide your YAML for reloading it?

Korki67 commented 1 year ago

Hi there,

how to reload can be found above. Anyhow, it was extending the life only. Now for whatever reason, reloading does not do anything anymore, so it got worse. Also manual reloading doesn't do anything anymore.

Regards, Horst

1liminal1 commented 1 year ago

Oh its there lol, I ended up figuring it out. But yes, does nothing :(

Its a real pity

Thanks for letting me know though :)

wip58 commented 1 year ago

Hi there, had the same problem as stated in March (above). Had two LD 2410 modules setups using BT with Olimex proxy. Added also a BT dongle to my RPi (tried both proxies together, each one and so on...) Frustrated, I went with one setup for the WiFi option by adding a Wemos D1 (esp8622) to it. That solved one problem. The other one kept disconnecting from time to time without any reason that I can spot. Kept reloading the integration in order to have the sensor back in HA. After some time and two HA updates the remaining BLE module kept its connection for more and more hours and even days. Now it works properly surviving HA soft and hard resets of my RPi. I am using the current version of HA OS, LD2410 is on 2.04.23022511 version (no change from March) and a BT dongle as proxy. Maybe my post does not help much, but I would like to share it with you as I had raised a problem in the past. BR, Wieslaw

1liminal1 commented 1 year ago

Thanks mate :)

What's the distance to the BT proxy?

wip58 commented 1 year ago

What's the distance to the BT proxy?

Bellow 1 m.

1liminal1 commented 1 year ago

Yeah, Im running the same thing right now and it does seem to be stable. But might be just easier to solder the whole thing together. At least its only one power cable HAHA. See how lazy I am lol

TGda commented 1 year ago

Hi guys

To reload only the LD2410 BLE integration do this:

  1. Goto integrations page. Click anywhere in the browser and select inspect. Select Network tab

  2. Reload the integration and you'll get the requested url. Copy that URL in notepad. image

  3. Goto your profile and create a long-lived token. Name it as your choice. Copy the token to notepad. image

  4. Goto file editor and add: shell_command: reload_ble: "curl -k -X 'POST' -H 'authorization: Bearer HERE_THE_TOKEN_FROM_STEP3' HERE_THE_URL_STEP2" Its a long line image Dont forget the quotes image

  5. Then go your automation and do the magic

alias: Reload Ble description: "" trigger:

This code will wait 5 seconds if the sensor becomes unavailable and will reload the integration by POSTing a the url that you pulled from the browser inspect. The action will call the code in the configuration yaml.

Just say thanks =)

Soukyuu commented 1 year ago

Since core update 2023.5.x, the integration requires full HA restart to be reloaded. This has gotten completely unusable for me. No sense in having presence detection that lets the light on the whole night. Not at these electricity prices.

The maintainers should add a warning to the documentation so that people don't end up wasting money until this is fixed, tbh.

Soukyuu commented 1 year ago

Is it me, or is this working better since HA 2023.7.x? I think the change mentioned something about btproxy improvements.

The sensor has stayed functioning for several days now.

1liminal1 commented 1 year ago

That's interesting, I've just plugged one in, lets see how it goes :)

Seems like detection distance and such are missing now?

image

Soukyuu commented 1 year ago

@1liminal1 : they are, just disabled by default. You have to go to settings and enable them (same as you did with Motion).

image

Also checked the changelog, you need HA 2023.7.x and ESPHOME 2023.6.x for the changes to work.

sunsetitaly commented 1 year ago

Same situation over here. In my case it works sometimes for a day, but the becomes unresponsive. I need to reload the integration and restart home assistant. Sometimes is not enough and I need to power off the LD2410 BLE sensor and repeat all procedure again

bdraco commented 1 year ago

It looks like the library retries forever so if the device disconnects while its writing a command that might be why it can get stuck

https://github.com/930913/ld2410-ble/blob/7a37db351cb887b2259c654410dad2c093336003/src/ld2410_ble/ld2410_ble.py#L436

Soukyuu commented 1 year ago

That would explain it, there are disconnects now and then in my logs.

And while it has gotten better, seems like it got stuck again yesterday. At least reloading the integration now doesn't require a full restart anymore.

1liminal1 commented 1 year ago

Same issues, stiill drops off after an hour or so... Maybe one day it will work LOL :)

kkaminski7 commented 1 year ago

Hi Recently I have bought few ld2410b sensors just to experience this issue. My Epshome bt proxy is istalled on sonoff mini extreme. I have disabled ble tracker in esphome configuration and it doesn't freeze anymore, at least so far it is OK. It has been working fine for past 24h. Earlier it froze within 30 minutes. Home Assistant: 2023.7.2 Esphome version: 2023.6.5

#esp32_ble_tracker:
#  scan_parameters:
#    interval: 1100ms
#    window: 1100ms
#    active: true

bluetooth_proxy:
  active: true

Update: it froze after 3 days