What is the value of ON vs IF and what's up with empty the ON section in some Pistons


#1

1) Give a description of the problem
I’m curious if there’s an advantage to using On {Battery_Devices}'s battery as opposed to If {Battery_Devices}'s battery changes. (Or generally the value of using On as opposed to If).
Also, I’ve noticed that several of the battery level handlers start with something like:
if {Battery_Devices}'s battery changes
end if;
every 1 hours, at :00 past the hour do
end every;
There’s nothing inside these trigger blocks. I’ve been putting the code inside the If and Every blocks. Do those empty blocks trigger and then pass execution to the code beneath it anyway?

2) What is the expected behavior?
Normally, I would expect the On or Every to only execute the code in the block.

3) What is happening/not happening?
Yet, it appears that the piston works with no code in the On or Every block(s).

**4) n/a

**5) n/a


#2

IF device changes to X
will run the entire piston from top to bottom, and execute any code that conditions allow…

Every day at X
will only execute that one block, and then stop


As far as your other question, the main time I use an empty block is if I need to force a piston to run to get a new time stored in a global variable. Although sometimes, if I need complex code to run a few times a day, I may put in a couple of empty “IF happens daily at Time” so they all trigger the code below.


#3

That’s helpful. Thanks.
Any wisdom on when to use an On versus an If? I tend to do the later, and webCoRE does note that On statements “execute asynchronously”.


#4

I do not know what you mean by “using On as opposed to If”.

Can you post a green snapshot as an example?


#5

Here you are. I note that the IF and ON both subscribe to events (one place for the IF and 3 places for the ON) so the piston should activate in both cases.
I’m just not sure if one is preferable to the other.
The ON version updates the piston state much more often than the IF version. I’m not sure why.


#6

In most cases, I use “IF”.

That being said, when checking battery levels, I do not use either. I use a once a day piston to send me the information I want. I definitely do not want every single battery change to notify me!!


#7

Thanks. Actually, it only notifies me if a battery is below the low threshold. It does update the piston state and log at every battery change though. Since I’m prone to panic on battery levels, once a day would be good enough.


#8

Yes, but once this happens, the pistons above will spam you until you change batteries, LOL


#9

Ah. Good point. I don’t want much Spam in it. :grinning: