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