rmoesbergen / openwrt-ha-device-tracker

OpenWRT device tracker for Home Assistant that actually works
101 stars 18 forks source link

HA reports zone as unknown #47

Closed 0utc45t closed 3 months ago

0utc45t commented 3 months ago

I have one openwrt AP at home and another at my garage some distance away. These sites are connected with wireguard. Both sites can report my location as "home" and "away" to the home-assistant running at my home. When I try to get the garage AP to report my presence with the correct zone name and change the presence-detector.settings.json file line

"location": "home",

to

"location": "garage",

the home-assistant reports my location as unknown. I've tested with developer tools to run service "device tracker see" with my MAC and zone name and using this method I get the frontend to show everything I put in the location box. So I suspect the problem is here.

rmoesbergen commented 3 months ago

Hi @0utc45t , can you enable the 'debug' setting in the config file? It show exactly what's posted to HA so we can check if that's what's expected. Thanks.

0utc45t commented 3 months ago

Hi Ronald,

I changed the configs location from home to garage and changed my MAC. This is all the logs I get from logread command after restarting the presence-detector.

Fri Jul 12 17:05:34 2024 daemon.info presence-detector[15835]: Device 12:34:56:78:90:ab is now at garage Fri Jul 12 17:05:34 2024 daemon.debug presence-detector[15835]: Posting to HA: {'mac': '12:34:56:78:90:ab', 'location_name': 'garage', 'source_type': 'router'} Fri Jul 12 17:05:34 2024 daemon.debug presence-detector[15835]: API Response: b'[]'

And HA reports my location "unknown"... then I disconnected my phone from the wlan and I got these lines.

Fri Jul 12 17:11:50 2024 daemon.notice hostapd: phy0-ap1: AP-STA-DISCONNECTED 12:34:56:78:90:ab Fri Jul 12 17:11:50 2024 daemon.info presence-detector[15835]: Device 12:34:56:78:90:ab is now away Fri Jul 12 17:11:50 2024 daemon.debug presence-detector[15835]: Posting to HA: {'mac': '12:34:56:78:90:ab', 'location_name': 'not_home', 'source_type': 'router'} Fri Jul 12 17:11:50 2024 daemon.debug presence-detector[15835]: API Response: b'[]'

and HA reports my location "away" as it should. Oh, maybe I should have started with disconnected status.... well, here is the logs after reconnecting again to wlan.

Fri Jul 12 17:14:53 2024 daemon.info hostapd: phy0-ap1: STA 12:34:56:78:90:ab IEEE 802.11: authenticated Fri Jul 12 17:14:53 2024 daemon.info presence-detector[15835]: Device 12:34:56:78:90:ab is now at garage Fri Jul 12 17:14:53 2024 daemon.debug presence-detector[15835]: Posting to HA: {'mac': '12:34:56:78:90:ab', 'location_name': 'garage', 'source_type': 'router'} Fri Jul 12 17:14:53 2024 daemon.debug presence-detector[15835]: API Response: b'[]' Fri Jul 12 17:14:53 2024 daemon.info hostapd: phy0-ap1: STA 12:34:56:78:90:ab IEEE 802.11: associated (aid 3) Fri Jul 12 17:14:53 2024 daemon.notice hostapd: phy0-ap1: AP-STA-CONNECTED 12:34:56:78:90:ab auth_alg=open Fri Jul 12 17:14:53 2024 daemon.info hostapd: phy0-ap1: STA 12:34:56:78:90:ab WPA: pairwise key handshake completed (RSN) Fri Jul 12 17:14:53 2024 daemon.notice hostapd: phy0-ap1: EAPOL-4WAY-HS-COMPLETED 12:34:56:78:90:ab

Thanks for the quick reply. Anything else I can do to help?

rmoesbergen commented 3 months ago

Thanks. So you mentioned it did work if you call the 'see' service from developer tools? What's the difference between your payload en the one that's logged after 'Posting to HA'?

0utc45t commented 3 months ago

I'm not quite sure I understand the question. When I use the HA frontends developer tools in yaml mode like this

service: device_tracker.see data: mac: 12:34:56:78:90:ab location_name: garage

it changes my location to garage.

Oh, the difference is the missing source_type: router. I added that to the dev tools service call and I get same behaviour, my location is changed to unknown. Is this actually HA bug?

rmoesbergen commented 3 months ago

Interesting... so source_type: router makes it break. I guess HA doesn't expect a "real" location from a router device, only from GPS devices. I remember I had to change device_type to router, or person tracking wouldn't work properly. I guess it wouldn't hurt to get some explanation from HA what's going on here. Do you feel like creating an issue there?

0utc45t commented 3 months ago

I have written about this in HA discord channel... and I just got a reply stating that the device_type: router is only home or not_home. It seems that some other device_type should be used instead of router?

rmoesbergen commented 3 months ago

I have written about this in HA discord channel... and I just got a reply stating that the device_type: router is only home or not_home. It seems that some other device_type should be used instead of router?

Ok, so that explains it. I can make the device type configurable? But I remember there were issues when it wasn't set to router, but forgot the details.

0utc45t commented 3 months ago

Does this help to remember what was the problem and circumvent it from happening again? https://www.home-assistant.io/integrations/person/ In any case, it would be nice to be able to configure the device type to tracker_gps atleast at the garage. Just wondering if I then have to set in the "location": zone name or coordinates? And does "away": "not_home" still work?

rmoesbergen commented 3 months ago

Ah, yes, it was the ordering. Routers have higher precedence over GPS devices, so when not sending device_type router, it would sometimes be overridden by another device and not set the person away on disconnects. But this might not a be problem or you, maybe just try it. I'll create a PR so make the device type configurable so you can test.

rmoesbergen commented 3 months ago

@0utc45t Can you please try the version in PR #49 and let me know if it works? The README file has been updated with the new setting.

0utc45t commented 3 months ago

@rmoesbergen I confirm, now it works. Thanks!

rmoesbergen commented 3 months ago

Cool, thanks!