fbradyirl / openwrt-luci-rpc

Other
34 stars 22 forks source link

Devices being incorrectly marked as home #37

Closed matt-snider closed 1 year ago

matt-snider commented 4 years ago

Description

First of all, thank you for this project! :-)

So my problem is: I'm using the home-assistant component which relies on this library to detect the presence of people to mark them as home or away. I notice that certain devices are being marked as home even though they aren't.

The relevant code in home-assistant is here:

result = self.router.get_all_connected_devices(only_reachable=True)

I have seen the note in the code about OpenWRT version >18.06:

Notes around newer OpenWrt releases (18.06+)

   Do not use `reachable` or `stale` values
   as they flap constantly even
   when the device is inside the network.
   The very existence of the mac in the results
   is enough to determine the "device is home"

But looking at the RPC calls I notice that, (1) reachable appears to be set properly in the results, and (2) only_reachable has no effect because "Flags" is never present in the device entry returned from the ARP RPC call:

if "Flags" in device_entry ...:
   # ...

So due to all of this, it appears devices are only marked as away when their DHCP lease expires, which I don't think is the desired behaviour.

Am I doing something wrong here or do you have any advice on how to troubleshoot this further?

mastnym commented 4 years ago

I'm having the exact same problem, but it appers to have something to do only with iOS devices. My android phone is 'away', but my wifes' iPhone is 'home' even though we were both away. Here is a same issue. I'm on version 1.12 (Homeassistant 0.107), Python 3.7. I'll investigate further, when this happens again (last couple of days it was working without any problems)

Emilv2 commented 4 years ago

I use this custom component to fix this issue. No more iOS devices incorrectly showing up as not home. You'll need luci-app-statistics (or rather one of its dependencies, I'm not sure which one) luci-mod-rpc and also luci-mod-network installed on your openwrt router to make it work.

tiagofreire-pt commented 4 years ago

I have this same issue but with an android device, on luci-mod-rpc 1.1.6 and HA 0.114.4.

pdecat commented 3 years ago

Hi, it seems this issue was fixed on the HA side by https://github.com/home-assistant/core/pull/40160, released in 0.115.0.

I do not face the issue with my Android devices nowadays. Can anyone with an iOS device also confirm this issue is resolved for them?

Emilv2 commented 3 years ago

No not fixed. Only wifi.getiwinfo works reliable for iOS in my experience.

ben-64 commented 3 years ago

Update: with commit 9d40417, it works. However this fix is not included in homeassistant

I have also some troubles with android devices. If I force Wi-Fi disconnection, then device is correctly seen as being away. However, if the device becomes out of range, then it is never flagged as away. It remains in the arp cache entry of the openwrt router.

floriangeigl commented 2 years ago

Hi 👋 I'd hope we can close this issue with the new release from today. The merged PR includes the fix mentioned here. Trying to get this (and other fixes for the luci component) into homeassistant here.

protyposis commented 1 year ago

Unfortunately, I need to reopen this issue as the fix has broken presence detection for some users.

Home Assistant's recent 2023.5 release upgraded this library from 1.1.11 to 1.1.16 (https://github.com/home-assistant/core/pull/91358), containing fix https://github.com/fbradyirl/openwrt-luci-rpc/pull/53 for this issue. Unfortunately, this fix led to wild fluctuations of device availability, as reported in https://github.com/home-assistant/core/issues/92580.

In contrast to the issue description, https://github.com/fbradyirl/openwrt-luci-rpc/blob/2b2bc06b23938e6a71f0cdb2f4955c1a26364f8a/openwrt_luci_rpc/openwrt_luci_rpc.py#L136-L142 seems to perfectly apply to my devices (Google Pixel 7, Samsung Galaxy A50). After multiple tests and hours of monitoring, I can confirm that reachable is fluctuating while my devices are connected, and only the existence of a result reliably determines presence.

I have no idea how to fix this, but I guess we need to either find another fix which considers a fluctuating reachable flag, make its use optional/configurable, or better handle the quirks of different OpenWRT versions.

jfly commented 7 months ago

Unfortunately, I need to reopen this issue

@protyposis, this issue is still marked closed. Did you mean to reopen it, or perhaps to file a new issue?

protyposis commented 7 months ago

I meant to reopen but lack the permission to do it - so it became just a comment :)

jfly commented 7 months ago

@fbradyirl, can you reopen this? Or should we file a new issue?