# New trigger: arrival of an MQTT message

**URL:** <https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127>\
**Category:** Demandes livrées\
**Created:** [April 29, 2023, 9:27am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127 "2023-04-29T09:27:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmilcent](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lmilcent/32/7023_2.png) [@lmilcent](https://community.gladysassistant.com/u/lmilcent)\
**Post date:** [April 29, 2023, 9:27am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/1 "2023-04-29T09:27:39Z")

</div>

**Feature description**  
Following our discussion here

> [@Connecter Frigate avec Gladys Assistant](https://community.gladysassistant.com/t/connecter-frigate-avec-gladys-assistant/8124/8?u=lmilcent):
>
> Ok c’est très clair slight_smile Effectivement, à court terme Node-RED est la meilleur option. A long terme, deux options (qui ne sont pas exclusive): Faire une intégration Frigate dans Gladys. Il faudra écouter les topics Frigate dans MQTT et ensuite publier les bons events dans Gladys / gérer des déclenchements de scènes. Proposer un déclencheur de scène «&nbsp;Quand un message MQTT arrive&nbsp;» qui permet d’écouter sur un topic custom et de réagir à ce message. Edit: Bon après en voyant le prod…

A scene must be able to be triggered when an MQTT message arrives on a particular topic.

---

<div class="post-metadata">

**Author:** ![guim31](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/guim31/32/4840_2.png) [@guim31](https://community.gladysassistant.com/u/guim31)\
**Post date:** [April 29, 2023, 8:20pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/2 "2023-04-29T20:20:01Z")

</div>

And that would be useful in other cases, I think!

I need to

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 13, 2023, 8:36am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/3 "2023-10-13T08:36:42Z")

</div>

I made a small suggestion on this PR :

> <https://github.com/GladysAssistant/Gladys/pull/1911>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[x\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[x\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[x\] Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to the community (\[french forum\](https://community.gladysassistant.com/)/\[english forum\](https://en-community.gladysassistant.com/)) for testing before merging.
> 
> \### Description of change
> 
> Launch scene when receive MQTT message on channel "gladys/scene/\[sceneSelector\]" 
> The message must contain "START'

I didn’t add a new trigger. I just added the ability to launch any scene from an MQTT message.

To do this you need to publish a «&nbsp;START&nbsp;» message to the channel: «&nbsp;gladys/scene/[sceneSelector]&nbsp;»

What do you think?

---

<div class="post-metadata">

**Author:** ![cce66](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@cce66](https://community.gladysassistant.com/u/cce66)\
**Post date:** [October 13, 2023, 8:55am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/4 "2023-10-13T08:55:25Z")

</div>

@Lokkye just one word: Awesome! 😊

> For that you need to publish a «&nbsp;START&nbsp;» message in the channel: «&nbsp;gladys/scene/[sceneSelector]&nbsp;»

You’ll need to explain because I don’t see the «&nbsp;how&nbsp;»?

Otherwise it’s great for opening scenes from outside via MQTT or Node-RED!  
Well done on these developments!!! 👍 👏

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [October 13, 2023, 5:05pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/5 "2023-10-13T17:05:43Z")

</div>

Super cool @Lokkye!

For the topic format, we need to keep the format we currently have on the other MQTT topics, notably the «&nbsp;master&nbsp;» prefix which indicates we’re addressing the «&nbsp;master&nbsp;» instance. It’s not the case yet in Gladys, but the idea of this «&nbsp;master&nbsp;» was to have, in the future, detached «&nbsp;pod&nbsp;» instances that can run remote services.

So I’d suggest something like:

```auto
gladys/master/scene/[sceneSelector]/start

```

No specific body.

What do you think?

PS: I also did a small technical review: [Run scene when receive message on MQTT by callemand · Pull Request #1911 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/pull/1911#pullrequestreview-1676916538)

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 16, 2023, 7:26am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/6 "2023-10-16T07:26:51Z")

</div>

@pierre-gilles : I didn’t know about the existence of the topic ‹&nbsp;gladys/master/…&nbsp;›.  
I just modified my code accordingly. It’s much simpler 🙂

Thanks for the technical review 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [October 16, 2023, 7:49am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/7 "2023-10-16T07:49:01Z")

</div>

> [@Lokkye](#):
>
> I just modified my code accordingly. It’s much simpler 🙂

Indeed it’s much simpler 😃 Great PR, I tested it and it works for me!

It’s merged and will be available in the next version of Gladys.

However I’m not sure we should close this feature request because it’s not exactly what was asked (this was talking about a custom topic here)

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 16, 2023, 8:03am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/8 "2023-10-16T08:03:04Z")

</div>

Thanks @pierre-gilles for the merge 🙂

[quote=«&nbsp;pierre-gilles, post:7, topic:8127&nbsp;»]  
However, I’m not sure

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 24, 2023, 8:08am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/9 "2023-10-24T08:08:32Z")

</div>

@pierre-gilles :  
Here is the PR that implements the feature:

> <https://github.com/GladysAssistant/Gladys/pull/1913>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[x\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[x\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[x\] If you are adding a new features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[x\] Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to the community (\[french forum\](https://community.gladysassistant.com/)/\[english forum\](https://en-community.gladysassistant.com/)) for testing before merging.
> 
> 
> \### Description of change
> 
> Add new scene trigger: received message from message queue
> \<img width="566" alt="Screenshot 2023-10-24 at 10 05 09" src="https://github.com/GladysAssistant/Gladys/assets/11317212/fb4652f9-439e-44e1-ac07-17ecd834ba10"\>
> \<img width="574" alt="Screenshot 2023-10-24 at 10 05 02" src="https://github.com/GladysAssistant/Gladys/assets/11317212/839039b1-1b13-411b-b4b3-3ba506868b57"\>

Tell me what you think 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [October 26, 2023, 8:38am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/10 "2023-10-26T08:38:06Z")

</div>

@Lokkye I left you a review! [Add scene trigger : MQTT message by callemand · Pull Request #1913 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/pull/1913#pullrequestreview-1699017013)

I’d like to better understand the logic behind this development to understand the implementation choices 🙂 If you prefer to explain here in French rather than on GitHub in English, whichever you prefer!

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 27, 2023, 9:04am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/11 "2023-10-27T09:04:28Z")

</div>

@pierre-gilles : Thank you for the review.

So regarding the fact that I don’t use the word «&nbsp;MQTT&nbsp;», I wanted to completely disconnect from the service. I do a lot of Clean Architecture in my work and therefore I like to separate concepts. I also wanted to avoid adding technical terms into Gladys. But it’s true that by doing that I’m not necessarily any clearer.  
Are we going to add other message queues in the near or not-too-distant future?

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [October 27, 2023, 11:59am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/12 "2023-10-27T11:59:08Z")

</div>

I understand the idea — however, from a user perspective, making things «&nbsp;ultra-generic&nbsp;» can just be confusing in practice, and it’s often better to be «&nbsp;ultra-specific&nbsp;», which allows using the right vocabulary.

**UX level**

In this case, a user who wants to connect an external MQTT script will inevitably look for the word «&nbsp;MQTT&nbsp;» as a trigger. Sure it’s technical, but anyone who wants that is technical.

If MQTT isn’t mentioned anywhere, it’s impossible to know what that means 🙂

Even if in the future we have other queue technologies, we can create other triggers specific to those technologies.

If we take the example of Zapier ([https://zapier.com/](https://zapier.com/)), when you select a trigger, they offer all the possible technologies directly so it’s clear:

 ![Screenshot 2023-10-27 at 13.45.47](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/7/7dbde73537dc9dc21e37e61bccc21c1f5beefdde.png)

I think we can mention MQTT in this case and talk about MQTT throughout the code without problems 🙂

**Implementation level**

I’m not sure the implementation makes sense for this specific case, notably the use of eventEmitters to cancel triggers and set triggers, because we don’t have a guarantee that the code will execute before moving on.

In the current implementation, nothing tells me that the listener:

```auto
this.gladys.event.on(EVENTS.MESSAGE_QUEUE.UNSUBSCRIBE, this.handleGladysEventUnsubscribe.bind(this));

```

Will actually be executed before:

```auto
this.gladys.event.on(EVENTS.MESSAGE_QUEUE.SUBSCRIBE, this.handleGladysEventSubscribe.bind(this));

```

So potentially, if I edit my scene, my listener is added a second time then removed and so we’re in a «&nbsp;messed-up&nbsp;» state.

Not sure we have a choice; I think we need to call `this.service.mqtt` in the scene. Besides, generally when we go from Gladys to the services, that’s what we do in the rest of the code (for example in the Telegram integration that’s what we do).

What do you think?

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [October 27, 2023, 2:03pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/13 "2023-10-27T14:03:49Z")

</div>

Ok, I understand better.

> [@pierre-gilles](#):
>
> **UX level**
> 
> In this case, the user who wants to connect an external MQTT script will necessarily look for the word “MQTT” as a trigger. Sure it’s technical, but whoever wants that is technical.
> 
> If MQTT isn’t mentioned anywhere, it’s impossible to know what that means 🙂
> 
> Even if in the future we have other queue technologies, we can create other triggers specific to those technologies.
> 
> If we take the example of Zapier ( [https://zapier.com/](https://zapier.com/) ), when you select a trigger, they show you all the possible technologies directly so it’s clear:
> 
> ![Screenshot 2023-10-27 at 13.45.47](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/7/7dbde73537dc9dc21e37e61bccc21c1f5beefdde.png)
> 
> I think we can mention MQTT in this case and talk about MQTT a bit everywhere in the code without issues 🙂

Yes, after thinking about it you’re completely right 🙂

> [@pierre-gilles](#):
>
> **Implementation level**
> 
> I’m not sure the implementation makes sense for this specific case, notably the use of eventEmitters to cancel triggers and set triggers, because we don’t have any guarantee the code will execute before moving on.
> 
> In the current implementation, nothing tells me that the listener:
> 
> ```auto
> this.gladys.event.on(EVENTS.MESSAGE_QUEUE.UNSUBSCRIBE, this.handleGladysEventUnsubscribe.bind(this));
> 
> ```
> 
> will actually be executed before:
> 
> ```auto
> this.gladys.event.on(EVENTS.MESSAGE_QUEUE.SUBSCRIBE, this.handleGladysEventSubscribe.bind(this));
> 
> ```
> 
> So potentially, if I edit my scene, my listener is added a second time then removed and so we’re in a “broken” state
> 
> Not sure we have a choice, I think we have to call `this.service.mqtt` in the scene. Besides, generally when we go from Gladys to the services, that’s what we do in the rest of the code (for example in the Telegram integration that’s what we do)

I didn’t think the «&nbsp;core&nbsp;» could be directly linked with the services. So we also need to handle the fact that the service isn’t enabled 🙂

I’ll take care of that 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [October 27, 2023, 3:29pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/14 "2023-10-27T15:29:13Z")

</div>

[quote=«&nbsp;Lokkye, post:13, topic:8127&nbsp;»]  
I

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [November 5, 2023, 11:57am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/15 "2023-11-05T11:57:36Z")

</div>

@pierre-gilles : I have made the changes based on your feedback.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [November 6, 2023, 8:34am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/16 "2023-11-06T08:34:45Z")

</div>

Great! I’ll check that out today 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [November 6, 2023, 9:47am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/17 "2023-11-06T09:47:27Z")

</div>

Super cool @Lokkye, it works perfectly for me like this 👌

I’ve left you a few comments but nothing major 🙂

> <https://github.com/GladysAssistant/Gladys/pull/1913#pullrequestreview-1714640371>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[x\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[x\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[x\] If you are adding a new features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[x\] Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to the community (\[french forum\](https://community.gladysassistant.com/)/\[english forum\](https://en-community.gladysassistant.com/)) for testing before merging.
> 
> 
> \### Description of change
> 
> Add new scene trigger: received message from message queue
> \<img width="566" alt="Screenshot 2023-10-24 at 10 05 09" src="https://github.com/GladysAssistant/Gladys/assets/11317212/fb4652f9-439e-44e1-ac07-17ecd834ba10"\>
> \<img width="574" alt="Screenshot 2023-10-24 at 10 05 02" src="https://github.com/GladysAssistant/Gladys/assets/11317212/839039b1-1b13-411b-b4b3-3ba506868b57"\>

---

<div class="post-metadata">

**Author:** ![Lokkye](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/lokkye/32/5881_2.png) [@Lokkye](https://community.gladysassistant.com/u/Lokkye)\
**Post date:** [November 7, 2023, 7:23am UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/18 "2023-11-07T07:23:39Z")

</div>

@pierre-gilles : I’ve just made the changes based on your feedback.  
Feel free to tell me if I missed anything. 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [November 10, 2023, 1:09pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/19 "2023-11-10T13:09:50Z")

</div>

Thanks for the fixes, it’s fine with me and it will be included in the next Gladys release! 🙏

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [November 20, 2023, 4:28pm UTC](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127/20 "2023-11-20T16:28:09Z")

</div>

This feature is available in Gladys Assistant 4.31! 🚀

> [@Gladys Assistant 4.31 : Filtre par tag & MQTT dans les scènes](https://community.gladysassistant.com/t/gladys-assistant-4-31-filtre-par-tag-mqtt-dans-les-scenes/8511):
>
> Salut à tous ! Après Gladys Assistant 4.30 et sa fameuse alarme, voilà une nouvelle version de Gladys avec pas mal de fonctionnalités sympa slight_smile A découvrir ci-dessus ! Merci à @Lokkye et @cicoub13 pour leurs contributions clapclap Edit: Je profite de ce post pour dire que je recherche de l’aide ici pour écrire du contenu sur le blog Gladys !

I’m closing this thread to free up the votes, feel free to create another thread if you encounter bugs with this feature 🙂

[Next page](https://community.gladysassistant.com/t/nouveau-declencheur-arrivee-d-un-message-mqtt/8127.md?page=2)
