mueslo / openwrt_hass_devicetracker

Simple OpenWRT package which forwards device connection changes to a HomeAssistant instance
GNU General Public License v3.0
92 stars 31 forks source link

Device incorrectly marked as away when switching between radios #20

Closed oxan closed 5 years ago

oxan commented 5 years ago

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:

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 5 years ago

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...

mueslo commented 5 years ago

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