How are pistons executed?


#1

This is not a problem but a question of how pistons work.

I see a lot of information on creating your first piston, but I am trying to figure out the execution. Obviously there is an engine created by webcore within ST as a central queueing and execution process (simply stated).

I have seen that pistons can be fired from routines which would indicate that that piston is not being evaluated but rather there to be fired. Another thing I am seeing that the condition is being evaluated before the subsequent piston code is continued. That indicates that the piston is ā€˜runningā€™ constantly (a certain period) and looking at existing conditions to continue the code. That would imply that this is an ā€˜activeā€™ piston looking to run rather than ā€˜inactiveā€™ waiting to be called. Obviously, IFTTT could and probably does exist in both types.

an option is to put in ā€˜waitā€™ that could be in either type of piston and put it in a queue that periodically would be checked to see if that wait time was up.

If the two types (active and inactive) exist, how do i set this up?


Piston executes from top to bottom?
#2

Have you see this thread?

Also, if you want a piston to not react to events generated by devices, then set the subscription method to never. You can then just call on that piston from another piston like an ST routine.


#3

Pistons donā€™t periodically check timers or periodically check conditions.

They subscribe to specific times defined by the piston, and they subscribe to device event notifications, and respond accordingly when the time is reached or an event comes in.


#4

This is personally the way I like to think about them.

You can make pistons which are Event based. That is when an Event happens the piston fires. Such as you come home, the lights come on. Therefore you make a piston which subscribes to the Event of your presence sensor changing to ā€œpresentā€. Then the actions you do are to turn on the lights. This is a very IFTTT type of setup. If this (or this and this but not this) then do that. :slight_smile:

However, you can also make pistons which do not subscribe to any events at all. You can just have pistons that only perform actions and do not have any Triggers in them. You can specifically modify the settings of a piston to turn off all event processing. I do this with several of the pistons that I have and I ā€œcallā€ those pistons from other pistons while passing some ā€œargumentsā€ to them so that they can take action when a different piston Triggers them.

But ultimately something is making a piston run. Whether that is Time or an Event. Otherwise they donā€™t do anythingā€¦


#5

My advice here is to ask a more specific question. What do you want to doā€¦ Weā€™ll then tell you the best approach to accomplishing that goal.

Youā€™re right, thereā€™s a lot to learn with WC, but itā€™s easier to do with some concrete examples rather than with some abstract concepts (trust me on this one). :slight_smile:


#6

Hi, there.

Iā€™ll take you up on your suggestion. :slight_smile:

Iā€™m trying to create a piston that will turn on all my lights 15 minutes before sunset. I want to turn off the lights at different times, depending on the day. For example:

Monday - Friday at Midnight: Turn off Coach Light - Front Door, String Lights
Saturday and Sunday at 2 AM: Turn off Coach Light - Front Door, String Lights
Everyday at 5 minutes after sunrise: Turn off Coach Light - Left, Coach Light - Right

I thought the code Iā€™ve attached would do it, but it didnā€™t.

This is what I see in regards to when it last ran:

Last executed: 11/14/2019, 7:00:59 AM
Next scheduled: 11/15/2019, 7:02:00 AM

Here is my code:

Any help is greatly appreciated - thanks in advance!