How to connect appdeamon when using network_mode host in docker-compose?

Hi,

I am trying to add appdaemon to my existing HA setup that is started/stopped by docker-compose.

Here is the docker-compose.yaml I am trying to get to work:

version: "2"
services:
  home-assistant:
          #image: homeassistant/home-assistant:0.99.3    
    image: homeassistant/home-assistant:0.104.2    
    container_name: homeassistant
    environment:
            - TZ=Europe/Berlin
    volumes:
            - ${HA}:/config
    restart: unless-stopped 
    network_mode: host
  appdaemon:
    container_name: appdaemon
    image: appdaemon:latest
    environment:
        - HA_URL="http://127.0.0.1:8123"
        - HA_KEY="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJkMmQzZjU3NTA0ZWI0YTE0YWVhM2VlMzIyOTgzYjIyYSIsImlhdCI6MTU3OTQ0MzU0MywiZXhwIjoxODk0ODAzNTQzfQ.2Gbcl2j-X_UBGGr7-7St9ghHqaS3FIUn0Hw_SGuKZbe"
    ports:
        - 5050:5050
    volumes:
        - ${AD}/config:/conf
    depends_on:
        - home-assistant
    network_mode: host
    restart: on-failure:15
networks:
  default:
    external:
      name: nginx-net

I have removed a nodered and an mqtt container from the file so that it is easier to read, let me know if I should readd them.

The containers share a network with an nginx-container (started in another compose file) that takes care of ssl-redirection for me.

Now to the problem: Every time I start the container appdaemon exits with

appdaemon         | 2020-01-20 22:21:18.703417 INFO AppDaemon: AppDaemon Version 4.0.1 starting
appdaemon         | 2020-01-20 22:21:18.703886 INFO AppDaemon: Python version is 3.8.1
appdaemon         | 2020-01-20 22:21:18.704449 INFO AppDaemon: Configuration read from: /conf/appdaemon.yaml
appdaemon         | 2020-01-20 22:21:18.705246 INFO AppDaemon: Added log: AppDaemon
appdaemon         | 2020-01-20 22:21:18.705752 INFO AppDaemon: Added log: Error
appdaemon         | 2020-01-20 22:21:18.706200 INFO AppDaemon: Added log: Access
appdaemon         | 2020-01-20 22:21:18.706978 INFO AppDaemon: Added log: Diag
appdaemon         | 2020-01-20 22:21:18.707517 ERROR AppDaemon: time_zone not specified in appdaemon.cfg
appdaemon         | 2020-01-20 22:21:18.708047 ERROR AppDaemon: latitude not specified in appdaemon.cfg
appdaemon         | 2020-01-20 22:21:18.708551 ERROR AppDaemon: longitude not specified in appdaemon.cfg
appdaemon         | 2020-01-20 22:21:18.709395 ERROR AppDaemon: elevation not specified in appdaemon.cfg

Which I think means it can’t connect to home assistant. I checked the token 5 times (using curl), it is absolutely correct.

How can I make appdaemon connect to HA? I tried changing HA_URL to 127.0.0.1, localhost and the actual IP address of the raspberry pi I am running this on.

Here is my appdaemon.yaml:

appdaemon:
  plugins:
    HASS:
      type: hass
      ha_url: "http://127.0.0.1:8123"
      token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJkMmQzZjU3NTA0ZWI0YTE0YWVhM2VlMzIyOTgzYjIyYSIsImlhdCI6MTU3OTQ0MzU0MywiZXhwIjoxODk0ODAzNTQzfQ.2Gbcl2j-X_UBGGr7-7St9ghHqaS3FIUn0Hw_SGuKZbe
http:
  url: http://raspberrypi:5050
admin:
api:
hadashboard:

I don’t know whether it’s important, as far as I understood the environment variables take precedence.

Any help is appreaciated! Thanks!

I dont see any error regarding access

All the things its complains about are required in 4.0

timezone
Longitude
Latitude
Elevation

I hard-coded them (except for time zone) in my configuration.yaml

homeassistant:                                                  
  # Name of the location where Home Assistant is running
  name: My Home Assi                                            
  # Location required to calculate the time the sun rises and sets
  latitude: 52.652950                                           
  longitude: 12.569330
  # Impacts weather/sunrise data (altitude above sea level in meters)                                                         
  elevation: 1.0

If I understand the appdaemon docs right then it should get the data from HA. Since it doesn’t I assumed it couldn’t connect to HA. Any ideas what I am doing wrong?

Yes. You need to put them in appdaemon.yaml . appdaemon doesnt use or read the config in HA. Those setting are for HA.

I was sure the docs said that appdaemon gets those values from home assistant… But I can’t find that line anymore. Weird. And embarrassing for me.

Thanks for the help, I will put those settings into appdaemon.yaml

Use too before v4