# MQTT - Allow integration of an external "device" (smartphone)

**URL:** <https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288>\
**Category:** Configuration\
**Tags:** mqtt\
**Created:** [April 29, 2021, 1:49pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288 "2021-04-29T13:49:46Z")\
**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, 2021, 1:49pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/1 "2021-04-29T13:49:46Z")

</div>

I don’t think this is possible at the moment, hence the creation of a feature request.

# Need

Detect my presence and that of my wife at home.

# Proposed Solution

I don’t particularly like Bluetooth key fobs, they take up a bit of space and my NUT seems to have given up quite quickly.

I found a simple Android application: [Presence Publisher](https://play.google.com/store/apps/details?id=org.ostrya.presencepublisher&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1) (Android).

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/8/855a8faeb35db220efa56d120d5183969f0c7d0d.png)

The application allows you to register on an MQTT server to push events when the home WiFi is detected.  
This allows me to detect my phone on the WiFi and easily and correctly identify myself.

I don’t currently see how I can do this.

- Maybe the possibility of creating MQTT users in the service needs to be added?
- Anything else?

---

<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:** [April 29, 2021, 1:55pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/2 "2021-04-29T13:55:33Z")

</div>

Normally I think you can use the same identifier provided in Gladys to identify yourself on the MQTT server, you just need to use a client-id different from Gladys’s (which is random so it shouldn’t be a problem)

After that, I don’t exactly know what the message format and the topic this app publishes to are?

---

<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, 2021, 2:18pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/3 "2021-04-29T14:18:49Z")

</div>

> [@pierre-gilles](#):
>
> Normally, I think you can use the same identifier provided in Gladys to log in to the MQTT server, you just need to use a different client-id from Gladys’s (which is random, so it shouldn’t be a problem)

Are these the credentials provided in the configuration file? I think it’s encrypted, right?

> [@pierre-gilles](#):
>
> After that, I don’t know exactly what the message format and the topic on which this app publishes is?

No idea yet, I haven’t gotten to the connection part, so I haven’t delved into this point yet.

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [April 29, 2021, 2:23pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/4 "2021-04-29T14:23:59Z")

</div>

> [@lmilcent](#):
>
> Are these the credentials provided in the configuration file? I think it’s encrypted, right?

You’ve got the little eye to display the password

 ![Screenshot_20210429_162447_com.android.chrome](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/8/87eaa872ff27c3df3c492cc7c5cea3d13dd8946f.jpeg)

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [April 29, 2021, 2:42pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/5 "2021-04-29T14:42:58Z")

</div>

However, I don’t see how this can work if MQTT is not accessible from the outside, you will never be marked as away.

Here’s what it publishes:

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/dde4cd747a499efb246f15473faa24c7090a7d86.png)

---

<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 30, 2021, 11:51am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/6 "2021-04-30T11:51:59Z")

</div>

Thanks for your answers!  
I hadn’t thought of that actually, that I need to be able to indicate that I’m no longer there. 🤔

For detecting my return home, it could work, I just need to find another way to detect when I’m no longer there, especially.

---

<div class="post-metadata">

**Author:** ![Shiftmaj](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@Shiftmaj](https://community.gladysassistant.com/u/Shiftmaj)\
**Post date:** [May 1, 2021, 7:31am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/7 "2021-05-01T07:31:02Z")

</div>

I’m just starting with these technologies, but wouldn’t it be possible to trigger someone’s absence when there’s no more «&nbsp;online&nbsp;» status update for, say, 15 minutes?

---

<div class="post-metadata">

**Author:** ![spenceur](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/spenceur/32/1961_2.png) [@spenceur](https://community.gladysassistant.com/u/spenceur)\
**Post date:** [May 1, 2021, 8:12am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/8 "2021-05-01T08:12:13Z")

</div>

For info, I use it to manage my presence and my phone’s battery in Gladys.  
And it works well.  
In the MQTT service, I created a device in this format:

 ![Screenshot_20210501-100714](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/f/f73f7cf33bfb9e7f5489e4ec381356fc21c4eacb.jpeg) ![Screenshot_20210501-100721](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/f/fc144851889ec5d51ad9876bfc3f0f04f35557bf.jpeg) ![Screenshot_20210501-100727](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/c/c09ba389ed78f1d4f996b5fd5d96d0ee4cd39191.jpeg)

Then, on the presence publisher side,  
I changed the presence value to 1 and the absence value to 0.  
After that, I opened Gladys access, so I can access it even outside Wi-Fi.  
But it shouldn’t be complicated for @pierre-gilles to create an API on the g+ side to set a value to 0 or 1 for a device or simply set absent or present when g+ receives the values via API?

---

<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:** [May 3, 2021, 3:35am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/9 "2021-05-03T03:35:12Z")

</div>

> [@spenceur](#):
>
> But shouldn’t it be complicated for @pierre-gilles to create an API on the g+ side to set a value to 0 or 1 for a device or simply set absent or present when g+ receives the values via API?

Not very complicated 🙂 If there is demand for this kind of feature on Gladys Plus, I’ll add it without any problem 🙂

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [May 3, 2021, 8:18am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/10 "2021-05-03T08:18:49Z")

</div>

+1 for the feature via Gladys +

---

<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:** [May 3, 2021, 8:23am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/11 "2021-05-03T08:23:38Z")

</div>

Got it, I’ve created a «&nbsp;feature request&nbsp;»:

> [@Envoyer des valeurs de capteurs via l'Open API Gladys Plus](https://community.gladysassistant.com/t/envoyer-des-valeurs-de-capteurs-via-lopen-api-gladys-plus/6296):
>
> Permettre d’envoyer des valeurs de capteurs via l’Open API Gladys Plus, utile par exemple pour envoyer de la présence via Gladys Plus. Demandée ici:

It’s a good idea and it’s not very complicated, I’ll check it out!

---

<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:** [May 7, 2021, 4:40am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/12 "2021-05-07T04:40:31Z")

</div>

Got it, I’ve coded the new route on the Open API, it will be coming soon in a PR on Gladys 🙂

The API call looks like this:

 ![Screenshot 2021-05-07 at 12.37.03](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/0/010ca91199150504d90927094a2de77f9aca95eb.png)

And in Gladys (and Gladys Plus), I now have the new value:

 ![Screenshot 2021-05-07 at 12.37.28](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/4/4d1b0d45f8bcfc94f6046ec8714676b5819dd230.png)

Of course, this feature can be used with any type of device, including a presence device!

---

<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:** [May 7, 2021, 4:47am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/13 "2021-05-07T04:47:03Z")

</div>

The PR is ready:

> <https://github.com/GladysAssistant/Gladys/pull/1184>
>
> \### 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:
> 
> \- \[\] If your changes affects code, did your write the tests?
> \- \[\] Are tests passing? (\`npm test\` on both front/server)
> \- \[\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[\] If you are adding a new features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[\] If your changes modify the API (REST or Node.js), did you modify the API documentation? (Documentation is based on comments in code)
> \- \[\] If you are adding a new features/services which needs explanation, did you modify the user documentation? See \[the GitHub repo\](https://github.com/GladysAssistant/v4-website) and the \[website\](https://gladysassistant.com).
> \- \[\] Did you add fake requests data for the demo mode (\`front/src/config/demo.json\`) so that the demo website is working without a backend? (if needed) See \[https://demo.gladysassistant.com\](https://demo.gladysassistant.com).
> 
> NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
> 
> \### Description of change
> 
> Little demo: 
> 
> \<img width="1208" alt="Screenshot 2021-05-07 at 12 37 03" src="https://user-images.githubusercontent.com/7365207/117399055-3a85b980-af32-11eb-8d95-e4801526d71a.png"\>
> 
> \<img width="411" alt="Screenshot 2021-05-07 at 12 37 28" src="https://user-images.githubusercontent.com/7365207/117399059-3e194080-af32-11eb-8c1f-aff9c58cd561.png"\>

---

<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:** [May 7, 2021, 5:28am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/14 "2021-05-07T05:28:01Z")

</div>

I just merged the PR, it’s available on master!

I just launched a Docker dev build integrating the latest bug fixes, as well as this feature 🙂

The production gateway was also re-deployed with this new feature 🥳

---

<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:** [May 13, 2021, 6:35am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/15 "2021-05-13T06:35:36Z")

</div>

It’s live in Gladys v4.3.1 🙂

> [@Gladys Assistant v4.3.1 est disponible, avec une nouvelle Open API pour Gladys Plus et autres rocket](https://community.gladysassistant.com/t/gladys-assistant-v4-3-1-est-disponible-avec-une-nouvelle-open-api-pour-gladys-plus-et-autres/6311):
>
> Salut à tous ! Nouvelle release aujourd’hui, et pas des moindres ! Bon je sais, le numéro de version peut laisser entendre que c’est une petite release, en fait j’ai sous estimé tout ce qu’on avait dans cette release au moment de faire le tag git sweat_smile ça aurait du être la 4.4 stuck_out_tongue Une nouvelle Open API Gladys Plus Vous êtes nombreux à avoir demander le moyen d’envoyer des valeurs de capteurs via l’API Gladys Plus. C’est possible via un simple call API maintenant, de n…

---

<div class="post-metadata">

**Author:** ![MHI](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@MHI](https://community.gladysassistant.com/u/MHI)\
**Post date:** [May 14, 2021, 3:19pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/16 "2021-05-14T15:19:02Z")

</div>

Hello everyone,

I’m new to Gladys, I’m taking the liberty to intervene on this post regarding the initial request for presence detection. In my current system (I won’t name it, but it runs on a PI4), I use Nut detection and also Ping detection for phones (the MAC address), which works perfectly well. Wouldn’t it be possible to do the same in Gladys, a module to ping IP or MAC addresses? I find it more practical than going through a third-party application.

---

<div class="post-metadata">

**Author:** ![Jean34](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/jean34/32/3349_2.png) [@Jean34](https://community.gladysassistant.com/u/Jean34)\
**Post date:** [May 14, 2021, 4:48pm UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/17 "2021-05-14T16:48:36Z")

</div>

Hello and welcome, your request has already been mentioned 😉

> [@Détection de présence via le réseau local](https://community.gladysassistant.com/t/detection-de-presence-via-le-reseau-local/6131?u=jean34):
>
> Ca serait bien de pouvoir détecter la présence d’un utilisateur quand un un appareil est détecter sur le réseaux local comme dans la v3. Par exemple quand le téléphone ce reconnecte au wifi.

The issue is that if the box reboots, you will change IP, and I no longer remember this discussion but there was also something that mentioned the MAC address changing as well… Read the discussion and you will be fixed

---

<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:** [May 27, 2021, 6:37am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/18 "2021-05-27T06:37:06Z")

</div>

Hello!

From what we’ve discussed on several topics, this feature already works (I think @VonOx made a working PoC on Android)

Is it good on your side @lmilcent?

If so, can we close the feature request?

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [May 27, 2021, 6:48am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/19 "2021-05-27T06:48:18Z")

</div>

Yes, it works great, I just need to find some time for the documentation

---

<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:** [May 27, 2021, 7:07am UTC](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288/20 "2021-05-27T07:07:19Z")

</div>

I haven’t tested it yet, as I don’t have Gladys Plus, I connect to my instance at home via VPN. So it’s more restrictive, but I will think again about the subject for my particular case.

[Next page](https://community.gladysassistant.com/t/mqtt-permettre-lintegration-dun-device-externe-smartphone/6288.md?page=2)
