Piston design - Nested Pistons or individual executions?


#1

What is the consensus in Piston design when it comes to executing commands?

For example, I have a Piston that is used to manage user presence and change the location mode of the home, such as:

Now, I want to add actions to occur when I’m away. For example, our dogs stay in the basement. Therefore, if it’s after sunset, I’d like two of my 4 basement lights to turn on. For something like this, would you simply add that action directly to the piston? Or would you create a second piston that took care of this and inside of my away piston issue an “Execute Piston” and point to it?

Thoughts?


#2

Personally. Half a dozen of one six of the other. However, sometimes, depending on complexity it is better to compartmentalize yourbpistons for troubleshooting. Just my two cents


#3

Thanks for the input. In this case, if you did a sub-piston, it should just be an action based piston, correct? There’s really no point in doing another conditional check, is there? I feel like that would be wasting execution time, or am I missing something?


#4

As a personal rule of thumb I tend to use a separate piston if there are a set of actions I want to reuse in more than one other piston. Otherwise I typically place the actions directly in the main piston, even if it becomes more complex. That said there’s always an exception to every rule!


#5

True


#6

Yeah, I’m a fan of reusing things as well. So if there are multiple ways that the same action is going to be called, I will put the actions in their own piston.

That said, for my setup I have a single piston which changes my house into the 5 different modes I use as the day goes on. Then as the mode changes that piston makes a call to the sub piston where I have all my home/away logic. To me this seemed more logical…and I can put the code in the sub-pistons for exceptions like when there are guests or if it’s a holiday. The piston which changes the modes is very clutter free and I don’t have to touch it any more. It just hums along.


#7

@Mike1616 do you mind sharing the example of the mode piston? I’m trying to accomplish this now as each mode has it’s own piston. I’d rather have one mode changing piston and then sub-pistons as you described.

Thanks!


#8

Here you go… It’s pretty simple and basic, which is why I like it. I got the idea from someone else in the community. As I said before, in my sub-pistons I do all the heavy lifting (like figuring out if guests are over and such). I also have a separate “Presence” piston which will turn on lights when I come home if the Mode is one where I’d expect it to be dark. You can see that I have two different triggers for the same “Morning” piston. That’s so I can sleep in on the weekends. :slight_smile: