mueslo/openwrt_hass_devicetracker

Device incorrectly marked as away when switching between radios

Closed this issue · 2 comments

oxan commented

Last night, my phone was incorrectly marked as away while it still was connected to the WiFi. Further inspection of the logs revealed the following sequence of events:

  • My phone connects to the 5 GHz radio (wlan1)
  • push_event.sh gets notified and tells Home Assistant that I'm home
  • A bit later, my phone disconnects from the 2.4 GHz radio (wlan0)
  • push_event.sh gets notified and incorrectly tells Home Assistant that I'm away

Relevant log fragment:

Sat Dec 29 04:48:57 2018 daemon.info hostapd: wlan1: STA AA:BB:CC:DD:EE:FF IEEE 802.11: authenticated
Sat Dec 29 04:48:57 2018 daemon.info hostapd: wlan1: STA AA:BB:CC:DD:EE:FF IEEE 802.11: associated (aid 1)
Sat Dec 29 04:48:57 2018 daemon.notice hostapd: wlan1: AP-STA-CONNECTED AA:BB:CC:DD:EE:FF
Sat Dec 29 04:48:57 2018 daemon.info hostapd: wlan1: STA AA:BB:CC:DD:EE:FF WPA: pairwise key handshake completed (RSN)
Sat Dec 29 04:48:57 2018 user.debug /usr/lib/hass/push_event.sh: push_event wlan1 AP-STA-CONNECTED AA:BB:CC:DD:EE:FF
Sat Dec 29 04:48:57 2018 user.debug /usr/lib/hass/push_event.sh: build_payload AA:BB:CC:DD:EE:FF OnePlus_6.lan 86400
Sat Dec 29 04:48:57 2018 user.debug /usr/lib/hass/push_event.sh: post {"mac":"AA:BB:CC:DD:EE:FF","host_name":"OnePlus_6.lan","consider_home":"86400","source_type":"router"}
Sat Dec 29 04:48:57 2018 user.debug /usr/lib/hass/push_event.sh: post response []
Sat Dec 29 04:53:58 2018 daemon.notice hostapd: wlan0: AP-STA-DISCONNECTED AA:BB:CC:DD:EE:FF
Sat Dec 29 04:53:58 2018 daemon.info hostapd: wlan0: STA AA:BB:CC:DD:EE:FF IEEE 802.11: disassociated due to inactivity
Sat Dec 29 04:53:58 2018 user.debug /usr/lib/hass/push_event.sh: push_event wlan0 AP-STA-DISCONNECTED AA:BB:CC:DD:EE:FF
Sat Dec 29 04:53:58 2018 user.debug /usr/lib/hass/push_event.sh: build_payload AA:BB:CC:DD:EE:FF OnePlus_6.lan 20
Sat Dec 29 04:53:59 2018 user.debug /usr/lib/hass/push_event.sh: post {"mac":"AA:BB:CC:DD:EE:FF","host_name":"OnePlus_6.lan","consider_home":"20","source_type":"router"}
Sat Dec 29 04:53:59 2018 user.debug /usr/lib/hass/push_event.sh: post response []
Sat Dec 29 04:53:59 2018 daemon.info hostapd: wlan0: STA AA:BB:CC:DD:EE:FF IEEE 802.11: deauthenticated due to inactivity (timer DEAUTH/REMOVE)

I think the best solution is to check if the device is still connected to any radio (comparable to what's done in sync_state) before sending the disconnect check.

oxan commented

Okay, so unfortunately this PR doesn't work; as sometimes (but not always) when my device disconnects it still shows up in the iw dev <dev> station dump output...

This is unfortunate. It seems you have to wait a while to what AP (if any) the device connects to.