appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

Set channel for self.notify()

Open gpbenton opened this issue 2 months ago • 0 comments

What happened?

This is a continuation of #2385 , but someone else's bug got fixed, but not this one (unless I am missing something).

For version 4.4.2 I had the following code for setting the output channel on a notify

            warn_msg = self.sensor.get_state(attribute="message")
            title = self.sensor.get_state(attribute="Title")
            notification_data = {"channel": self.channel}
            self.log(f"{warn_msg =}, {title =}, {notification_data =}", level="DEBUG")
            self.notify(
                    warn_msg, title=title, data=notification_data
            )  # pyright: ignore [reportUnusedCoroutine]

For 4.5.12 I get the error

2025-06-25 09:16:33.092823 WARNING HASS: Error with websocket result: invalid_format: required key not provided @ data['message']

The problem as I understand it, is that the data parameter gets interpreted as the data field in the service call, and so the kwarg parameter replaces the default version that has the message field included.

The solution for the call_service in #2385 is to set the kwarg to service_data, but if I do that in the self.notify I get the error

2025-11-05 17:10:56.448533 WARNING HASS: Error with websocket result: invalid_format: extra keys not allowed @ data['channel']

The data field of a notify service call itself has a field called data, which is causing some confusion (to me at least).

Image

I think the channel needs to go in the inner data field, but I can't work out how to get it there in the self.notify call.

Version

4.5.12

Installation type

Docker container

Relevant log output

2025-11-05 17:41:25.244766 DEBUG waste_reminder: initialize
2025-11-05 17:41:25.245687 DEBUG waste_reminder: Registering reminder for run_every in 1:00:00 intervals, starting 2025-11-05 17:41:25.245470+00:00
2025-11-05 17:41:25.250738 DEBUG waste_reminder: reminder
2025-11-05 17:41:25.251606 DEBUG waste_reminder: kwargs={'__thread_id': 'thread-27', 'constrain_input_boolean': 'input_boolean.waste_needs_moving'}
2025-11-05 17:41:25.252866 DEBUG waste_reminder: send_notify
2025-11-05 17:41:25.253283 DEBUG waste_reminder: get state: input_boolean.waste_needs_moving, default from waste_reminder
2025-11-05 17:41:25.254790 DEBUG waste_reminder: Previous message repeated 1 times
2025-11-05 17:41:25.255356 DEBUG waste_reminder: call_service: notify/notify, {'service_data': {'data': {'channel': 'Waste Notification'}}}
2025-11-05 17:41:25.256499 WARNING HASS: Error with websocket result: invalid_format: required key not provided @ data['message']



and then

2025-11-05 17:33:48.532834 DEBUG waste_reminder: initialize
2025-11-05 17:33:48.533852 DEBUG waste_reminder: Registering reminder for run_every in 1:00:00 intervals, starting 2025-11-05 17:33:48.533636+00:00
2025-11-05 17:33:48.538194 DEBUG waste_reminder: reminder
2025-11-05 17:33:48.539054 DEBUG waste_reminder: kwargs={'__thread_id': 'thread-27', 'constrain_input_boolean': 'input_boolean.waste_needs_moving'}
2025-11-05 17:33:48.540196 DEBUG waste_reminder: send_notify
2025-11-05 17:33:48.540607 DEBUG waste_reminder: get state: input_boolean.waste_needs_moving, default from waste_reminder
2025-11-05 17:33:48.542030 DEBUG waste_reminder: Previous message repeated 1 times
2025-11-05 17:33:48.542561 DEBUG waste_reminder: call_service: notify/notify, {'channel': 'Waste Notification'}
2025-11-05 17:33:48.543739 WARNING HASS: Error with websocket result: invalid_format: extra keys not allowed @ data['channel']

Relevant code in the app or config file that caused the issue

warn_msg = self.sensor.get_state(attribute="message")
            title = self.sensor.get_state(attribute="Title")
            notification_data = {"channel": self.channel}
            self.log(f"{warn_msg =}, {title =}, {notification_data =}", level="DEBUG")
            self.notify(
                    warn_msg, title=title, data=notification_data
            )  # pyright: ignore [reportUnusedCoroutine]

Anything else?

No response

gpbenton avatar Nov 05 '25 17:11 gpbenton