How to run a few near-identical pistons with slightly different devices each time


#1

1) Give a description of the problem

I’d like to lean the best way to make this piston work, instead of having to do lots of unnecessary duplication please. I suspect this is an easy thing to do, but I’m lacking knowledge

2) What is the expected behaviour?

This piston works just fine…

image

… but the issue is that I need to run this for a number of times, replacing the target radiator, the target boost switch, and the LED.

Fairly sure there’s a better way than having multiple pistons of a great big long one.

3) What is happening/not happening?
n/a
4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
n/a

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Just a quick thought. You could use variables and just call your main piston each time, passing the appropriate variables. You could even automate it with an Alexa routine.


#3

Hmm 3 device list variables and iterate? Same number of devices for all three?


#4

Yup


#5

Sounds good. Could you show how please? I attempted something with $args and failed miserably :grin:


#6

currenty stuck fast, here… attempting to use array / iterate and convert the top into something that repeats

Note that I used the 'expression] approach for boosts due to device list always being alphabetical, which would go south with arrays.


#7

Do you ALWAYS want to adjust ALL of your radiators at the same time? Or do you want to do them individually and randomly?


#8

it’s the easiest way to check/adjust the status of each of my led’s on a panel.

Piston runs on certain triggers, and just checks the status of all and alters the leds to reflect that.

Each room has a boost and a couple of leds.


#9

No joy on this I’m afraid.


#10

I have been working with this in an attempt to create and access a 3X3 device array. I’m not sure it is possible. OR, I just cannot get the syntax correct to access the device attributes (switch status). Someone here smarter than me may be able to do it. But I could not. I would just iterate as @eibyer has said. I would use temporary device variables. Define your three arrays as you have (LED, rads, boosts). Also define 3 temporary variables as below.
I don’t know the attributes of your devices so that may need modification below.
I have not tested this!

Device Temp_Rad
Device Temp_Boost
Device Temp_LED

For $index = 0 to (NumberOfRadiators - 1) step 1
  Set variable Temp_Rad = arrayItem($index, rads)
  Set variable Temp_Boost = arrayItem($index, boosts)
  Set variable Temp_LED = arrayItem($index, LED)
  If [Temp_Rad : switch] is on
    Then
      If [Temp_Boost :switch] is on
        Then
          With Temp_LED
            Turn On
            Set color to Red
        Else
          With Temp_LED
            Set color to Orange
            Turn On
END For

#11

Thanks for that, I’ve never used arrays. Looks awesome, I appreciate the time =)

At work at the minute, so I’ll give it a crack when I get back. Thanks!


#12

@Pantheon

Sorry, tried and fell at the first hurdle. Attempted to set up a for loop but immediately hit an error about $index. Any chance of a piston import code to get me going please? Can’t get my head around some of these functions I haven’t used before - I tend to stick with fairly bog-standard webcore scripts.


#13

This might help see how I use arrays. This piston is a standard piston to handle turning on lights when a sensor is activated. All lights/sensors are defined in the arrays at the start, so if you add more, you just add to the variables.

I wrote this when I was new to webcore, and where if shows the power of webcore, I’m not sure its the best way to go.


#14

I don’t have the devices that you have of course. I set mine up with light switches around my house. But the design is the same. I used a flashing light in my computer room to test. It seems to work.


#15

cheers @Pantheon & @Paul1964 , that looks ace. I’ll take a peek in a bit.

Ideally I need one piston that runs a check (no triggers, seems to be covered by @Pantheon’s above), and another which is fired by triggers.

Bit of a rabbit hole, as always :smiley:


#16

ok, sorry guys, work/kids.

Managed to get this working, and incorporated a few other bits.

Bearing in mind I’m still learning (obviously!), I get the feeling this could be cut shorter.

Any assistance, as always, much appreciated.