401 Unauthorized - mueslo/openwrt_hass_devicetracker (solved)

SOLUTION FOUND and posted below

Hi,

Trying to set up a better device tracking method than nmap with mueslo/ openwrt_hass_devicetracker

Downloaded and installed the v0.1.1 successfully on OpenWRT router after meeting dependencies.

Editted the config file in /etc/config/hass

config hass 'global'
        option host 'a.b.c.d:8123'
        option token 'xyz'
        option timeout_conn '24:00'
        option timeout_disc '00:03'

‘a.b.c.d’ is my correct Hassio IP.
‘xyz’ is a “Long-Lived Access Token” Generated via the webinterface of Hassio.

Ran ‘service hass start’ on OpenWRT.

Syslog of OpenWRT:

Sat Dec 15 18:25:00 2018 user.err /usr/bin/hassd.sh: post response curl: (22) The requested URL returned error: 401 Unauthorized
Sat Dec 15 18:25:00 2018 user.err /usr/bin/hassd.sh: post response curl: (22) The requested URL returned error: 401 Unauthorized

And Hassio reports ‘login attempt failed’.

Added :api to configuration.yaml although that might not be required?
Also ran opkg install hass on the OpenWRT router since it might have been an outdated package. 0.1.1-1 is reported to be installed.

What am I missing here?

AAARGH the package was not updated with the latest commit from 20 Oct.
Manually downloaded functions.sh and got it working.

If anyone likes a step by step tutorial for this device tracker method, let me know.

1 Like

He Saturnus,

I set by step guide to this topic would be great. I have been struggling with the instructions for a while and got stuck at the same point that you are describe.

Regards Tijmen

Hi Tijmen,

You will have to replace /usr/lib/hass/functions.sh with the newer source version here: https://raw.githubusercontent.com/mueslo/openwrt_hass_devicetracker/master/packages/net/hass/files/functions.sh.

Then proceed as described in the topic start. Let me know if you get it working.

Yes got it up and running now. Thanks for the advice.

I am having some issue’s though. Association events work perfect and disassociation when i turn off wifi as well, but when i leave the house the message gets ignored

Sat Feb 23 14:35:39 2019 daemon.info hostapd: wlan1: STA f0:98:9d:b4:fc:39 IEEE 802.11: disassociated due to inactivity
Sat Feb 23 14:35:39 2019 user.debug /usr/lib/hass/push_event.sh: push_event wlan1 AP-STA-DISCONNECTED f0:98:9d:b4:fc:39
Sat Feb 23 14:35:39 2019 user.debug /usr/lib/hass/push_event.sh: push_event ignored as device is still online
Sat Feb 23 14:35:40 2019 daemon.info hostapd: wlan1: STA f0:98:9d:b4:fc:39 IEEE 802.11: deauthenticated due to inactivity (timer DEAUTH/REMOVE)

Do you know this issue?

This is due to commit https://github.com/mueslo/openwrt_hass_devicetracker/commit/212b19f3d95892793abc7bad5ea58bb97a6bf292. You should be able to undo this commit by hashtagging out the green lines in your functions.sh or downloading the older version of the file: https://github.com/mueslo/openwrt_hass_devicetracker/blob/e615d168b0010e430ea3389a6183164dd546ee42/packages/net/hass/files/functions.sh.

If you are sure you are not connected to any of your router WiFi radio’s anymore while this situation occurs, then please also make a bug report at https://github.com/mueslo/openwrt_hass_devicetracker/issues (New issue).

On a more irrational level, I think development of the component is pretty much halted. So be warned one day a (big) change in Home Assistant might break this component forever.

Great, I will try this.

Yes I was already a bit afraid that it wasn’t really actively developed anymore. But it is the only presence detection on OpenWRT that i got working. I think this is because i use the router as a dumb access point, but i am not sure of this. (my main router is from my ISP and doesn’t allow much configuring)

Do you think there is a better way for presence detection?

Some people reported GPS from within the native app to work well and not consume much battery. Like geofencing. Haven’t tried it myself.