I’m sure that this is something extremely obvious that I’m missing here but I’m getting this error.
2018-11-01 10:28:30.471407 WARNING AppDaemon: ------------------------------------------------------------
2018-11-01 10:28:30.474303 WARNING AppDaemon: Unexpected error in worker for App smoke_alarms:
2018-11-01 10:28:30.475601 WARNING AppDaemon: Worker Ags: {'name': 'smoke_alarms', 'id': UUID('74489e3a-f189-4b22-a51d-b7e75d235873'), 'type': 'attr', 'function': <bound method SensorNotification.state_change of <smoke_detector.SensorNotification object at 0x7fa178041be0>>, 'attribute': 'state', 'entity': 'sensor.upstairs_smoke', 'new_state': 'Testing', 'old_state': 'Idle', 'kwargs': {'handle': UUID('8ad8af65-7a03-4e7e-a3fd-b1fb451af7df')}}
2018-11-01 10:28:30.476900 WARNING AppDaemon: ------------------------------------------------------------
2018-11-01 10:28:30.477919 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 595, in worker
self.sanitize_state_kwargs(app, args["kwargs"]))
File "/conf/apps/smoke_detector.py", line 50, in state_change
self.announcement_cb(self, message_text)
File "/conf/apps/smoke_detector.py", line 58, in announcement_cb
self.call_service("tts/google_say", entity_id=self.media_player, message=kwargs.message_text)
AttributeError: 'str' object has no attribute 'message_text'
2018-11-01 10:28:30.478345 WARNING AppDaemon: ------------------------------------------------------------
Here is my code
import appdaemon.plugins.hass.hassapi as hass
#
# App to send notification when a sensor changes state
#
# Args:
#
# sensor: sensor to monitor e.g. sensor.upstairs_smoke
# idle_state - normal state of sensor e.g. Idle
# turn_on - scene or device to activate when sensor changes e.g. scene.house_bright
# Release Notes
#
# Version 1.0:
# Initial Version
class SensorNotification(hass.Hass):
def initialize(self):
if "sensor" in self.args:
for sensor in self.split_device_list(self.args["sensor"]):
self.listen_state(self.state_change, sensor)
self.media_player = 'group.speakers'
def state_change(self, entity, attribute, old, new, kwargs):
self.log("{} is in state {}".format(self.friendly_name(entity), new))
#self.notify("{} is in state {}".format(self.friendly_name(entity), new), name="ios")
if self.get_state(entity) == "Fire":
self.log("Announcing there is a fire")
message_text = "The {} has detected smoke. Please exit the house immediately through the safest path." .format(self.friendly_name(entity))
self.announcement(self, message=message_text)
for light in self.args["turn_on"]:
self.turn_on(light)
self.turn_on(self.args["turn_on"])
while self.get_state(entity) == "Fire":
self.fire_handle = self.run_in(self.announcement, 15, message=message_text)
else:
self.cancel_timer(self.fire_handle)
if new == "CO":
self.log("Announcing there is CO")
self.turn_on(self.args["turn_on"])
self.announcement(self, message=message_text)
message_text = "The {} has detected carbon monoxide. Please exit the house immediately through the safest path." .format(self.friendly_name(entity))
while new == "CO":
self.co_handle = self.run_in(self.announcement, 15, message=message_text)
else:
self.cancel_timer(self.co_handle)
if new == "Testing":
self.log("Announcing that we're testing")
message_text = "The {} has detected test mode. There is no need for you to panic this is only a test." .format(self.friendly_name(entity))
self.announcement(self, message=message_text)
while new == "Testing":
self.testing_handle = self.run_in(self.announcement, 15, message=message_text)
else:
self.cancel_timer(self.testing_handle)
def announcement(self,kwargs):
self.call_service("media_player/volume_set", entity_id=self.media_player, volume_level = 100)
self.call_service("tts/google_say", entity_id=self.media_player, message=(kwargs['message']))
I just figured it’d be cleaner if I had just a stand alone callback for handling all of the announcements but I don’t think I"m passing the message text in properly. Thank you all for your help.