rmoesbergen / openwrt-ha-device-tracker

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

SSL not working. #26

Closed rmedros closed 1 year ago

rmedros commented 1 year ago

Hi,

I know this is not a bug, but I was just wondering if this would work with an SSL address. I installed SSL on my router and modified presence-detector.py to import and use it. Seems like HomeAssistant rejects the call. Is there any solution for that?

Thanks, Rob

rmoesbergen commented 1 year ago

Hi @rmedros , how exactly did you modify presence detector and how does HA reject the call? Any exceptions/logging you can share? Looking at the code and from a little experiment, it should 'just work'.

EDIT (after some more testing): you should have the 'python3-openssl' package installed for SSL support. Other than that, the unmodified code should be able to use https.

rmedros commented 1 year ago

Hi @rmoesbergen,

I was wondering if it was because I have https below. This is what I am seeing when I use the standard presence-detector.py and I have installed Python3-ssl.

Thanks, Rob

{ "hass_url": "https://dnsname.duckdns.org:8123", "hass_token" : "I have a token here." "interfaces": ["hostapd.wlan0", "hostapd.wlan1"], "offline_after": 3, "poll_interval": 15, "full_sync_polls": 10, "ap_name": "", "location": "home", "away": "not_home", "debug": true }

Fri Mar 17 13:18:39 2023 daemon.debug presence-detector[2300]: <urlopen error [Errno 111] Connection refused> Fri Mar 17 13:18:39 2023 daemon.info presence-detector[2300]: Home Assistant seems to be offline, sleeping... Fri Mar 17 13:18:44 2023 daemon.debug presence-detector[2300]: Posting to HA: {'mac': '20:02:af:77:07:a1', 'location_name': 'home', 'source_type': 'router'}

rmoesbergen commented 1 year ago

Connection refused means there's nothing listening on port 8123. Are you sure you're using the correct port, and have setup the proper port-forwarding on your router? You can test by opening the same URL in a browser, which should show the HA web interface.

rmedros commented 1 year ago

Yes it works fine and brings up the HA web interface. I setup my remote access based on this video so the external and internal address is the same. I believe it works because the router is doing a nat loopback. https://duckduckgo.com/?q=everything+smart+home+homeassistant+remote+access&iax=videos&ia=videos&iai=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAK5E2T5tWyM

I'm wondering if its related. Thanks for the help, but I don't want to take up any more of your time.

rmoesbergen commented 1 year ago

Ok, thanks for the explanation. It doesn't look like this a problem with the presence detector, but more of a router/dns/forwarding configuration issue. A simple fix would be to just use your internal IP in the presence detector, or if your router supports it, set up a local DNS record for your duckdns hostname that points to the internal IP of home assistant.

I'll update the readme to add the python3-openssl dependency if https is required.

rmedros commented 1 year ago

Thanks.