Multiple device status changes: group notifications


#1

1) Give a description of the problem
When two switch devices (which actually represent presence) switch off at the same time (or within a few seconds of each other), I’d only like one notification listing both devices to be posted. How can I make the notification wait for a few seconds to gather other matching devices?

2) What is the expected behavior?
Only one notification is posted in my Smartthings notification list.

3) What is happening/not happening?
It’s currently posting an individual notifications for each device that changes.

**4) Post a Green Snapshot of the piston![image|45x37]


#2

You can add another boolean variable, notified initially unset.

Add another condition after Any of...

Variable notified is false

Ater your Send notification task, add
Set variable notified = true
Wait X seconds
Set variable notified = false

X = number of seconds for cooldown

I think that would do it… let me know if you have any questions.


#3

Thanks for the advice. I’ll test this out a bit later today though, with my current setup, wouldn’t this still replace {wholeft} with the mostly recently changed device (as opposed to appending other devices that switched within a minute to the same variable)? Pretty new to this and trying to understand how variables work in this way.


#4

It will replace the contents of wholeft variable but it won’t send notification again. If your end goal is to keep a list of the people who left, I’d suggest using is off instead of changes to off, changes to off will only store the device that triggered the event.


#5

Thanks again. Ideally, I’d only have a list of all of the devices which switched to OFF within a minute of another device switching to OFF, in a single notification - as opposed to a list of all of the devices which were already off. Basically something like:

IF ANY PRESENCE DEVICE CHANGES TO OFF
SET notified VARIABLE TRUE
THEN
IF notified VARIABLE CHANGES TO TRUE
WAIT 60 SECONDS
THEN IF ANY PRESENCE DEVICE CHANGED TO OFF WITHIN THE LAST 60 SECONDS
SET MATCHING DEVICES TO devices VARIABLE
SEND NOTIFICATION" {devices} left home."
SET notified VARIABLE FALSE

The one thing I can’t figure out is how to configure this: “THEN IF ANY PRESENCE DEVICE CHANGED TO OFF WITHIN THE LAST 60 SECONDS”

Any suggestions?


#6

I just tried adjust to this:

Any reason this won’t work?


#7

Hmm, do you want the wholeft variable to reset to empty after a minute of the first departure? Also, when do you want to send the notification if there’s more than one departure within the minute?


#8

Here’s my interpretation of what you’re trying to accomplish…


#9

I want the notification to be posted within one minute after any device changes to off. I want there to be a notification for any and all devices that have switched off within that minute.

While testing my implementation above, one device left at 6:13p while another device left at 6:17p. Only one of the notifications was posted though (the 6:13 event). Any ideas why? I may update the timer to allow a longer grace period but why wouldn’t my second device have a notification posted?

Would your implementation solve that? I assume in Line 22, I’d have it save matching devices to variable who left? What does “Log debug” actually do here?


#10

In my piston example above, I’m manually saving the device names to the variable, there’s no need to add the ‘save matching devices to variable’.

You can change the Log debug to Send notification, I just used Logging to console for testing so the phones that have ST installed don’t get the notification while I was testing.


#11

What does {count(wholeft)} is 0 actually mean?

I see/understand that it sets the variable to the triggering device.Then, it waits 60 seconds - where/when does it update the variable to include new devices?

Does this limit to only 2 devices leaving at the same time? What if all four leave at the same time?

Sorry I’m feeling really new to these advanced pistons.


#12

count(wholeft) is 0 checks to see if a device has already left (counts the number of devices in wholeft). If none, then it saves the current device to wholeft, waits 60 seconds, sends the notification, then clears the variable.

If there’s already a device in wholeft, it will append the name of the next device to the list, waits another 60 seconds, then sends you the notification that the two devices have left. If another device leaves within the 60 seconds, it cancels the timer, appends that other device to the wholeft variable then waits the 60 seconds again and so on…

Oh and not limited to two devices but the way I have it set up, it adds another 60 seconds when another device gets added to the device list.


#13

Thanks for the explanation. I’ve tried this out and at first, it seemed to work, so I created a second piston that handles arrivals the same way. My two Pistons are below:

The notifications appear to be grouped appropriately but for someone reason, if any people leave, I get two notifications in this order:

Switch 1 and 2 left.
Switch 1 and 2 are home.

If anyone arrives, I get two notifications in this order:
Switch 1 and 2 are home.
Switch 1 and 2 left.

Am I missing something completely obvious? Should these Pistons be combined into one? Please let me know what other info I can send to help.


#14

Turn on full logging and paste it here so we can check out what’s going on. By itself, the pistons look ok to me but I could be missing something also. Maybe after my coffee kicks in I’ll see it :slight_smile:

Edit: I see my error on the piston I gave you, let me see if I can fix that.


#15

Try this one. Also click the Reply below my post on the right (not the blue one) when replying to me so I will get notified.


#16

Thanks for working with me on this. I used your new piston, though this time when I click Test, it doesn’t appear to set the “wholeft” variable to Home appropriately.

6/9/2018, 11:45:43 AM +719ms
+0ms ╔Received event [Home].test = 1528559143718 with a delay of 1ms
+107ms ║RunTime Analysis CS > 21ms > PS > 59ms > PE > 26ms > CE
+109ms ║Runtime (41280 bytes) successfully initialized in 59ms (v0.3.104.20180323) (108ms)
+110ms ║╔Execution stage started
+135ms ║║Condition #4 evaluated false (19ms)
+136ms ║║Condition group #1 evaluated false (state did not change) (20ms)
+150ms ║║Condition #18 evaluated false (12ms)
+151ms ║║Condition group #17 evaluated false (state did not change) (13ms)
+153ms ║╚Execution stage complete. (42ms)
+155ms ╚Event processed successfully (154ms)

One thought: shouldn’t there be another check after line 27 to determine whether or not that statement should stop (meaning, that line 38 should happen instead of line 28)?


#17

I need to rethink this one and probably have to combine it with the arrival. Reason being is when the device switches to on, it will also cancel the timer.


#18

Shouldn’t something like this prevent restarting/cancelling the timer? Clicking Test still doesn’t populate the variables though for some reason…


#19

Made a slight modification, though the issue still appears:

6/9/2018, 2:26:21 PM +391ms
+1ms ╔Received event [Home].test = 1528568781391 with a delay of 0ms
+109ms ║RunTime Analysis CS > 14ms > PS > 42ms > PE > 52ms > CE
+111ms ║Runtime (40894 bytes) successfully initialized in 42ms (v0.3.104.20180323) (109ms)
+113ms ║╔Execution stage started
+136ms ║║Condition #4 evaluated false (17ms)
+137ms ║║Condition group #1 evaluated false (state did not change) (19ms)
+143ms ║║Comparison (boolean) false changes_to (boolean) true = false (0ms)
+144ms ║║Condition #26 evaluated false (4ms)
+145ms ║║Condition group #21 evaluated false (state did not change) (5ms)
+147ms ║╚Execution stage complete. (35ms)
+148ms ╚Event processed successfully (148ms)


#20

Just one more update. This is my “Arrival” version of the piston.

Clicking Test doesn’t work for this either, though when using the actual device - it seems like it’s doing something more. However, no notification was actually posted.

6/9/2018, 3:04:42 PM +277ms
+2ms ╔Received event [SWITCH2].switch = on with a delay of 229ms
+114ms ║RunTime Analysis CS > 18ms > PS > 68ms > PE > 28ms > CE
+117ms ║Runtime (40709 bytes) successfully initialized in 68ms (v0.3.104.20180323) (114ms)
+117ms ║╔Execution stage started
+134ms ║║Comparison (enum) on changes_to (string) on = true (0ms)
+136ms ║║Cancelling condition #4’s schedules…
+137ms ║║Condition #4 evaluated true (15ms)
+138ms ║║Cancelling condition #1’s schedules…
+138ms ║║Condition group #1 evaluated true (state changed) (16ms)
+144ms ║║Comparison (integer) 0 is (integer) 0 = true (1ms)
+146ms ║║Condition #9 evaluated true (4ms)
+146ms ║║Condition group #17 evaluated true (state did not change) (6ms)
+148ms ║║Cancelling statement #2’s schedules…
+154ms ║║Executed virtual command setVariable (3ms)
+159ms ║║Comparison (boolean) false changes_to (boolean) true = false (0ms)
+161ms ║║Condition #21 evaluated false (3ms)
+161ms ║║Condition group #18 evaluated false (state did not change) (4ms)
+163ms ║╚Execution stage complete. (46ms)
+164ms ╚Event processed successfully (164ms)