Webcore, force every block to execute

Hi,
I would like to trigger a block lets say each 5 minutes OR if a device change its state. Is there a way to put those 2 trigger together ? For now the only way seems to duplicate my block or to use another piston like every 5 minutes run the piston and an event with the device that trigger the same piston... But before to change anything I would like to know if its possible. Maybe a great feature to add to be able to merged different trigger with or conditions...
Thanks!

1 Like

I've run into something similar. I wish you could define and name action blocks so they can be called from other parts of the piston. Basically like an anchor in HTML, GOTO in Basic or void function in C+.

Maybe the easiest way to do it is to call an action-only piston from a separate triggers-only piston. I have "Open Garage" and "Close Garage" pistons that have no triggers. They just open and close the garage. Then I can call those from different pistons in whatever way I need. Just make sure you change the action-only piston to Never Subscribe to trigger events. That way it will only run when it's called.

Maybe others have more insight...

thanks for reply! That was exactly what I though right after publishing the post, a kind of block to call (goto would be more for condition only piston since event or every block are considered appart, like a piston inside the piston...) but would be nice! Or like condition, we could have an add event to the block.
The other way I found to stay with the same piston is to use a global variable and use an event on it. If the global change, do something. so with the every loop you just set the variable to 1 and at the end of the block set it back to 0 for example. and with the device event you just do the same...
It takes another variable but not forced to have another piston.

Also, I just realized while building my reply that it could also be that the every loop call the same piston its in. Since as I said that the block is appart, it wont run by running the piston, it would only run the conditions block. So maybe it would be a way to use every block to call the actual piston to run and a device event that also trigger the actual piston. But the piston must be dedicated and not have any other condition that should not run until other event or other trigger.

You can at the top of the piston set variables for what you want to happen based on triggers, then below that just evaluate your variables for what to run.

You likely won't use 'every' (as it is its own block that exits), but you could have a variable for when next to run.

You can put into the end of the piston the triggers

ie

Time happens daily at a time,

or Date & Time happens daily at variable

See:

1 Like

yes, the variable could be local... another good ideas!
Thanks!

I've been using this technique since SmartThings, only I refer to and name them as SUB-ROUTINES (from my old programming days I guess). :slight_smile:

1 Like

That's it! I couldn't remember the term.

1 Like

thanks for all those ideas!
Is there a chance that multiple event capability will be added to webcore if the request is made? we can select multiple devices from event, why not multiple event type, like every 5 minutes OR switch1 event DO... ?
Have a nice day!

Maybe I'm coming into this discussion late, but you can do exactly what you want today. You would do something like this:

execute
Every 10 min
do
nop
end do
end every

if switch changes to ON
do
nop
end do
end if

do
now do something based on either of those triggers happening. But you may have to be careful since this do will execute when the switch turns on and when it turns off. So you may need a local control variable to tell this do when to execute and when to ignore.
end do

end execute

Yes, I know that but the goal is to not have the same code twice! If it have multiple lines, you then have a very long piston and if you want to change something you need to modify those 2 events…
If we could mix multiple events we could then have actions only one time without repeating!

That’s why the other post suggests to run a different piston (or same piston with variable) because the piston contains only one time those actions and could be run multiple way..

It would be great to be able to do it with events directly, events are just like pistons but we cannot call them outside their trigger… or mix them..
thanks for your reply!

Every blocks only execute the specific block then exits

ie it is not a start to finish run of the piston...it is more like a mini-piston within a piston.

See:

Yes I already know, the point is that it would be more efficient to be able to mix those trigger like :

Every 5 minutes
Or
On event from switch
Do
End

So, single block and multiple trigger… or like said, the ability to name a kind of block and make it run like any action..

I ll do it separately but would be a great improvement…

you should use if time happens to have a time event with full piston runs.

Yes, could be a way, I ll check if it works to merge it within the event… sometimes it works but I would need to store time inside variable and update it 5 minutes later at the end of execution..
Thanks

Oops, sorry for the wrong-way detour.

Ok! I just found, its linked with latest reply @nh.schottfam , I just used if condition at the place of events. The trigger within the conditions allows for daily at time and can be merged with or switch changes… so I just create a variable (must be time variable) and set it first time to now + 5 minutes .
After that I just need to set the time variable to now + 5 minutes again…
So, each 5 minutes it run and if a change occurs with the switch… (ideally the switch should not set the time…)
Thanks again for all those ideas!