Can I use the new action events with appdaemon?

Hi,

I am using the IKEA Tradfri Switch (Model E2001/E2002) with AppDaemon. In my Python code, I have been listening to the following event: sensor.tradfri_switch_action

After updating to Zigbee2MQTT 2.0.0, I would like to use the new action events. Therefore, I tried listening to the following event: event.tradfri_switch_action

However, this event is never triggered in AppDaemon (as shown in the experiment below). Additionally, after disabling the “Home Assistant legacy action sensors” setting in the Zigbee2MQTT settings, the old sensor-based action events stopped working as well.

Here is my experiment code for listening to the new event:

self.listen_state(self._experiment, "event.tradfri_switch_action")
       
def _experiment(self, entity, attribute, old, new, kwargs):
        self._mylog("experiment", "entity = {}".format(entity))
        self._mylog("experiment", "attribute = {}".format(attribute))
        self._mylog("experiment", "old = {}".format(old))
        self._mylog("experiment", "new = {}".format(new))
        self._mylog("experiment", "kwargs = {}".format(kwargs))

It is unclear to me whether the new event actions are supported via AppDaemon or if I am missing a configuration step.

Could someone clarify if these new event actions are indeed supported via AppDaemon? If they are, am I using the correct method to listen for these events?

Regards,
Will

When you listen for events in Appdaemon, you use the listen_event function and not the listen_state function.

Try this:

  self.listen_event(self.handle_event, "tradfri_switch_action")

    def handle_event(self, event_name, data, kwargs):
    # Handle your event here...

Please note that the listen_event callback takes different arguments than the listen_state callback as per above, and you do not prefix the event name with event.