Appdaemon 2.0.8 acockburn/appdaemon image

Dear Community,

I am really hoping someone might be able to save what hair I have left after spending too many hours on this now without resolution.

I’m running Docker on a Synology and have HASS working absolutely fine but do you think I can get the latest appdaemon docker image connected to it? You thought right, no :frowning:

Would be realllllllyyyyy grateful if someone might be able to shed some light on this as I’m beginning to think it might be a bug or problem with the latest python response util module?

My appdaemon.yaml looks like this:

AppDaemon:
  logfile: STDOUT
  errorfile: STDERR
  threads: 10

HASS:
  ha_url: http://192.168.redacted:8123
  ha_key: 111111

HADashboard:
  dash_url: http://192.168.redacted:5050

#Apps
hello_world:
  module: hello
  class: HelloWorld

The following docker command is being used to create the container and I’ve tried many variants, both with and without the environment variables too. The strange thing is if I use the env variables they appear twice in the Synology Docker GUI. I’m currently leaving them out because all this information should be picked up from the configuration file, correct?

sudo docker run --name=appdaemon -d -p 5050:5050 \
  --restart=always \
  -e HA_URL="http://192.168.redacted:8123" \
  -e HA_KEY="111111" \
  -e DASH_URL="http://192.168.redacted:5050" \
  -v /volume1/docker/appdaemon:/conf \
  acockburn/appdaemon:latest

The container is created and runs but no matter what I do, it will not connect to the HASS instance, running in a separate Docker container. I’ve even tried removing the api_key and simplifying the HASS configuration but nothing seems to work.

If I use the EXTRA_CMD="-D DEBUG" variable this is the only thing that’s got slightly close to hinting at the problem but still does not make much sense to me but hopefully someone here maybe able to decipher better than me?

WARNING Unable to connect to Home Assistant, retrying in 5 seconds

2017-08-08 12:18:21.894482 WARNING ------------------------------------------------------------                                                            
2017-08-08 12:18:21.894666 WARNING Unexpected error:                                                                                                       
2017-08-08 12:18:21.895332 WARNING ------------------------------------------------------------                                                            
                                                                                                                                                           
2017-08-08 12:18:21.900090 WARNING Traceback (most recent call last):                                                                                      
  File "/usr/local/lib/python3.6/site-packages/requests/utils.py", line 868, in check_header_validity                                                      
    if not pat.match(value):                                                                                                                               
TypeError: expected string or bytes-like object                                                                                                            
                                                                                                                                                           
During handling of the above exception, another exception occurred:                                                                                        
                                                                                                                                                           
Traceback (most recent call last):                                                                                                                         
  File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1727, in main                                                                 
    ha_config = ha.get_ha_config()                                                                                                                         
  File "/usr/local/lib/python3.6/site-packages/appdaemon/homeassistant.py", line 233, in get_ha_config                                                     
    r = requests.get(apiurl, headers=headers, verify=conf.certpath)                                                                                        
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 72, in get                                                                           
    return request('get', url, params=params, **kwargs)                                                                                                    
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 58, in request                                                                       
    return session.request(method=method, url=url, **kwargs)                                                                                               
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 494, in request                                                                 
    prep = self.prepare_request(req)                                                                                                                       
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 437, in prepare_request                                                         
    hooks=merge_hooks(request.hooks, self.hooks),                                                                                                          
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 306, in prepare                                                                   
    self.prepare_headers(headers)                                                                                                                          
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 440, in prepare_headers                                                           
    check_header_validity(header)                                                                                                                          
  File "/usr/local/lib/python3.6/site-packages/requests/utils.py", line 872, in check_header_validity                                                      
    "not %s" % (value, type(value)))                                                                                                                       
requests.exceptions.InvalidHeader: Header value 111111 must be of type str or bytes, not <class 'int'>                                                     
2017-08-08 12:18:21.900506 WARNING ------------------------------------------------------------

Interestingly where it states near the bottom “Header value 111111” (i’ve changed the number for security) but that’s the ha_key value??? I’ve tried to validate the appdaemon.yaml file and added single quotes around any string data that contains special characters and tried without, and even used an online validator which validated it fine. I’ve then tried the old INI format but when you look in the docker log it doesn’t look like it ever attempts to look for the old style config any more. I’ve exhausted all the possibilities I think could be preventing this from working and now would really appreciate any help somebody can offer. I’m pretty clued up (obviously not enough) so I’m amazed that other’s presumably have this all working fine?

Thank’s if you’ve read this far. Standing on tool stool…Help?

Not something I have seen before - presumably you can connect to your HASS instance OK?

I just pushed a new version of AppDamon, the dicker build should be up by now, but thise errors don;t seem to be happening in my code so I don;t have high hopes that the new version will behave any differently.

Hi Andrew,

Thanks very much for the prompt reply, it’s very much appreciated and might just save me from a wig :wink:

I’ll give it a try and report back.

Are you or do you know if anyone else is using AppDaemon with Docker on a Synology?

Are there any further diagnostic steps you would recommend or could be taken to try and narrow the problem down.

Due to a problem with this website, this message was not posted and I can now confirm, that updating to your latest “latest” tagged release has not (as you suspected) made any difference.

With the ha_url, ha_key and dash_url, do you specify the environmental variables or just leave it to pickup the ones read from the configuration file, which is what I assume. Do you enclose this data in single or double quotes? I have tries all variations and it doesn’t seem to make a difference but the DEBUG information almost suggests the ha_key is being picked up as an integer, instead of a string.

I can connect to the HASS instance fine outside of docker both locally and publicly. If I use:
url -X GET -H "x-ha-access: <api pwd here>" -H "Content-Type: application/json" http://192.168.redacted:8123/api/config
from a new terminal session within the appdaemon docker image it also returns the data fine.

Is there any way the DEBUG could print the data that it’s reading from the configuration/environment variables before it says “Unexpected error”, so that we can verify the string it’s trying to use to connect to HASS and the key, etc?

It’s frustrating as I’m moving from the otherwise excellent RPI3 environment but I’ve become fed up with eventually succumbing to SD Card corruptions, hence using the Syno device.

I look forward to hearing from you when you get time.

If your key is numeric that could be the case - if so, surrounding it with single quotes might help.

I am new to docker, so this may be completely wrong, but I notice that you are not using the net=host in your docker command, but using external address numbers. I think that without that, docker sets up the image to use its own internal network, which wouldn’t be much good for MQTT.

Hi and thanks for your messages.

The key is numeric and I’ve tried enclosing these values in single quotes and then later in double quotes instead. I’ve also enclosed the URL’s in single quotes, assuming the colon in the url may cause problems with the yaml. Still, there is no difference and the file currently has all three values enclosed in single quotes and is stating “…unable to connect, will retry in 5 seconds…”.

As for the net=host this, by default, should not make any difference to the outgoing connection and the -p 5050:5050 maps the ports to expose the dashboard interface to the bridged network. Having said this I have tried using the host network stack (as it doesn’t clash with any host ports) just to exhaust all possibilities but out of the numerous changes I’ve tried nothing seems to have helped.

I think the problem is potentially related to the yaml format and the python response module so would be keen to know whether there is anyway of using the older INI style format with the latest 2.0.8 appdaemon release. My testing seemed to suggest the .cfg file was being ignored, even if I remove the .yaml file. Is there a way to force this, just for testing as I know the yaml is the best way forward, although still am not totally convinced in general that this is the best format for automation systems, when it’s so picky about layout.

I would welcome comments from anyone that might be using Docker on the Synology with appdaemon? Ideally, if people are using it successfully, could an example config with docker run commands be given and the image source/version?

There are sample commands in the DOCKER_TUTORIAL.md file here.

Regarding Synology users - I’m not sure but there have been over 10K pulls from the hub so I am guessing someone somewhere is …

Thanks Andy, I’ve already used your helpful page but without success.

I started out using the built-in Synology Docker GUI but quickly switched to the CLI interface, which obviously has a lot more control. Unfortunately, this hasn’t helped.

I guess I’ll have to keep my fingers crossed that another Synology/Docker user will read this, that has a working system and would be kind enough to send their working config.

Is there any chance the code could be updated to include the config information it’s reading (or at least the HASS connection parameters) in the DEBUG level logs?

:crossed_fingers: :crossed_fingers:

Sure - I am adding it now and there will be a new release with a couple of other requests in a few minutes :slight_smile:

That would be great. Thank you.

OK, 2.1.2 is uploaded an building, it has a lot more debug info in it. Be careful though as the debig statements include sensitive info such as passwords and defeat any “!secret” processing you might be using.

Give it a few minutes to build and lets see what we can learn :slight_smile:

Thanks Andy, that’s great.

Once I’m back in the office later I’ll test and let you know.

1 Like

Well it looks like all the information is being picked up successfully. I can’t help but feel this is either going to be a silly overlooked configuration error or hopefully just a bug that can be resolved.

To preserve formatting I thought it best to use an image.

put quotes around your key?

Thanks, I’ve tried both single and double (not at the same time!)

Do you by chance have a working Synology/Docker/Appdaemon setup?

I do have appdaemon working but not on docker… I wonder if you change your key to not be an int if it would work. Have you tried a key with letters?

Sorry for the delay, this website keeps returning 502 errors and preventing a reply.

I haven’t but did, early on, try removing the key all together from AD and HA…Ahhhh

OK. Your comments made me realise what might have been overlooked. I was focusing on using the ENV variables to specify the HA_ parameters and I removed the HA_KEY all together and removed the api_password from HA but must have left the ha_key in the AD yaml file. I’ve just tried removing it from everywhere (as should have originally been the case) and it worked! I’ve then put it all back and now prefixed the key with a letter and again, it all works.

Thank you azeroth12 and Andrew for getting to the bottom of the problem. I’ve got so many things going on at the moment, this shouldn’t have been overlooked but hopefully this will prove useful for someone else out there and may help remove a bug of not supporting an all numeric key.

2 Likes

For future reference
tl;dr

http://docs.python-requests.org/en/master/user/quickstart/#custom-headers

https://github.com/requests/requests/issues/3477

any chance you might be running VPN on your synology box ?

There is an issue with VPN if you are.

if so turn it off, once you have appdaemon running you can turn VPN back on

check out this post here https://philhawthorne.com/installing-home-assistant-io-on-a-synology-diskstation-nas/

that is right…adding the single quotes can resolve it.