AppDaemon Q&A

I am having issue of not getting called my state listener everytime, looks like it works for few times initially and then never gets called. Below is the details
.

  1. I have AppDaemon running on Windows 10 under Bash shell
  2. My HA is running on same network but on different computer which is running latest Ubuntu.
  3. What issue I am noticing is the status change for HA entity are not reflected here in my app which has listener set to receive the status updates.
    a. It does call my callback for initial few times when status gets updated and then stops and no other status changes causes to call my callback.
    b. There is no error in log (console)
    c. I have added logging to prove my callback got called as well it sends PushBullet notification, and I don’t see any log or PushBullet notification.
    d. My HA runs securely and I have ha_url set to use https but I have not provider cert_path in config file as you see in the code
    e. I have automation trigger set in HA which occurs and sends me PushBullet notification which proves there was change in status but not from my AppDaemon app
    f. I have set many listeners on different entities and none of them works after few times
    g. While development I was just keep saving the python app file and AppDeamon was keep loading to get latest changes and I thought dynamic loading may be an issue and I tried stopping the AppDaemon and running again still same issue.
    h. I have most of the sensor where I have listener set are templated sensor, what I mean is I have some kind of device which gives sensor data but that sensor has attributes that I want to monitor so I have set template sensor to pull that specific attribute and that works great in HA to trigger automation.
  4. I have another app which is purely time based (every two hours) which calls my callback without any fail and works flawlessly.
  5. I have attached config and app file to review the code if I missed anything.

Config file:

[AppDaemon]
ha_url = https://myha.duckdns.org
ha_key = ******
logfile = STDOUT
errorfile = STDERR
app_dir = conf/apps
threads = 10
latitude = xxxxx
longitude = -xxxxx
elevation = xxxx
time_zone = America/Chicago

# Apps
[TestPushBullet]
module = test_pushbullet
class = TestPushBullet

[EcobeeAutomation]
module = ecobee_automation
class = EcobeeAutomation

App code:

import appdaemon.appapi as appapi
import datetime

class EcobeeAutomation(appapi.AppDaemon):

  def initialize(self):
    self.log("Starting EcobeeAutomation App")
    self.listen_state(self.cb_dn_status, "sensor.thermostat_downstairs_current_status")
    self.listen_state(self.cb_dn_fan, "sensor.thermostat_downstairs_current_status_fan")
    self.listen_state(self.cb_dn_away, "sensor.thermostat_downstairs_away_mode")
    self.listen_state(self.cb_dn_temp, "sensor.thermostat_downstairs_set_temp_ac")

  def cb_dn_status(self, entity, attribute, old, new, kwargs):
    msgStr = "cb_dn_status: old=" + old + ", new=" + new + " at " + datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
    self.log(msgStr)
    self.call_service("notify/pushbullet", title = "AppDaemon", message = msgStr, target = "channel/somechannel")

  def cb_dn_fan(self, entity, attribute, old, new, kwargs):
    msgStr = "cb_dn_fan: old=" + old + ", new=" + new + " at " + datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
    self.log(msgStr)
    self.call_service("notify/pushbullet", title = "AppDaemon", message = msgStr, target = "channel/somechannel")

  def cb_dn_away(self, entity, attribute, old, new, kwargs):
    msgStr = "cb_dn_away: old=" + old + ", new=" + new + " at " + datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
    self.log(msgStr)
    self.call_service("notify/pushbullet", title = "AppDaemon", message = msgStr, target = "channel/somechannel")

  def cb_dn_temp(self, entity, attribute, old, new, kwargs):
    msgStr = "cb_dn_temp: old=" + old + ", new=" + new + " at " + datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]
    self.log(msgStr)
    self.call_service("notify/pushbullet", title = "AppDaemon", message = msgStr, target = "channel/somechannel")

Home Assistant sensor definition

  - platform: template
    sensors:
      thermostat_downstairs_current_status:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.operation }}{% else %}??{% endif %}'
      thermostat_downstairs_current_status_fan:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.fan }}{% else %}??{% endif %}'
      thermostat_downstairs_away_mode:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.away_mode }}{% else %}??{% endif %}'
      thermostat_downstairs_hvac_mode:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.operation_mode }}{% else %}??{% endif %}'
      thermostat_downstairs_set_temp_ac:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.target_temp_high }}{% else %}??{% endif %}'
      thermostat_downstairs_set_temp_heat:
        value_template: '{% if states.climate.downstairs %}{{ states.climate.downstairs.attributes.target_temp_low }}{% else %}??{% endif %}'

it didnt even come up to me that it is possible to use appdaemon on another computer.

can you tell me why you chose to install it on another computer?

without appdaemon my HA only functions partly, so the 2 are 2 part from 1 working programm in my eyes.
i wouldnt want that to be dependent on 2 computers functioning.

My guess would be thread exhaustion from the pshbullet call not returning. Can you add a line to log a message after the pushbullet call in each callback and let me know if you see it? If my theory is correct, after each thread is used up, you have 10, the requests will start queuing up waiting for a free thread.eventually you should start getting log messages about thread starvation.

First thing first. Thanks a lot for the suggestion/question.
Here is my answer. I was trying to minimize the impact on production computer of Home Assistant as I wanted to explore the options. Once proven what I wanted to do I will move it to the same box. As I am not using python virtual environment on my HA computer and I already experienced the issue of from home user to root user force move due to system updates changing python/folders.
I can definitely try installing AppDaemon to HA computer and see. I think (being positive) it will work as I have noticed another AppDaemon app works which has only time based callback. Which kind of hints there may be network interruption causing the connection between HA and AppDaemon getting closed? Not sure though this is my theory. May be Andrew can tell more on this as it has active connection to HA server or not?
Let me try to move AppDaemon to same computer and see the results, I will come back and post the finding so it can help everyone here.
Thanks again

Has it been determined why the Appdaemon is not starting properly via init.d? I am also seeing this behavior when I tried using init.d. Runs properly if I start it manually.

Thanks a lot for the reply, I appreciate it.
As you suggested I will add a debug line to see if it is using all threads and new updates just gets queued up and not getting delivered. But in this case it should get delivered once thread(s) becomes available. I will try this and report back to share the results. As far as I know Push Bullet is very reliable and in case of any issue it throws error without locking the tread/app.
As ReneTode mentioned in his reply about multiple computers involvement, I will try to move AppDaemon to same computer to remove all other parameters which can potentially cause such/other issues.
Thanks one more time for your help and time and also for this wonderful app.

Hi Andrew, did you have a chance to look into the autostart issue of AppDaemon on the RPI AIO ?

Not yet sorry, have been traveling on business and am on vacation this week.

Hi

I can’t auto start AppDaemon.

Copied over the appdaemon.service file to etc/systemd/system and it still not starting.

Also modified the appdaemon.service file so it know where the appdaemon.cfg is.

#
# Sample unit file for systemd
#
# Edit top suit your environment, then copy to /etc/systemd/system
#
# run "systemd enable appdaemon" to make it start at boottime
#
[Unit]
Description=AppDaemon service for Home Assistant

[Service]
#ExecStart=/usr/local/bin/appdaemon
#
# If you are not using a default path for the config file use this:
#
ExecStart=/usr/local/bin/appdaemon -c /home/pi/appdaemon/conf/appdaemon.cfg
#
[Install]
WantedBy=multi-user.target

When i run-

pi@RPI3:~ $ cd appdaemon/conf
pi@RPI3:~/appdaemon/conf $ appdaemon -c appdaemon.cfg

It start fine. Any help please.

Did you enable the service?

$ systemd enable appdaemon

@mchrisb03 @Tyfoon

I took a look at the restart issue today and I figured out what was going on I think.

I am just about to push version 1.3.6 which should fix the issue - let me know!

Hi Andrew
Thanks for the help but i upgraded to version 1.3.6 and it WORKED.

I tried systemd enable appdaemon but it came back as Excess arguments.

root@RPI3:/etc/systemd/system# systemd enable appdaemon
Excess arguments.

Done a reboot and lots of errors in the appdaemon.log
appdaemon.yaml (28.9 KB)
Had to save as YAML ext to upload to this forum. Hope this helps.

Cameron

Sounds good. How do I update AppDaemon to the latest version? Did some searching but could not find it.

Not sure about the excess arguments as nothing has changed there - but the errors in the log are expected behavior. This is simply because AppDaemon is starting up more quickly than HA and con;t connect to it. Previously, this caused an error and AppDaemon stopped, which is why you never saw it load the programs etc. I could suppress those errors but they are useful for tracking down othewr issues for example if you had an invalid URL, or some other problem, I am trying to strike a balance between keeping the logs clean and giving enough info for debugging.

It’s in the README:

EDIT - I see they have a mistake - do the following:

Updating AppDaemon

To update AppDaemon after I have released new code, just run the following command to update your copy:

$ git pull origin

If you are using pip3 for the install do this:

$ sudo pip3 uninstall appdaemon
$ sudo pip3 install .

If you are using docker, rerun the steps to create a new docker image.

Ok thanks for your help i may need some more in the future.

1 Like

You must think I’m a complete fool but…

$ git pull origin indeed seems to update. But when I then run sudo pip3 uninstall appdaemon I get below (either from the appdaemon dir or one below)

Sudo pip3 Install gives a similar type of respnse

This is not anything to do with AppDaemon, it seems to be a version mismatch between the requests library and pip3. A quick Google found this thread that may help you to resolve the issue.

I’m not running anything else on my PI but an AIO installer of HASS (still on 28.2 but upgrade according to instructions here: https://home-assistant.io/getting-started/installation-raspberry-pi-all-in-one/ ).

Also never installed anything else but AppDaemon on top of this (this based on the instructions provided by your readme).

So I have no idea on why I now get this error. I also feel very uncomfortable in messing about with other components scared to break HASS

The good news is that if you followed the instructions you will have hass installed in a virtual environment which means you can’t mess it up unless you explicitly switch to that environment., What probably happened is that when you installed AppDaemon, it upgraded your requests library as part of the process. As far as I can tell, upgrading pip3 as mentioned in that article should fix the issue and allow you to upgrade AppDaemon, however I can understand your caution. In the end the choice is yours.

1 Like