# Unregister a FlowCardTriggerDevice.trigger

**URL:** <https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721>\
**Category:** Developers\
**Created:** [January 7, 2023, 5:11pm UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721 "2023-01-07T17:11:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Le\_Cactus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/le_cactus/32/9727_2.png) [@Le\_Cactus](https://community.homey.app/u/Le_Cactus)\
**Post date:** [January 7, 2023, 5:11pm UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/1 "2023-01-07T17:11:45Z")

</div>

Hi,

In my Device.js I use the following code:

```auto
const someTrigger = this.homey.flow.getDeviceTriggerCard('some_capability');

```

But as soon as my device is deleted I begin getting errors like

```auto
[err] 2023-01-07 16:51:28 Unhandled Rejection at: Promise {
  <rejected> Error: device_not_found
      at Remote Process
      at HomeyClient.emit (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/lib/HomeyClient.js:1:312)
      at ManagerFlow._onCardTriggerDevice (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/manager/flow.js:219:26)
      at FlowCardTriggerDevice.trigger (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/lib/FlowCardTriggerDevice.js:1:1180)
      at EcovacsMQTT_JSON.<anonymous> (/drivers/Deebot/device.js:158:29)
      at EcovacsMQTT_JSON.emit (node:events:526:28)
      at EcovacsMQTT_JSON.handleMessagePayload (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:188:22)
      at /node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:122:28
      at EcovacsMQTT_JSON.handleMessage (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:126:11)
      at EcovacsMQTT_JSON.handleCommandResponse (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:69:22)
      at EcovacsMQTT_JSON.sendCommand (/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:206:22) {
    code: 404
  }
} reason: Error: device_not_found
    at Remote Process
    at HomeyClient.emit (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/lib/HomeyClient.js:1:312)
    at ManagerFlow._onCardTriggerDevice (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/manager/flow.js:219:26)
    at FlowCardTriggerDevice.trigger (/opt/homey-client/system/manager/ManagerApps/AppProcess/node_modules/homey-apps-sdk-v3/lib/FlowCardTriggerDevice.js:1:1180)
    at EcovacsMQTT_JSON.<anonymous> (/drivers/Deebot/device.js:158:29)
    at EcovacsMQTT_JSON.emit (node:events:526:28)
    at EcovacsMQTT_JSON.handleMessagePayload (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:188:22)
    at /node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:122:28
    at EcovacsMQTT_JSON.handleMessage (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:126:11)
    at EcovacsMQTT_JSON.handleCommandResponse (/node_modules/ecovacs-deebot/library/950type/ecovacsMQTT_JSON.js:69:22)
    at EcovacsMQTT_JSON.sendCommand (/node_modules/ecovacs-deebot/library/ecovacsMQTT.js:206:22) {
  code: 404
}

```

What do I need to do in the onDeleted() function to prevent this? I tried

```auto
this.someTrigger.destroy()

```

and

```auto
detele this.someTrigger

```

But both don’t seem to work. On line 158 of device.js the is this trigger:

```auto
someTrigger.trigger(this);

```

Should /can I check to see if my device is still available before I trigger it, and solve the errors that way?

Any hints?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 7, 2023, 5:39pm UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/2 "2023-01-07T17:39:30Z")

</div>

It looks like your device handler is still receiving MQTT messages for the device which is causing the triggering of the flow card, even though the device has already been deleted.

---

<div class="post-metadata">

**Author:** ![Le\_Cactus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/le_cactus/32/9727_2.png) [@Le\_Cactus](https://community.homey.app/u/Le_Cactus)\
**Post date:** [January 7, 2023, 6:26pm UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/3 "2023-01-07T18:26:14Z")

</div>

Yeah, I know, but there could be other devices that need those MQTT messages. I didn’t code it myself so I’m not sure how to handle this.

So, disabling trigger cards isn’t an options?

Then I will have to see how I can stop the MQTT messages i guess. Bummer 🙂 Thanks though!

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 7, 2023, 8:12pm UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/4 "2023-01-07T20:12:39Z")

</div>

The library that you’re using is emitting events, you should stop listening to those events in your device class. Even if you would be able to disable trigger cards, you’d probably run into other issues anyway 😬

---

<div class="post-metadata">

**Author:** ![Le\_Cactus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/le_cactus/32/9727_2.png) [@Le\_Cactus](https://community.homey.app/u/Le_Cactus)\
**Post date:** [January 8, 2023, 9:27am UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/5 "2023-01-08T09:27:46Z")

</div>

Okay, noted 🙂

Thanks. I’ll ask the developer of the library how to do that, I can’t seem to find a way how to do that.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [January 8, 2023, 9:57am UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/6 "2023-01-08T09:57:49Z")

</div>

How do you register your device to get updates? Perhaps there is an unregister function like used for events.

---

<div class="post-metadata">

**Author:** ![Le\_Cactus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/le_cactus/32/9727_2.png) [@Le\_Cactus](https://community.homey.app/u/Le_Cactus)\
**Post date:** [January 8, 2023, 10:01am UTC](https://community.homey.app/t/unregister-a-flowcardtriggerdevice-trigger/74721/7 "2023-01-08T10:01:09Z")

</div>

No, I just connect and disconnect to and from the API.

I got word from the developer from the library/API saying it’s a bug; the disconnect only disconnects, but doesn’t unsubscribe. He’s going to try an fix it. 👍🏽
