Send notification only to the device which trigger the event


#1

1) Give a description of the problem
I cannot send push notification to only one device, since push notification goes to all devices which are added to ST.
I have 6 presence sensor in ST (android and iOS phone basically) however notification should be sent only to the person who has changed presence status like “Present / Away” at the location.

I’ve used “send PUSH notification” but I suppose it’s not the proper way.

2) What is the expected behaviour?
I would like to create a piston to send push notification based on presence sensor status (Present / Away) only to the device which is triggering the change.

3) What is happening/not happening?
Everyone receive the notification but only one person should be

4) Post a Green Snapshot of the pistonimage


#2

Yes, as you undoubtedly noticed, the PUSH sends to every member so everyone gets the message. However, if you use “send SMS message to 123-555-1212…”, you can send to an individual device.


#3

Thanks for the hint.
Can I set send SMS message without phone number? Like this


#4

I don’t believe you can but if you create a variable containing all your devices and a string with your corresponding list of phone numbers you can use indexOf() and arrayItem() to look up the appropriate number for the SMS.


#5

guxdude is correct here. SMS is expecting something in the form of a phone number, this can be a calculated value as he suggests.


#6

Thanks. This is what I am looking for.
Do you have an example? :roll_eyes:


#7

Try this:


Given the language of your messages in your original piston, I suspect your telephone numbers may be of a different length than mine. After you put in your numbers, also edit the phoneNumberLength constant to match the length of one phone number.


#8

Thanks a lot!


#9

Here’s a slight revision which guxdude helped me out with. It turns out that the arrayItem() function will work on a comma-separated string as if it was an array. So my fancy stuff with the mid function isn’t needed and the phone numbers can be any length or even different lengths. I added in another string so the message can call each entity by name. Here is the revised version:


#10

I did get one thing wrong:
You need to change $device to $currentEventDevice in all 3 If {$device} is equal to… statements. Otherwise it will send every message to everyone in the list.
Oops.


#11

A little late but for future reference you could just say

deviceIndex=indexOf(allDevices,$currentEventDevice)

This avoids the loops and goes straight to the device of interest.