Hey Everyone,
I copied an appdaemon app/config created/modified by @kylerw from this post:
The following is the app:
import appdaemon.appapi as appapi
#
# DoorLeftUnlocked
#
class Notifications(appapi.AppDaemon):
def initialize(self):
self.log("Generic Notification App")
notifyState = self.args["notifyState"]
stopState = self.args["stopState"]
entityType = self.args["entityType"]
self.entity_timer = None
if "entities" in self.args:
for entity in self.split_device_list(self.args["entities"]):
## If Group - initialize all entities from the group
if "group" in entity:
self.log("Group provided.")
groupitem = self.get_state(entity,"all")
entity_list = groupitem['attributes']['entity_id']
for member in entity_list:
if entityType in member:
self.log("Initializing entity: " + self.friendly_name(member))
self.listen_state(self.state_changed, member, new=notifyState)
self.listen_state(self.state_changed, member, new=stopState)
else:
self.log("Single entity provided.")
self.log("Initializing entity: " + self.friendly_name(entity))
self.listen_state(self.state_changed, member, new=notifyState)
self.listen_state(self.state_changed, member, new=stopState)
else:
# This will monitory ALL of the entities in your house
self.log("No entity provided in cfg, configure for all.")
self.listen_state(self.state_changed, entityType, new=notifyState)
self.listen_state(self.state_changed, entityType, new=stopState)
def state_changed(self, entity, attribute, old, new, kwargs):
notifyState = self.args["notifyState"]
entitystate = new
if notifyState in entitystate:
self.run_in(self.start_timer, 0, item=entity, new=entitystate)
else:
self.run_in(self.stop_timer, 0, item=entity, new=entitystate)
def send_notification(self, kwargs):
# This sends a notifcation and then starts the timer for another XX minutes
msg = kwargs["msg"]
self.call_service("notify/notify", message="Generic: {}".format(msg))
self.log(msg)
def start_timer(self, kwargs):
entity = kwargs["item"]
entitystate = kwargs["new"]
if "notifydelaymin" in self.args:
cfgtimer = self.args["notifydelaymin"]
notifydelay = int(cfgtimer) * 60
else:
notifydelay = 600
msg = "{} is currently {}. Will alert again in {} seconds.".format(self.friendly_name(entity), entitystate, notifydelay)
## Send notification immediately
self.run_in(self.send_notification, 0, new=entitystate, msg=msg)
### Reset timer after XXX seconds
self.entity_timer = self.run_in(self.start_timer, notifydelay, entity=entity, new=entitystate)
def stop_timer(self, kwargs):
entity = kwargs["item"]
entitystate = kwargs["new"]
msg = "{} is now {}. Cancelling timer.".format(self.friendly_name(entity), entitystate)
self.run_in(self.send_notification, 0, new=entitystate, msg=msg)
# This cancels the timer once the door is entityed
self.cancel_timer(self.entity_timer)
self.run_in(self.all_entities_check, 0)
def all_entities_check(self, kwargs):
notifyState = self.args["notifyState"]
stopState = self.args["stopState"]
entityType = self.args["entityType"]
## Will send alert if all entitys are entityed
if "all_entity_alert" in self.args and self.args["all_entity_alert"] == "true":
if "entities" in self.args:
for entity in self.split_device_list(self.args["entities"]):
allState = self.get_state(entity)
if allState == stopState:
break
else:
allState = get_state(entityType)
if notifyState not in allState:
msg = "All {}s are now {}.".format(entityType, stopState)
self.run_in(self.send_notification, 0, msg=msg)
Config:
AppDaemon:
errorfile: STDERR
logfile: STDOUT
threads: '10'
HADashboard:
dash_url: http://10.100.10.30:5050
HASS:
ha_key: MyKey
ha_url: https://mydomain.com
hello_world:
class: HelloWorld
module: hello
lock_notifications:
module: notifications_state-timer
class: Notifications
entityType: "lock"
entities: group.all_locks
notifyState: "unlocked"
stopState: "locked"
notifydelaymin: 10
all_entity_alert: true
cover_notifications:
module: notifications_state-timer
class: Notifications
entityType: "cover"
entities: group.all_covers
notifyState: "open"
stopState: "closed"
notifydelaymin: 10
all_entity_alert: true
When I run appdaemon as a service there are no log or error logs which are created. Also, when i run using āsudo ./appdaemon -c /home/pi/appdaemon/confā, i get the following error:
2017-07-22 21:29:01.035214 INFO AppDaemon Version 2.0.7 starting
2017-07-22 21:29:01.035755 INFO Configuration read from: /home/pi/appdaemon/conf/appdaemon.yaml
2017-07-22 21:29:01.488428 INFO Got initial state
2017-07-22 21:29:01.490487 INFO Loading Module: /home/pi/appdaemon/conf/apps/notifications_state-timer.py
2017-07-22 21:29:01.492798 WARNING ------------------------------------------------------------
2017-07-22 21:29:01.493256 WARNING Unexpected error during loading of notifications_state-timer.py:
2017-07-22 21:29:01.493554 WARNING ------------------------------------------------------------
2017-07-22 21:29:01.496931 WARNING Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 911, in read_app
conf.modules[module_name] = importlib.import_module(module_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1572, in get_code
File "<frozen importlib._bootstrap>", line 1532, in source_to_code
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/pi/appdaemon/conf/apps/notifications_state-timer.py", line 21
if entityType in member:
^
TabError: inconsistent use of tabs and spaces in indentation
2017-07-22 21:29:01.497427 WARNING ------------------------------------------------------------
2017-07-22 21:29:01.497805 INFO Loading Module: /home/pi/appdaemon/conf/apps/motion.py
2017-07-22 21:29:01.499424 INFO Loading Module: /home/pi/appdaemon/conf/apps/hello.py
2017-07-22 21:29:01.500947 INFO Loading Object hello_world using class HelloWorld from module hello
2017-07-22 21:29:01.658270 INFO hello_world: Hello from AppDaemon
2017-07-22 21:29:01.660860 INFO hello_world: You are now ready to run Apps!
2017-07-22 21:29:01.661286 INFO Loading Module: /home/pi/appdaemon/conf/apps/lights.py
2017-07-22 21:29:01.662945 INFO App initialization complete
2017-07-22 21:29:01.663665 INFO Starting dashboard
2017-07-22 21:29:01.783943 INFO Connected to Home Assistant 0.49.0
anyone see anything iām missing?