Appdaemon - new at it No Idea whats happening

Hi,

I’ve installed appdaemon via the hassbian config installation and I have figured out as far as getting hadashboard and the hello world.py running, but I can’t for the life of my figure out how to get it to do stuff in HA. I’ve been tinkering with this now for about 5 days and was actually starting to think I should just try node red install but I must be missing something.

Ok here my appdaemon.yaml:

log:
accessfile: /home/homeassistant/appdaemon/logs/access.log
errorfile: /home/homeassistant/appdaemon/logs/error.log
logfile: /home/homeassistant/appdaemon/logs/appdaemon.log
log_generations: 2
log_size: 1024
appdaemon:
threads: 10
plugins:
HASS:
type: hass
ha_url: !secret home_asst_url
ha_key: !secret home_asst_key
hadashboard:
dash_url: http://192.168.1.49:5050
dashboard_dir: /home/homeassistant/appdaemon/dashboards

apps.yaml:

hello_world:
module: hello
class: HelloWorld

alarm_set:
module: alarmset
class: AlarmSet

test_app:
module: test
class: NightLight

All the logs and everything generate…I can see the Hello World:

2018-04-14 00:50:59.290451 INFO AppDaemon: Reloading Module: /home/homeassistant/appdaemon/apps/hello.py
2018-04-14 00:50:59.300016 INFO AppDaemon: Initializing app hello_world using class HelloWorld from module hello
2018-04-14 00:50:59.309142 INFO hello_world: Hello from test AppDaemon
2018-04-14 00:50:59.316694 INFO hello_world: You are now ready to run Apps!

But when I try to run this app but on this example https://github.com/ReneTode/My-AppDaemon/blob/master/AppDaemon_for_Beginner/Part_1(listen_state_and_get_state).md
, nothing happens:

import appdaemon.plugins.hass.hassapi as hass

class NightLight(hass.Hass):

  def initialize(self):
    self.listen_state(self.turn_on_boolean,"input_boolean.test1", new="on")
	self.log("test1")
  def self.turn_on_boolean (self, entity, attribute, old, new, kwargs):
    boolean_test = self.get_state("input_boolean.test2")
	if boolean_test == "on":
	   self.log("it's on")
	   self.turn_on("input_boolean.test3")
	   self.log("test3")

I have 3 input booleans in HA
I have test2 on and I am toggling test1

|input_boolean.test1|on|friendly_name: test1|
|input_boolean.test2|on|friendly_name: test2|
|input_boolean.test3|off|friendly_name: test3|

2018-04-14 00:58:00.161769 INFO AppDaemon: Terminating test_app
2018-04-14 00:58:00.162544 INFO AppDaemon: Reloading Module: /home/homeassistant/appdaemon/apps/test.py
2018-04-14 00:58:00.163151 INFO AppDaemon: Loading App Module: test
2018-04-14 00:58:00.170765 WARNING AppDaemon: Removing associated apps:
2018-04-14 00:58:00.171475 WARNING AppDaemon: test_app

grrrrrrr - note it’s 1:03 am

Indentation is important in Python, just as in yaml, and your app has some extra indentation that you need to remove.

import appdaemon.plugins.hass.hassapi as hass

class NightLight(hass.Hass):

  def initialize(self):
        self.listen_state(self.turn_on_boolean,"input_boolean.test1", new="on")
	self.log("test1")
  def self.turn_on_boolean (self, entity, attribute, old, new, kwargs):
        boolean_test = self.get_state("input_boolean.test2")
	if boolean_test == "on":
	   self.log("it's on")
	   self.turn_on("input_boolean.test3")
	   self.log("test3")

There may be more wrong I can’t see by eye, but that should get you started.

No Luck, still did nothing…le sigh!

Can you post your appdaemon.yaml and apps.yaml files again using the formatting button ( </> ) so that we can see the indentation of those files?

This is a problem:

Sure, see below:

appdaemon.yaml

log:
  accessfile: /home/homeassistant/appdaemon/logs/access.log
  errorfile: /home/homeassistant/appdaemon/logs/error.log
  logfile: /home/homeassistant/appdaemon/logs/appdaemon.log
  log_generations: 2
  log_size: 1024
appdaemon:
  threads: 10
  plugins:
    HASS:
      type: hass
      ha_url: !secret home_asst_url
      ha_key: !secret home_asst_key
hadashboard:
  dash_url: http://192.168.1.49:5050
  dashboard_dir: /home/homeassistant/appdaemon/dashboards

apps.yaml


hello_world:
  module: hello
  class: HelloWorld

alarm_set:
  module: alarmset
  class: AlarmSet

test_app:
  module: test
  class: NightLight

Do you have an app called “test.py” in your apps directory?

yes thats were the code with the test boolen is…in test.py

thats wrong syntax.

You should brush up on python, specifically object orientation. The method you created above should be this:

  def turn_on_boolean(self, entity, attribute, old, new, kwargs):
      boolean_test = self.get_state("input_boolean.test2")
      if boolean_test == "on":
          self.log("it's on")
          self.turn_on("input_boolean.test3")
          self.log("test3")

I also noticed that you are mixing spaces and tabs. This is a NO-NO with python. If you are using a text editor, use a setting called ‘replace tab with spaces’.

Python is a white-space oriented language and not all white space is equal. So to be safe, always use tabs or always use spaces. DO NOT MIX.

EDIT: I Quoted the wrong person, should be a quote/reply to @Sublime_chaos

Hi, Still no luck, I have no idea what’s wrong…I actually thought that I botched the installation and actually started with a new image and reinstalled home assistant and got back to a point when I set up appdaemon but still the same results…it’s actually a bit frustrating because I cannot find in any documentation, forums, videos what’s supposed to be happening when so I cannot troubleshoot different points…it does seem to be communicating with home assistant:

2018-04-18 19:10:26.082555 INFO AppDaemon: HASS: Connected to Home Assistant 0.67.0
2018-04-18 19:10:26.194333 INFO AppDaemon: Got initial state from namespace default

what’s supposed to happen when the app loads? how would I know that the app is executing properly? what would show as the output??

When the app loads, you will see INFO saying it loaded the name of the file. According to your app.yaml config, it would probably say soemthing like ‘loaded test.py’

Then you know its running. If it doesn’t say that, then your setup is wrong.

Did you do what @eBoon said?

yes, it loads the app fine, just nothing happens in home assistant when I’m toggling the input boolean test switches

Can you tail -f your Appdaemon output log (I think it’s /home/homeassistant/appdaemon/logs/appdaemon.log for you) on a window and then from a different window write your test.py file? You should see Appdaemon respond with something like this in the window that the log is scrolling:

2018-04-19 16:29:19.722677 INFO AppDaemon: Initializing app Garage using class garage from module garage

Except you will see “Initializing app test …”

or… just post the last 20 lines or so from your log file so we can take a look.

2018-04-20 16:40:50.314240 INFO AppDaemon: HASS: HASS Plugin initialization complete
2018-04-20 16:40:50.315935 INFO Starting Dashboards
2018-04-20 16:40:50.338023 INFO API is disabled
2018-04-20 16:40:50.572523 INFO AppDaemon: HASS: Connected to Home Assistant 0.67.1
2018-04-20 16:40:50.670032 INFO AppDaemon: Got initial state from namespace default
2018-04-20 16:40:52.816957 INFO AppDaemon: Reading config
2018-04-20 16:40:52.830827 INFO AppDaemon: /home/homeassistant/.homeassistant/conf/apps/apps.yaml added or modified
2018-04-20 16:40:52.831428 INFO AppDaemon: /home/homeassistant/.homeassistant/conf/apps/apps.yaml added or modified
2018-04-20 16:40:52.831821 INFO AppDaemon: App 'hello_world' added
2018-04-20 16:40:52.832166 INFO AppDaemon: App 'alarm_set' added
2018-04-20 16:40:52.832506 INFO AppDaemon: App 'test_app' added
2018-04-20 16:40:52.833049 INFO AppDaemon: Adding /home/homeassistant/.homeassistant/conf/apps to module import path
2018-04-20 16:40:52.834503 INFO AppDaemon: Loading App Module: /home/homeassistant/.homeassistant/conf/apps/test.py
2018-04-20 16:40:52.858091 INFO AppDaemon: Loading App Module: /home/homeassistant/.homeassistant/conf/apps/hello.py
2018-04-20 16:40:52.859886 INFO AppDaemon: Loading App Module: /home/homeassistant/.homeassistant/conf/apps/alarmset.py
2018-04-20 16:40:52.869769 WARNING AppDaemon: Removing associated apps:
2018-04-20 16:40:52.870272 WARNING AppDaemon: alarm_set
2018-04-20 16:40:52.870844 INFO AppDaemon: Initializing app hello_world using class HelloWorld from module hello
2018-04-20 16:40:53.119889 INFO hello_world: Hello from test AppDaemon
2018-04-20 16:40:53.123266 INFO hello_world: You are now ready to run Apps!
2018-04-20 16:40:53.123755 INFO AppDaemon: Initializing app test_app using class HelloWorld from module test
2018-04-20 16:40:53.127619 INFO test_app: Hello second AppDaemon
2018-04-20 16:40:53.130885 INFO test_app: You are now ready to run Apps!
2018-04-20 16:40:53.132648 INFO AppDaemon: App initialization complete

sorry, i moved the code to alarm_set for testing, I tried a different code in test_app to see how it would respond…just to note, I am doing this in notepad ++ using the samba share to access the .py files, should I be doing this using vi or nano? Also, I’ve installed appdaemon using the “pi” user, should I have installed it in the virtual environment and be running it from there? i’d be okay with teamviewer so you can watch me break stuff and see what i’m doing, if you’re up for that…

This is the problem - I just don’t understand why your app is being removed. No issues using notepad++ through samba or installing pi. AD is working - you can see the the other two apps are working as written. @aimc or @ReneTode ideas?

1 Like

the app is probably removed because off syntax errors inside the app or because there is something wrong in apps .yaml

in the error log there should be errors telling what is wrong.

to start i should do the following:

  1. find the errorlog and clear it.
  2. delete hello world and test_app
  3. change the apps.yaml and leave only the part that points to alarm_set (check if class and module are given right.)
  4. restart appdaemon.
  5. check the error log if there is an error and check if the app is started correct in the appdaemon log
  6. if not post the apps.yaml and the alarm_set.py here (exactly as it is)

if you try to learn things and ask for help, it is important to have a little patience.
dont do other things as what is told you in between (like changing from app) because that will confuse those who are trying to help you.
if you still want to try something, then try it, and if it doesnt work get back to where you were before that, so that you are still at the same level from your helpers.

this should be a working code if the entities are correct:

import appdaemon.plugins.hass.hassapi as hass

class NightLight(hass.Hass):

  def initialize(self):
        self.listen_state(self.turn_on_boolean,"input_boolean.test1", new="on")
        self.log("test1")
  def self.turn_on_boolean (self, entity, attribute, old, new, kwargs):
        boolean_test = self.get_state("input_boolean.test2")
        if boolean_test == "on":
            self.log("it's on")
            self.turn_on("input_boolean.test3")
            self.log("test3")

1 important remark!!
when i copied this code and cleaned it i noticed a combination from TABS and SPACES.
when indenting 1 TAB is not the same as 4 SPACES. but it looks the same.
python will get confused and trow errors.
in the code i posted here i took out all TABS and replaced them with spaces. so copiing this code will probably work, where yours does gives an error.

1 Like

Thanks guys, I actually used an online python code checker and that helped me identify what was wrong with my the code as even the one posed above still didn’t work for me…here’s what finally worked:


import appdaemon.plugins.hass.hassapi as hass


class NightLight(hass.Hass):

    def initialize(self):
        self.listen_state(self.turn_on_boolean, "input_boolean.test1", new="on")
        self.log("input_boolean 1 is now on")

    def turn_on_boolean(self, entity, attribute, old, new, kwargs):
        boolean_test_on = self.get_state("input_boolean.test2")
        if boolean_test_on == "on":
            self.log("input_boolean 2 is on")
            self.turn_on("input_boolean.test3")
            self.log("input_boolean 3 is on")

I had to move the “self” from the front of the turn_on_boolean, move some spaces and create some whitespace as well (as spaces and not tabs, which the checker tells you).
I’m not sure if I can post the link of the online checker I used but it’s pretty much the first one that came up in a google search…I do thank you guys for all the help and support…i actually set up nodered and got that working so I was = <- this close to using it…

1 Like

lol i didnt even notce that extra self.
you can give a link to the python checker for others to use if you like.

at least you learned a lot :wink:

@petro did tip about the wrong syntax 16 days ago :wink:

2 Likes