Homey Community Forum

Filtering of MQTT message

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

You can use Homeyscript for that:

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

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)

@robertklep,

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

Gr. Remco

@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

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.

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

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

@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:

\(([^\)]+)\)

But how do I Create a string with that:

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

This should work:

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

@robertklep,

Thanks, its working now…

Gr. Remco