AppDaemon / appdaemon

:page_facing_up: Python Apps for Home Automation
Other
847 stars 418 forks source link

Docker Compose Issue #1278

Closed KimHEF closed 1 year ago

KimHEF commented 3 years ago

Hello Everybody,

i have the problem that appdeamon sometimes don't work when i restard my system or after a few days of working. I run both HomeAssistant and Appdeamon in Docker so my thought is to put them together in a Composefile and starting Appdeamon always and after HomeAssistant but i won't work. Home Assistants starts but Appdaemon does not (HASS: Error in authentication). When i start them without Compose just with Docker Run there are no issues... Could anyone see my fault? Or it there another way to solve the problem without restarting appdeamon manually?

docker run --name=appdaemon -d -p 5050:5050 \ --restart=always \ -e HA_URL="http://192.168.0.4:8123" \ -e TOKEN="LongKey" \ -e DASH_URL="http://192.168.0.4:5050" \ -v /home/user/appdaemon/conf:/conf \ appdaemon:latest

Composefile:

version: '3' services: homeassistant: container_name: homeassistant image: homeassistant/raspberrypi4-homeassistant:stable volumes:

Justihar commented 3 years ago

KimHEF, it looks like you're relying on an environment variable to provide the HASS token to AppDaemon in your compose file. If you don't have that environment variable set in your shell environment upon executing then you will indeed have issues with authentication. This will particularly be an issue when your system reboots unexpectedly or docker needs to restart without being in the shell because it'll never be able to get that token. I recommend that you add the token in your appdaemon.yaml or secrets.yaml file and reference it using !secret.

Example:

appdaemon.yaml (just the beginning parts including the HASS plugin)

appdaemon:
  latitude: 10
  longitude: -10
  elevation: 600
  time_zone: America/Los_Angeles
  plugins:
    HASS:
      type: hass
      namespace: default
      ha_url: http://127.0.0.1:8123
      token: !secret hass_token
      cert_verify: false
    MQTT:
      type: mqtt
      namespace: mqtt
      client_host: localhost
      client_user: !secret mqtt_username
      client_password: !secret mqtt_password
      persist_entities: true
      client_topics: NONE

secrets.yaml

hass_token: hassLongLivedTokenGoesHere
KimHEF commented 3 years ago

Yes the Key is in my appdaemon.yaml in the Homeassistant Configfolder without the !secret-yaml.

appdaemon:
  latitude: 0
  longitude: 0
  elevation: 30
  time_zone: Europe/Berlin
  plugins:
    HASS:
      type: hass
      ha_url: http://192.168.0.4:8123
      token: SameToken
http:
  url: http://192.168.0.4:5050
admin:
api:
hadashboard:
Justihar commented 3 years ago

If that is your config file, try removing it from the environment in your compose file and try again. I don't know the expected behavior from the environment variable when you already have it in your configuration file but we have to assume there is the possibility of the environment variable, when specified, taking priority over the config file.

KimHEF commented 3 years ago

Does docker fill the Appdeamon.yaml or does it work the other way around?

Justihar commented 3 years ago

It appears that dockerStart.sh will overwrite the settings in appdaemon.yaml with your environment variables.

KimHEF commented 3 years ago

So i tried that. I deleted the Key from the appdaemon.yaml and it has been filled automatically with the Key from Docker but the same issue: WARNING HASS: Error in authentication WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds

Justihar commented 3 years ago

I suggest the other way around, remove the args for the keys in environment variables but keep it in appdaemon.yaml.

KimHEF commented 3 years ago

Oh damn i found the Problem... i missed the last letter from the token while Copy&Paste. Now it is runnig with compose. Hope it will fix the restart problems. Thank you and shame on me.

KimHEF commented 3 years ago

Hmm it won't work after a reboot i had to restart the appdeamon container manually.