Synchronising light zones


#1

First time post so please be easy on me :slight_smile:

1) Give a description of the problem
I have 3 light zones in my house. What I want is a way of synchronising all the light zones in response to certain commands - e.g. when my switches are held I want them to synchronise all the lights and either turn them all on or off (depending on the state of the majority of the lights at that time - i.e. if 2 or more zones are on, then turn all 3 zones off, but if 2 or more zones are off, turn all 3 zones on) - but the zones must still be able to be manually overriden, so you can turn on one zone at a time.I can think of a clunky way of doing this (basically set a variable for the state of each zone, check the states against each other, determine the majority state and set the lights accordingly). Is this the best way, or is there something simpler? I’m not using virtual devices or anything like that - would that make this easier?

2) What is the expected behavior?
See above

3) What is happening/not happening?
See above (it works but it’s clunky)

Thanks in advance for any help!


#2

I am guessing that your example might be worded wrong…

If 2 or more zones are on, then turn all 3 zones off
If 2 or more zones are off, then turn all 3 zones on

This sounds like an infinite loop the way it is currently worded


#3

I think I worded it correctly (but badly!) - so what I’m saying is that if zone 1 and zone 2 are both on, and I hold down the switch, I want all the zones to switch off - because at that point, the majority of the lights are on so if I’m holding down the switch the likely desire is for all the lights to be turned off. If I just wanted to turn on zone 3, I would just press the zone 3 button. Similarly the opposite way around when 2 zones are off. Hope that makes sense.


#4

Thanks for the clarification. I am sure there’s a better way, but the way I would do it is this:

Start with all 3 zones off.

Create a Global Variable (maybe @zoneCount=0)
When any zone turns on, add 1 to @zoneCount
When any zone turns off, subtract 1 from @zoneCount

When holding down your switch:
If @zoneCount > 1
Turn off all 3 zones
Else Turn on all 3 zones

The beauty of this method is, if you have a piston that turns on 2 of the zones, you can tell that piston to add 2 to @zoneCount

I do admit though that your way (in original post) has more error correction than my suggestion. Using my method I would likely run a nightly ‘cleanup’ piston to reset that number, in case I had a glitch sometime in that past day.


#5

Maybe the best of both worlds:
Make a global variable for each of the 3 zones.
(maybe @zone1, @zone2 & @zone3)
Each variable has two choices: 1 (off) or 2 (on)

Then, when holding down your switch:
Set variable zoneCount = @zone1 + @zone2 + @zone3
If zoneCount > 4
Turn off all 3 zones
Else Turn on all 3 zones


#6

Thanks! This is similar to what I was thinking so glad I wasn’t on completely the wrong page. Here’s what I did - possibly not the most efficient way of doing it but because the switches are either “off” or “on” that needs to be translated to numbers to get something working. It seems to work, but might not be the most efficient implementation. As long as it works for now I’m happy though :slight_smile: thanks!


#7

Glad you got it working!

I have read that when using global variables, they can not be referenced in that same piston until the next run. This is why the final variable in our examples (zoneCount / Number_of_zones) should be a local variable. (ie: you can write to a global variable in any piston, but the new number will not be read back until the next time the piston runs)

And this last paragraph is just my personal preference, but I try to avoid using zero as a working variable, even though logically we think 0=off and 1=on. The reasoning is if there is an issue, and it returns (null), it will mess up your expected output. If you make off=1 and on=2 you will avoid that issue.