Simplify piston with many light zones


#1

I’m not a programmer and I’m having some difficulties simplifying my pistons.
I have quite alot of smart bulbs and z-wave switches in different zones and I would like to shorten my piston and make it easier to maintain.

Can someone help me create the right variables?
For instance, today my pistons says: If device Virtual_Switch1 is turned on then with Bulbs_Zone1 turn on.
Can I have something like: If $VirtualSwitch is turned on then with $Bulbs_Zone turn on? How can i create the correct variables / device groups.

I would really appreciate any help


#2

what is the use case? looks like the piston syncs the switch of each group of bulbs to a device in the virtual variable, but why? what’s the purpose of doing so?

btw, there is no device variable called virtual_stue5.


#3

I have Philips HUE bulbs and I’m using tiles, z-wave switches, the HUE app or HUE switches to turn them on and off. All the different light zones have three or more bulbs, and I’m using a virtual device to control the different zones. If the bulbs is turned on with the HUE app or switch, I need the virtual device to turn on.

Yes, I removed some variables before I posted here and remove virtual_stue5 by mistake. The original piston is quite long and with alot more devices.


#4

there may be a way couple of ways to simplify this piston.

  1. will make the code much more streamlined but there will be need for repetitive group of variables and small code blocks, though the piston will likely end up being much more smaller than it is now.
  2. will make the maintenance of the code much simpler but the code will be a bit more complex. there will be a need to setup a couple of device variables that will be a little tricky. but, the code itself will be generic in nature and allow for as many real lights and virtual switches as you would like to use (hopefully) :slight_smile:

if you are really interested in getting one of these options working, i will have a couple of clarifying question for you to come up with an example for that option.


#5

Thank you, really nice of you to help out.
I’m think maybe option 1 is my preferred. Smaller is good and hopefully when I’m happy with the piston it won’t be to much maintenance :slight_smile:

So yes I’m really interested.


#6

ok.

  1. i will do an example with a couple of light groups of my own and you will need to update it for all your lights and virtual switches. if that is ok with you?
  2. if there are 2 lights in a group and just 1 of the lights in the group is on should the corresponding virtual switch be on or off?

#7
  1. yes, no problem.
  2. that’s a question I have been struggling with so far. Sometimes I like to only use some of the lights and not all the lights in a group. I think it’s best if the virtual switch changes to on if a light in the group is on. So if I would like the whole group to go on I first switch the virtual switch off and then on again.

#8

try this:


#9

thanks, I will try.


#10

btw, if i was using this i wouldnt actually create the vSwitch1 … vSwitchX device variables. i would just put the right virtual switch in the corresponding with statement. so for lines 32 - 36:

instead of this:

with vSwitch1
   ...
end with

i would use this:

with Switch 21
   ...
end with

since its a virtual switch, the likelihood of me having to replace is extremely low and it makes it more efficient during runtime when you are having to run that similar statement over and over may be 100s of times a day.


#11

Ah, ok. I try that instead!


#12

Works perfectly. Thanks alot, very nice of you to help out! :slight_smile:


#13

excellent. you are welcome. :slight_smile: