Launch/trigger a piston from another piston

I’ve got a handful of contact sensors and a handful of status LED arrays around my house, and I’ve got CoRE set up so that, if the front door is open, then LED #1 on all of the arrays is lit, etc. Like so:

  • Front Door Open -> Light LED #1 on panels 1, 2, 3, 4
  • Front Door Closed -> Extinguish LED #1 on panels 1, 2, 3, 4
  • Kitchen Door Open -> Light LED #2 on panels 1, 2, 3, 4
  • Kitchen Door Closed -> Extinguish LED #2 on panels 1, 2, 3, 4
  • etc.

The problem is that I have five contact sensors, which is ten pistons. This all works fine, but the problem arises if I want to add another LED panel; I’ll have to add panel #5 to ten pistons.

An alternative idea I thought of was using an additional piston just to update the status panels, like so:

  • Front Door Open -> Set $ledNumber=1, Set $ledStatus=true, CallPiston UpdatePanels
  • Front Door Open -> Set $ledNumber=1, Set $ledStatus=false, CallPiston UpdatePanels
  • Front Door Open -> Set $ledNumber=2, Set $ledStatus=true, CallPiston UpdatePanels
  • Front Door Open -> Set $ledNumber=2, Set $ledStatus=false, CallPiston UpdatePanels
  • etc.
  • UpdatePanels -> if $ledStatus { Light LED #$ledNumber on Panels 1,2,3,4 } else { Extinguish LED #$ledNumber on Panels 1,2,3,4 }

This way, each piston for a contact sensor can just set two variables to indicate the contact number and open/closed, and then I only have to update a single piston, “UpdatePanels”, which can update whichever panels I want (or even change the colors or re-map the LED assignments).

Is there a simple way to do this? Is this what virtual buttons are for? Or is there a better way to achieve what I’m after?

I link pistons together using global variables. So condition in piston A sets variable “@variable1” to true. Then piston B acts when it sees the variable change.

There is probably a cleaner way to write your pistons though. Maybe using case statements. Try asking on the webcore forum. I got some great help there.

The simplest way I can think of is unless each piston is overly complicated you can combine all that into one piston. I look at tit like this. A piston is defined by what it does. If I have multiple doors all doing similar things then it all goes in the same piston. by doing this you can then define variables at the beginning of the piston and just call the variables thru out your code. If you ever have to replace or add a sensor then this makes things way easier than going thru all the code line by line.

Interesting. How would I go about setting the variables? I’m currently trying to do all of this through the iPhone/iPad app, and it only seems to offer basic if/then stuff. Sure, I can create a piston which fires if “any of sensor1, sensor2, sensor3 change”, but I’m not sure how to (within the piston) access any variables which might contain the identity of the sensor that changed or what it changed to.

Are you using the old version of Webcore? I recommend the new version but you would be building your code via desktop unless they have come out with a phone version im not aware of. Here is a snapshot of one I use that has variables.

Hope that helps.