Combine names of people in same location


#1

1) Give a description of the problem
I have a piston that tells me where each family member is. I’d like to add a section that combines all those members who are in the same location.

2) What is the expected behaviour?
Instead of “X is at home, Y is at home, Z is at work.”, I’d like it to say “X and Y are at home. Z is at work.”

3) What is happening/not happening?
Each person is stated separately.

**4) Post a Green Snapshot of the piston.


#2

This is just an example of what you’re trying to accomplish. Line 19 is what I edit to simulate the number of ‘people at work’. Your existing piston can stuff all the “people at work” in the whoWhere variable then the rest of the piston should output the rest of the info you want in the variable message. This can probably be optimized more, just first thing that came to mind.

These are example outputs of what I set in Line 19

11/27/2019, 4:02:51 PM +481ms
+180ms	║Billy and Bobby are at work.

11/27/2019, 4:04:27 PM +741ms
+212ms	║Billy, George, Mike, and Susan are at work.

11/27/2019, 4:03:32 PM +14ms
+198ms	║Billy is at work

#3

That’s pretty nifty! Did you already have something like this, or did you just come up with it?

I guess I’ll need to figure out what to do with people that are elsewhere. Do you have an import code?


#4

I just tried it today, and yes I’ll post the import code in the morning when I get to a PC.


#5

Thank you. :slight_smile:


#6

Very slick. I did a similar thing but building up the list based on array of devices using a for each loop. I like your trick though to avoid loops.


#7

I was considering that, but it occured to me that I might get multiple identical messages (if 3 people are at same location, it would say, “X, Y and Z are at Location” three times) because each of them are checked in the loop. I couldn’t figure out how to exclude the remaining folks.


#8

I use the loop to put together a string which the message and then just send it to echo speaks at the end so I always get only one message.


#9

Which makes sense…but if the loop is checking 3 people’s locations, what keeps it from doing this:

Check if X is at same place as Y and Z. Answer is Yes, so message = “X and Y are at A” (Check with Z is no)
Check if Y is at same place as X and Z. Answer is Yes, so message = “Y and X are at A” (Check with Z is no)
Check if Z is at same place as X and Y: Answer is No, so message = “Z is at B”

This would give you “X and Y are at A, Y and X are at A, and Z is at B”, unless you can remove Y from the loop since it matches X. Does that make sense?


#10

Here it is, a little late :slight_smile:


#11

Sorry, I have a variable, stuff it with all the people at a certain place, do the loop to create the sentence and then move to the next place. No duplications.