Simplify an arrive/ leave piston

conditions
holiday
triggers

#1

1) Give a description of the problem
Is this just to complicated to run consistently, if so is there a way to simplify

2) What is the expected behavior?
trigger home, evening, night, away or work from home depending on conditions also have a guest fob for when we are away on holiday

3) What is happening/not happening?
think its working but seems to complex for what its doing

4) Post a Green Snapshot of the pistonimage
posting red as no sensitive data and to make it easier to read

5) Attach any logs (From ST IDE and by turning logging level to Full)
N/A


#2

Think I have simplified it a bit more myself but im sure they must be a easier way.


#3

Hereā€™s my global advice on this oneā€¦ Any time youā€™re using the exact same lines of code in any program more than once, youā€™ve got an opportunity to completely eliminate all of them but the first one.

So for example, these statements which are completely identical could be evaluated ONCE at the beginning of the piston and then the result could be stored into a Boolean variable.

Then rather than making this same comparison over and over again you just have a simple IF statement like this:

define boolean SomeoneCameHome

Make all your checks and then stuff the result into the variable

IF SomeoneCameHome is True Then

The other thought I have is if you have multiple ways for the same eventual thing to be true then rather than duplicate the same actions in this piston, call an external piston and put all the actions in it. Much like you are calling routinesā€¦just call another piston.

But it does seem like you need to take a step back on this one and think about it from the perspective of, what triggers are going to cause an action to happen. Check for all of them at the beginning and if they are all true then do those actions. However, if there are actions which are only going to be done for one person and no one elseā€¦then thereā€™s nothing wrong with moving that one person out to their own pistonā€¦and then again you can call the common stuff in a separate piston as needed.


#4

I have this for me and the guest fob, will give it ago thanks for your help :grin:


#5

Just realized I donā€™t know how to do this, is it just

If X or Y presence changes to present

Then set variable SomeoneCameHome to true


#6

Yep, thatā€™s essentially it. Take a look at the post that I just made in the examples section. I go over many things which you might find helpful.


#7

been on my holidays so only just got chance to re work it. So I think I have it but wanted to get it checked for obvious stuff before i unpause it. Should this work @Mike1616


#8

OKā€¦here are my thoughts in general.

Iā€™m not a fan of having the same trigger in one piston multiple times. So in this one Line 26, 42 and 51 all have the same trigger in them. if you want to know ā€œwhoā€ came home so you can do different things, then look into using currentEventDevice.

I think on lines 93 and 95 the use of ā€œchangesā€ could be a problem. Might need to be ā€œisā€.

On line 115 and 117, are you trying to detect ā€œchanges to not presentā€ as a trigger, or ā€œis not presentā€ as a condition? Because right now it looks like WC is using it as a condition. Which would mean that it would not kick off this piston when that happens.


#9

seen and used this before in backup pistons but canā€™t work out how it works?

good catch

Edit:

I thought that but I think because its it its own IF it does work (this is how I have it on my existing piston) I seem to remember something about if there is no triggers then conditions trigger or something :thinking:


#10

Thereā€™s an example. Itā€™s just a string variable with the name of the device in it.


#11

Thatā€™s how/ what iā€™m using it for on another piston. So does currentEventDevice just take the one that triggered? and because you have asked for presence changes to present, that is what it will take from it, ie presence sensor 1 is now present?


#12

Itā€™s a system variable that will contain the friendly name of the device that triggered the piston.

So if you have a command like this:

IF ANY of Lauraā€™s phone, Peteā€™s phone or Jackā€™s Phone changes to present

And letā€™s say ā€œJackā€™s Phoneā€ (which is what youā€™ve chosen to name the device) is the one that triggers the event.

Then the value ā€œJackā€™s Phoneā€ will be put into the variable $currentEventDevice

Which would then mean you could write an IF statement like this:

IF $currentEventDevice is equal to ā€œJackā€™s Phoneā€ then do thisā€¦

That saves you from having to retest for your trigger over and over again.

If you wanted to take it one step furtherā€¦you could likely even do something like this in an expression (I have not tested thisā€¦but it should work).

IF [$currentEventDevice:presence] == ā€˜presentā€™ thenā€¦


#13

Think i have seen this before im assuming this would exaluate as long as one of them is present (great for the overall present)
Then I could use

for when I want to check for a particular person?


#14

Yeah, a presence sensor can be either ā€˜presentā€™ or not present. So thatā€™s how youā€™d know if the device which triggered the event came home or left. So if you need that type of logic statement use that.

And yes, when you want to check for one particular person (device) from a listā€¦youā€™ll know which one it is by name. Or maybe sometimes you donā€™t even care about the nameā€¦you just want to do the something to the one which was the trigger.

Meaning you could write a piston like this:

IF any of Light1, Light2, Light3 or Light4 changes to to on
with $currentEventDevice
set level to 50%

Thatā€™s much simpler than:

IF Light1 changes to on
with Light1
Set level to 50%
Else if Light2 changes to on
with Ligh2
Set level to 50
and so onā€¦


#15

ok think I have it ?


#16

Looking good. I wonder why this line is not a trigger.

image

Seems like it should be. But thereā€™s no little lightning bolt next to it which is the usual indicator.

My concern is that where this is in the piston, if it is not a trigger, then it relies on someone else coming home before this will ever activate.

Iā€™d do some testing around that and make sure it works the way you want it to. If it does not then perhaps youā€™ll need to flip the order around. Or make it in an IF block unto itself rather than an Else IFā€¦unless you mean for it to work that wayā€¦


#17

Good spot, it should be. Iā€™ll move it to its own if then it should work.


#18

i moved it but still no lightning bolt should this cause a issue?


#19

Not sureā€¦but maybe try flipping the order around so that this one is first.

image


#20

yep that did it

iā€™ve started to use it now to try and test it out so fingers crossed it works smother