Hi,
i am writing a class which should spawn a notification when or washing machine/dryer/dishwasher is starting or has finished. But i have a problem. First, please have a look at the python code:
class NotifyHaushaltsgeraete(hass.Hass):
def initialize(self):
self.log("Achte darauf ob Haushaltsgeraete fertig sind")
self.listen_state(self.send_notification_haushaltsgeraet, self.args["deviceID"])
def send_notification_haushaltsgeraet(self, entity, attribute, old, new, kwargs):
if old=="off" and new=="on":
# Startet
self.title = self.args["deviceName"] + " aktiv"
self.message = "Der " + self.args["deviceActivity"] + " wurde gestartet."
elif old=="on" and new=="off":
# Endet
self.title = self.args["deviceName"] + " fertig"
self.message = "Der " + self.args["deviceActivity"] + " wurde abgeschlossen."
self.log(self.title)
self.notify(self.message, title=self.title, name="pushover_simon")
self.notify(self.message, title=self.title, name="pushover_frauke")
In the apps definition, i am handing over the sensor ID, and some values for the notification strings:
notify_trockner:
module: notify
class: NotifyHaushaltsgeraete
deviceID: "binary_sensor.badezimmer_trockner_aktiv"
deviceName: "Wäschetrockner"
deviceActivity: "Trocknungsvorgang"
notify_waschmaschine:
module: notify
class: NotifyHaushaltsgeraete
deviceID: "binary_sensor.badezimmer_waschmaschine_aktiv"
deviceName: "Waschmaschine"
deviceActivity: "Waschvorgang"
notify_spuelmaschine:
module: notify
class: NotifyHaushaltsgeraete
deviceID: "binary_sensor.kueche_spuelmaschine_aktiv"
deviceName: "Spülmaschine"
deviceActivity: "Spülvorgang"
As a result, i get the following error:
2021-12-08 09:40:20.256294 WARNING notify_haushaltsgeraete: ------------------------------------------------------------
2021-12-08 09:40:20.256818 WARNING notify_haushaltsgeraete: Unexpected error running initialize() for notify_haushaltsgeraete
2021-12-08 09:40:20.257218 WARNING notify_haushaltsgeraete: ------------------------------------------------------------
2021-12-08 09:40:20.258050 WARNING notify_haushaltsgeraete: Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/appdaemon/app_management.py", line 165, in initialize_app
await utils.run_in_executor(self, init)
File "/usr/local/lib/python3.9/site-packages/appdaemon/utils.py", line 308, in run_in_executor
response = future.result()
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/conf/apps/notify.py", line 51, in initialize
self.listen_state(self.send_notification_haushaltsgeraet, self.args["deviceID"])
KeyError: 'deviceID'
2021-12-08 09:40:20.258698 WARNING notify_haushaltsgeraete: ------------------------------------------------------------
since that’s one of my first steps with AppDaemon (currently migrating some stuff from node-red), and my first attempt with arguments in AppDaemon ever, i have no clue what is wrong here. I would be very happy if someone could help me out here.