# Filtering of MQTT message

**URL:** <https://community.homey.app/t/filtering-of-mqtt-message/30103>\
**Category:** Flows\
**Created:** [May 19, 2020, 12:11pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103 "2020-05-19T12:11:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 19, 2020, 12:11pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/1 "2020-05-19T12:11:01Z")

</div>

Hello,

I have installed a SIP2MQTT tool and now I get an MQTT message whenever someone calls my Asterisk PBX. The script also searches for the accompanying name in a vCard file.

The MQTT message looks like:

`{"verb": "incoming", "caller":"Remco Hannink (0612345678)", "uri":"\"0612345678\" <sip:0612345678@192.168.1.256>"}`

Now I want to filter just the name off the maller from this message and Send it to Google Home to make an announcement.  
I am wonderen how I can achieve this with Homey flows.

Gr. Remco

---

<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:** [May 19, 2020, 12:59pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/2 "2020-05-19T12:59:43Z")

</div>

You can use Homeyscript for that:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/d/fd62388e9134401ee6193b4903c82c2ce1ce527c.jpeg)

The `mqttcaller` script extracts the caller and puts it in a tag:

```auto
const payload = JSON.parse(args[0]);
setTagValue('caller', { type: 'string', title : 'caller' }, payload.caller);
return true;

```

(for some reason, the tag title isn’t show in the Action card, just its green placeholder)

---

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 19, 2020, 1:12pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/3 "2020-05-19T13:12:58Z")

</div>

@robertklep,

Thanks slot, I Will try it and let you know…

Gr. Remco

---

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 19, 2020, 1:29pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/4 "2020-05-19T13:29:06Z")

</div>

@robertklep,

Two problems, Problem one, I don’t see the returned TagValue from the script with the callerID in the list of tags (no empty placholder either).  
And I was wondering if I could filter just the name from the entire callerID: “Remco Hannink (0612345678)”.

Gr. Remco

---

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 19, 2020, 1:33pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/5 "2020-05-19T13:33:42Z")

</div>

First problem is solved. I had to run the script once manual and then the caller tags shows in the list (with name BTW).

Second problem is still not solved.

---

<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:** [May 19, 2020, 1:37pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/6 "2020-05-19T13:37:50Z")

</div>

If it’s always of that format, you can remove everything from the first parentheses:

```auto
setTagValue('caller', { type: 'string', title : 'caller' }, payload.caller.replace(/\s*\(.*/, ''));

```

---

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 20, 2020, 1:48pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/7 "2020-05-20T13:48:56Z")

</div>

@robert,

I like to send the name if it is known. I have the tag callername for that.  
If caller is empty however I want to display the tag Number. I have already tried to Create the tag myself, regular expression for everything between parentheses is:

```auto
\(([^\)]+)\)

```

But how do I Create a string with that:

```auto
setTagValue('callername', { type: 'string', title : 'naam' }, payload.caller.replace(/\s*\(.*/, ''));
setTagValue('callernumber', { type: 'string', title : 'nummer' }, payload.caller ????????? 

```

Sorry for these “dumb” questions, was not Able to find it on google.

Gr. Remco

---

<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:** [May 20, 2020, 2:16pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/8 "2020-05-20T14:16:19Z")

</div>

This should work:

```auto
payload.caller.replace(/.*\((.*?)\).*/, '$1')

```

---

<div class="post-metadata">

**Author:** ![rhannink](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rhannink/32/10648_2.png) [@rhannink](https://community.homey.app/u/rhannink)\
**Post date:** [May 20, 2020, 2:32pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/9 "2020-05-20T14:32:06Z")

</div>

@robertklep,

Thanks, its working now…

Gr. Remco

---

<div class="post-metadata">

**Author:** ![VanGilles](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vangilles/32/11478_2.png) [@VanGilles](https://community.homey.app/u/VanGilles)\
**Post date:** [June 3, 2020, 2:33pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/10 "2020-06-03T14:33:51Z")

</div>

I have a similar use-case with a IKEA dimmer connected with Zigbee2MQTT on a Raspberry PI.  
It outputs a payload like:  
**{“rate”:195,“linkquality”:36,“brightness”:252,“update\_available”:true,“battery”:87,“action”:“rotate\_stop”}**

I can use the MQTT client and receive the payload with the topic within a flow:  
**zigbee2mqtt/IKEA SYMFONISK REMOTE (keuken)**

How can i extract the brightness value, in this case “252”, and store it in a variable? Is there a way without Homeyscript, for instance make use of math.js in the app Better Logic to only extract a piece of a string. Or even better connect a way to receive a topic including a direct to link to a payload array in the MQTT client app.

Can you help me out?

---

<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:** [June 3, 2020, 2:52pm UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/11 "2020-06-03T14:52:19Z")

</div>

It might be possible with Math.js and Better Logic. I doubt it’s possible with the MQTT Client app because parsing/processing JSON is too specific (JSON isn’t part of MQTT).

But I think Homeyscript is the easiest way, the script will be very similar to [this script](https://community.homey.app/t/filtering-of-mqtt-message/30103/2), just a different call to `setTagValue`:

```auto
setTagValue('brightness', { type: 'number', title : 'brightness' }, payload.brightness);

```

---

<div class="post-metadata">

**Author:** ![VanGilles](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vangilles/32/11478_2.png) [@VanGilles](https://community.homey.app/u/VanGilles)\
**Post date:** [June 4, 2020, 9:50am UTC](https://community.homey.app/t/filtering-of-mqtt-message/30103/12 "2020-06-04T09:50:54Z")

</div>

Hello Robert,

Thanks for your help. It worked with your homeyscript sollution.

Unfortunately my flow is automatically dissabled by Homey after some use of the volume remote because the flow is to much started if I dail in and out the round dailer knob on the remote. (use case is to change volume of a chromecast by a remote with Homey)

I will try out the Homey MQTT hub app to directly change the chromecast volume capability without a flow and see if this will work.

If anyone have a better sollution or some tips, you’re welcome. 🙂
