Using a global variable to temporarily stop push notifications


#1

1) Give a description of the problem
I have a piston that sends a push notification when someone changes a thermostat’s temperature. I also have pistons that automatically set the temperature when I leave or when it’s a certain time of the day. These also send push notifications (e.g., “Temp was set to 60° because you left”). The end result is I get two simultaneous notifications, one when the piston sees the setpoint change and another notification generated by the piston that initiated the change. I don’t want two notification so I tried to use a global variable to determine whether or not to send the notifications from the piston that reacts to any setpoint change. I thought I could create a piston that would set a global “sendNotification?” boolean variable to false, change the temp when my presence changes to away, and then set the "sendNotifications? boolean to true. Of course, this didn’t work because the pistons don’t run at the same time. So the sendNotication flag gets set to false, the temp gets change, the sendNotification gets set to true and then the other piston that watches for setpoint changes runs and the sendNotification flag has already been set to true again and it generates a “setpoint was changed” notification.

Has anyone found themselves with a similar need and successfully addressed it?

2) What is the expected behavior?
I want to somehow have a piston tell other pistons not to send a push notification under certain circumstances.

3) What is happening/not happening?
I can’t figure out the logic needed to temporarily tell other pistons to not send notifications.

4) Post a Green Snapshot of the pistonimage
Here’s what I tried. It wasn’t working and after a “Doh!” moment I realized why.

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS)


#2

Never mind, I figured it out.


#3

Let everyone know what you did in case it helps someone in the future. We are all learning here.


#4

There’s probably more concise ways to do this, but here’s what I came up with:

I have a piston that sends a push notification when someone adjusts my thermostat’s temperature. This piston reacts to a change in the thermostat’s setpoint and sends a “Thermostat’s temp was just changed to…” message. I also have pistons that turn down the heat at 11:00 PM or when I leave the house. These send their own push notifications. Which meant I was getting two notifications, one from any piston that changed the setpoint (i.e., turn the heat down when I leave) and a second notification from the piston that reacts to any setpoint change. I needed a way to send a push notification only when a person adjusted the thermostat but not when a piston made the change. The solution turned out to be simple.

I created a global variable called sendSetpointChangeMessage. Any piston that makes a change to the thermostat’s setpoint sets this flag to false before it adjusts the temperature. After one of those pistons runs, the piston that watches for any change in the setpoint runs because it sees the setpoint was just changed. That piston checks the sendSetpointChangeMessage variable to see if a message should be sent. And because the piston that changed the temperature set the flag to false, a second message isn’t sent and I only get a message from the piston that actually made the change. The last thing the piston that reacts to any change in the setpoint does is set the sendSetPointChangeMessage back to true so I get a message if someone messes with the thermostat. And the next time a piston runs that adjusts the temperature, that piston sets the “send notification” flag to false, and the second pistons runs, sees a message shouldn’t be sent, and then sets the flag back to true. And round and round we go.

Set the notification flag to false:

Check the notification flag to see if a push notification should be sent. Reset notification flag to true:

Edit: If there’s a better way to do what I’m trying to do, please feel free to comment.