First Piston - simple presence test


#1

Noob here trying my hand at my first piston. Here are my parts: 2 smartphones set up as presence sensors and a switch that controls a hot water circulating pump. I have set up an automation in Smartthings to turn the pump off at 10pm. I want a piston to test the presence of the smartphones beginning at 4:15am and turn the pump on if either smartphone is present but turn the pump back off when both are not present (when we leave for work). Then turn the pump back on when either of us return from work. Sounds simple, but I am having difficulty getting started with the overall learning curve.


#2

Hi @Kcrane
Something like this would be a start:

IF time happens daily AT 04:15
 AND
IF any presence Sensor 1, sensor 2 is present (either one is home)
 then 
Turn on switch

IF  presence sensor 1 CHANGES TO not present (One is leaving the other already left)
 AND
IF presense sensor 2 is NOT present
Then Turn OFF switch

IF  presence sensor 2 CHANGES TO not present (One is leaving the other already left)
 AND
IF presense sensor 1 is NOT present
Then Turn OFF switch

IF any presence sensor 1, 2 changes to ON (one of them back home)
 Then
Turn ON switch 1

The diffuculty is presence sensors can only be TRIGGER with “CHANGES”
I believe this should work well…


#3

Thank you for the guidance. Does this piston constantly monitor the status of the presence sensors, or do I have to set up some sort of loop to periodically check the status of the sensors?


#4

Well it’s a tricky one ;)))
it does and it does not:)

Meaning, your sensors are connected to the Webcore. So, any changes are reported back. BUT with the presence sensor, the delay can be up to 2-3 minutes sometimes. The good part is, your piston doesn’t have to execute every minute. It only executes when a change happens.

If you want your piston to check on the phones constantly, you can use timers.

Execute
TIMER( every minute)
 do 
 IF any sensor is NOT PRESENT
 then
do this do that

With this approach your piston will execute every minute and check to see what phones are doing.

Coders/Minions can explain better but I am not a big fan of executing a piston every minute.
Here is an example:)
without timer - You are waiting for some amazing news. You make sure your phone is at reach and volume ON. You wanna be able to answer as soon as they call.
With timer - Every 60 second you call them to see what happened.

I use timers but ussualy for something like,
every day at 6:00pm (it executes only once a day)
or
Every 30 minutes (it executes once every 30 minutes)

Maybe your system can handle it but my house is overloaded as is (almost 300 devices with over 100 pistons) so in my case queiter the better:)))


#5

This is how I have coded the piston based on your suggestions. Does this look right?

//
/* Recirculating Pump Timer */
/
/
/* Author : Kent /
/
Created : 1/31/2019, 1:44:54 PM /
/
Modified : 2/8/2019, 8:39:44 AM /
/
Build : 8 /
/
UI version : v0.3.109.20181207 */
/**************************************************************/

execute
if
Time happens daily at 4:15:00 AM
and
(
Any of His Phone’s or Her Phone’s presence is present
)
then
with
Recirculating Pump
do
Turn on;
end with;
end if;
if
His Phone’s presence changes to not present
and
(
Her Phone’s presence changes to not present
)
then
with
Recirculating Pump
do
Turn off;
end with;
end if;
if
Any of His Phone’s or Her Phone’s presence changes to present
then
with
Recirculating Pump
do
Turn on;
end with;
end if;
end execute;


#6

can you pls share the green snapshot of your piston…
this format impossible to understand.
I believe you have two triggers in a single IF which will almost never execute.


#7

Sorry, I wasn’t sure how to get the image in the reply.


#8

Yes as I suspected, line 31 and line 34 are both triggers. Which means, it can ONLY be TRUE if you left home at the same time AND if both your sensors reported AT THE SAME EXACT MOMENT… which will never be the case:))

Thats why you need to use A TRIGGER and foloowed by A CONDITION

IF  presence sensor 1 CHANGES TO not present (One is leaving the other already left)
 AND
IF presense sensor 2 is NOT present
Then Turn OFF switch

IF  presence sensor 2 CHANGES TO not present (One is leaving the other already left)
 AND
IF presense sensor 1 is NOT present
Then Turn OFF switch

OR
You can use a timer. lets say checking the phones once every 60 minutes maybe?


#9

Got it. I’ve made the changes you suggested and I understand your point. I’ll be able to test it out next week. I am learning a lot with this project. I appreciate your help.


#10

My pleasure…
Let us know how it goes…