Authenticating AppDaemon

I’m following this guide for getting started with AppDaemon.

I can’t get the AppDaemon to connect to HASS — I don’t understand what the ha_key parameter in appdaemon.yaml stands for. I’ve tried both my user’s password and and empty one, both lead to errors:

Authentication error (no / empty ha_key):

$ appdaemon -c ~/homeassistant/conf -D DEBUG
2018-08-30 17:26:33.755980 INFO AppDaemon Version 3.0.1 starting
2018-08-30 17:26:33.757906 INFO Configuration read from: /home/pi/homeassistant/conf/appdaemon.yaml
2018-08-30 17:26:33.758509 DEBUG AppDaemon Section: None
2018-08-30 17:26:33.759043 DEBUG HADashboard Section: None
2018-08-30 17:26:33.765949 INFO AppDaemon: Starting Apps
2018-08-30 17:26:33.767756 WARNING config_dir: /home exists, but is not writeable, owner: root
2018-08-30 17:26:33.771228 DEBUG AppDaemon: Creating worker threads …
2018-08-30 17:26:33.776597 DEBUG AppDaemon: Done
2018-08-30 17:26:33.777148 DEBUG AppDaemon: Entering run()
2018-08-30 17:26:33.777859 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-08-30 17:26:33.824455 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-08-30 17:26:33.825573 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-08-30 17:26:33.826273 DEBUG AppDaemon: Starting utility loop
2018-08-30 17:26:33.826915 INFO Dashboards are disabled
2018-08-30 17:26:33.827339 INFO API is disabled
2018-08-30 17:26:33.827709 DEBUG Start Loop
2018-08-30 17:26:33.846431 INFO AppDaemon: HASS: Connected to Home Assistant 0.77.0
2018-08-30 17:26:33.852264 WARNING AppDaemon: HASS: Error in authentication
2018-08-30 17:26:33.852857 DEBUG AppDaemon: Event type:ha_disconnected:
2018-08-30 17:26:33.853478 DEBUG AppDaemon: {}
2018-08-30 17:26:33.854108 WARNING AppDaemon: HASS: Disconnected from Home Assistant, retrying in 5 seconds
2018-08-30 17:26:33.854657 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-08-30 17:26:33.855191 WARNING AppDaemon: HASS: Unexpected error:
2018-08-30 17:26:33.855680 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-08-30 17:26:33.857711 WARNING AppDaemon: HASS: Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/appdaemon/plugins/hass/hassplugin.py”, line 214, in get_updates
raise ValueError(“Error in authentication”)
ValueError: Error in authentication

Connection refused (user’s password as the key):

$ appdaemon -c ~/homeassistant/conf -D DEBUG
2018-08-30 17:28:27.652872 INFO AppDaemon Version 3.0.1 starting
2018-08-30 17:28:27.653535 INFO Configuration read from: /home/pi/homeassistant/conf/appdaemon.yaml
2018-08-30 17:28:27.654067 DEBUG AppDaemon Section: None
2018-08-30 17:28:27.654577 DEBUG HADashboard Section: None
2018-08-30 17:28:27.660070 INFO AppDaemon: Starting Apps
2018-08-30 17:28:27.662299 WARNING config_dir: /home exists, but is not writeable, owner: root
2018-08-30 17:28:27.665859 DEBUG AppDaemon: Creating worker threads …
2018-08-30 17:28:27.670790 DEBUG AppDaemon: Done
2018-08-30 17:28:27.671333 DEBUG AppDaemon: Entering run()
2018-08-30 17:28:27.672287 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-08-30 17:28:27.719615 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-08-30 17:28:27.720785 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-08-30 17:28:27.721547 DEBUG AppDaemon: Starting utility loop
2018-08-30 17:28:27.722358 INFO Dashboards are disabled
2018-08-30 17:28:27.722820 INFO API is disabled
2018-08-30 17:28:27.723219 DEBUG Start Loop
2018-08-30 17:28:27.726049 DEBUG AppDaemon: Event type:ha_disconnected:
2018-08-30 17:28:27.726605 DEBUG AppDaemon: {}
2018-08-30 17:28:27.727155 WARNING AppDaemon: HASS: Disconnected from Home Assistant, retrying in 5 seconds
2018-08-30 17:28:27.727589 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-08-30 17:28:27.728060 WARNING AppDaemon: HASS: Unexpected error:
2018-08-30 17:28:27.728448 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-08-30 17:28:27.731978 WARNING AppDaemon: HASS: Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/appdaemon/plugins/hass/hassplugin.py”, line 194, in get_updates
“{}/api/websocket”.format(url), sslopt=sslopt
File “/usr/local/lib/python3.5/dist-packages/websocket/_core.py”, line 502, in create_connection
websock.connect(url, **options)
File “/usr/local/lib/python3.5/dist-packages/websocket/_core.py”, line 219, in connect
options.pop(‘socket’, None))
File “/usr/local/lib/python3.5/dist-packages/websocket/_http.py”, line 120, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File “/usr/local/lib/python3.5/dist-packages/websocket/_http.py”, line 190, in _open_socket
raise err
File “/usr/local/lib/python3.5/dist-packages/websocket/_http.py”, line 170, in _open_socket
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

Which version of HA are you using? As of 0.77 a new authentication system is on by default which is not compatible with Appdaemon. So, downgrade or disable the auth system. See below for better answers!

You have to enable API password legacy by adding

http:
  api_password: YOUR_PASSWORD

to your HA configuration. This YOUR_PASSWORD is ha_key in AppDaemon configuration.

2 Likes

besides enabeling the api password there are some more lines needed in the configuration.

homeassistant:
  auth_providers:
   - type: legacy_api_password

downgrading should not be neccesary.

1 Like

I don’t have

auth_providers:
   - type: legacy_api_password

in configuration and api_password works (HA 0.77.1).

hmm, strange. that shouldnt. they have put in that part esspecially for that.
are you sure you have restarted everything (including the device) and have AD up and running and HA 0.77.1?

@ReneTode

Ever since the new HA updates I am trying to run appdaemon by this command sudo appdaemon -c /home/homeassistant/.homeassistant/conf -D DEBUG to check if its working fine. I get the following errors:

2018-08-31 12:07:43.598280 INFO AppDaemon Version 3.0.1 starting
2018-08-31 12:07:43.600309 INFO Configuration read from: /home/homeassistant/.homeassistant/conf/appdaemon.yaml
2018-08-31 12:07:43.601672 DEBUG AppDaemon Section: None
2018-08-31 12:07:43.602833 DEBUG HADashboard Section: None
2018-08-31 12:07:43.613513 INFO AppDaemon: Starting Apps
2018-08-31 12:07:43.624643 DEBUG AppDaemon: Creating worker threads ...
2018-08-31 12:07:43.636071 DEBUG AppDaemon: Done
2018-08-31 12:07:43.638270 DEBUG AppDaemon: Entering run()
2018-08-31 12:07:43.640335 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2018-08-31 12:07:43.705103 INFO AppDaemon: HASS: HASS Plugin Initializing
2018-08-31 12:07:43.707987 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-08-31 12:07:43.709833 DEBUG AppDaemon: Starting utility loop
2018-08-31 12:07:43.711361 INFO Starting Dashboards
2018-08-31 12:07:43.752413 INFO API is disabled
2018-08-31 12:07:43.754252 DEBUG Start Loop
 Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 1044, in create_server
    sock.bind(sa)
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/appdaemon", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/appdaemon/admain.py", line 375, in main
    admain.main()
  File "/usr/local/lib/python3.6/site-packages/appdaemon/admain.py", line 371, in main
    self.run(appdaemon, hadashboard)
  File "/usr/local/lib/python3.6/site-packages/appdaemon/admain.py", line 92, in run
    loop.run_until_complete(asyncio.gather(*pending))
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 1048, in create_server
    % (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 5066): address already in use

@ReneTode so I changed the port for HAdashboard and it worked fine. However if I restart my raspberry pi I get the same error as above.

Why is the port for HAdashboard being replaced by something else?

I think .77 has it built in by default and the auth part is not required anymore…

for clarification, read this post and the next one from baloob.

1 Like

the dashboard is a server and you can chose your own port.
if you have something else running on those ports you get conflicts.

@aidbish ballob did tell Andrew that it needs to be used that way.

@ReneTode there is nothing running on the port chosen for HAdashboard.

Its flaky as I have rebooted my rpi, debugged it and it seems to be connecting fine. Lets see how long it lasts!

Works for me with just:
configuration.yaml:

http:
  api_password: 'pass'

Adding auth_providers breaks things.

do you have a username password combination when you go to HA in a browser?
what do you use hassio, hassbian, anything else?

There’s no prompt for username / password, but I do have an username and a password set (does the browser remember me?).

I use HASS on Raspbian.

Hey all,

I’m guessing plans are to move away from HA requiring the API_password method for Appdaemon and use the new default method of HA??

yeah, thats it. i was misinformed and auth_providers isnt needed.

@robg the plan at this moment is that you get a web frontend for AD where you can do all kind of stuff, and you set the user/password combination for HA there.

WEB frontend for AD, sounds interesting good luck!

1 Like

Don’t need or want a web frontend for AD.

From what I understand, HA is building out authentication tokens (can’t remember the official name). So you can generate one for each application. They would be used in a similar way as the api password, just instead of one, you have many and can revoke them, etc, etc.

AD just needs to support that, when it is ready.

Andrew has spoken with balloob and came to the conclusion that the best and easiest way is to create a frontend where you connect AD with HA.

so AD will support the new authentication in that way.

after you have set the authentication, you dont need to use the frontend if you dont want to.
but it will get more functions, like an easy way to shutdown and restart apps.

If I am running AD in a docker, now I’ll have to open another port in it, just to configure one thing?

If they are creating a way to create long lived access tokens, just let me create on in HA, then I’ll paste it in the config for AD. Then it sends the key over.

I understand some benefits of a UI, but I’d rather not be forced to use one.