App won't run

Okay, so if you go through my post history, you’ll see I’ve had a few Appdaemon issues when using Appdaemon with Hass.io. Then I solved the problem, but got stuck at a limitation of Hass.io.

So I started from scratch with Raspian, installed Home Assistant in a venv as per this. Got that all working. Installed Appdaemon in a separate venv as per this video.

Firstly, the systemd service file:
…/…/etc/systemd/system/appdaemon.service

[Unit]
Description=Appdaemon for Hass
After=network.target

[Service]
Type=simple
User=pi
ExecStart=/home/pi/appdaemon/bin/appdaemon -D DEBUG -c "/home/pi/appdaemon/conf"

[Install]
WantedBy=multi-user.target

appdaemon.yaml
home/pi/appdaemon/conf/appdaemon.yaml

log:
  logfile: /home/pi/appdaemon/conf/appdaemon.log
  errorfile: /home/pi/appdaemon/conf/aderror.log

appdaemon:
  threads: 10
  app_dir: /home/pi/appdaemon/conf/apps
  plugins:
    HASS: 
      type: hass
      ha_url: http://XXXXX:8123
      token: <blah blah blah blah>

hasdashboard:
  dash_url: http://XXXXX:5050
  dash_dir: /home/pi/appdaemon/conf/dashboards

apps.yaml
home/pi/appdaemon/conf/apps/apps.yaml

testapp:
    module: test
    class: FirstApp

test.py
home/pi/appdaemon/conf/apps/test.py

import appdaemon.plugins.hass.hassapi as hass

class FirstApp(hass.Hass):
        def initialize(self):
                self.log("Test app initialized")
                self.listen_state(self.run, "input_boolean.run_test_app")

        def run(self, entity, attribute, old, new, kwargs):
                self.log("Test app starting")
                self.turn_on("light.dining_room")
                self.log("Test app run")

And I uploaded the appdaemon.log file here because I couldn’t paste it or upload it here.
To generate this log, I removed the log file, stopped the appdaemon process and rebooted the Pi.

I just do not think the app is actually running? I’m not seeing any of my self.log printouts? (These should be in appdaemon.log right?) and the light is definitely not turning on…

What am I doing wrong?

Actually, this is occurring in the log:

2018-11-11 09:50:09.409349 DEBUG AppDaemon: {'domain': 'light', 'service': 'turn_off', 'service_data': {'entity_id': 'light.dining_room'}, 'service_call_id': '3008ae082e1c40aeb946a09445c09e5d'}
2018-11-11 09:50:09.451134 DEBUG AppDaemon: Event type:service_executed:
2018-11-11 09:50:09.452702 DEBUG AppDaemon: {'service_call_id': '3008ae082e1c40aeb946a09445c09e5d'}
2018-11-11 09:50:09.859136 DEBUG AppDaemon: Event type:state_changed:

But the light is not changing, and it is named correctly.

I have been seeing a warning that LIFX is not working with the light entity now, so could that be the problem?

Is there anything in the error log?

No. There wasn’t.

It’s now working. I have no idea what I did to make it work.

1 Like

in the log you showed AD didnt connect to HA at first (could be that HA wasnt ready with starting)

2018-11-11 09:16:05.836005 WARNING AppDaemon: HASS: Disconnected from Home Assistant, retrying in 5 seconds
2018-11-11 09:16:05.837077 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-11-11 09:16:05.838313 WARNING AppDaemon: HASS: Unexpected error:
2018-11-11 09:16:05.839417 WARNING AppDaemon: HASS: ------------------------------------------------------------
2018-11-11 09:16:05.854489 WARNING AppDaemon: HASS: Traceback (most recent call last):
  File "/home/pi/appdaemon/lib/python3.5/site-packages/appdaemon/plugins/hass/hassplugin.py", line 152, in get_updates
    "{}/api/websocket".format(url), sslopt=sslopt
  File "/home/pi/appdaemon/lib/python3.5/site-packages/websocket/_core.py", line 511, in create_connection
    websock.connect(url, **options)
  File "/home/pi/appdaemon/lib/python3.5/site-packages/websocket/_core.py", line 220, in connect
    options.pop('socket', None))
  File "/home/pi/appdaemon/lib/python3.5/site-packages/websocket/_http.py", line 120, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  File "/home/pi/appdaemon/lib/python3.5/site-packages/websocket/_http.py", line 190, in _open_socket
    raise err
  File "/home/pi/appdaemon/lib/python3.5/site-packages/websocket/_http.py", line 170, in _open_socket
    sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

you had AD running in debug mode.
i think you restarted AD, HA was up and running at that point so your problem was gone.

No, that wasn’t it. I definitely tested that thoroughly to make sure it was connected to HA.

I reloaded the daemon a few times after the minor changes, restarted services, rebooted the Pi, etc. I also rewrote the Python app in IDLE on my local PC and SCPd it to the Pi, I was concerning about the tabbing/whitespace.

I think any combination of that would is probably what fixed the problem.

Now I’m having trouble importing RPi.GPIO in Appdaemon. I installed in using pip3, but I’m getting the No module named RPi error.

Any insight into how to install RPi.GPIO in my setup?

first make sure that you are inside the appdaemon venv.
then install with pip3 install

you should be able to find your libs inside the venv dir

but it should actually be installed on default with raspbian.

When you say inside the venv, is it just inside the directory?

So:

pi@raspberrypi:~/appdaemon $ pip3 install RPi.GPIO

Still errors

GOTCHA

source appdaemon/bin/activate
pip3 install RPi.GPIO

Thanks for your help.

dont forget to activate and deactivate the right venv everytime you want to install something inside it.
the commands wont throw an error, because you still got your default python environment.
so it just installs in there :wink: