Partition wall light control

Partition wall light control #

Task #

Create a script that controls lights in all rooms where the partition walls are not closed from any switch that is located in these rooms. It's a universal solution that works for any number of partition walls with a limit of one switch / light per room.

Event script #

All input objects should have a common tag to which this event script is attached.

Modify inputs (push-buttons), sensors (true when the wall is closed) and outputs (lights) tables as needed.

Number of inputs and outputs should match and the number of sensors should be one less.

inputs = {
  '33/1/1',
  '33/1/2',
  '33/1/3',
  '33/1/4',
  '33/1/5',
}

sensors = {
  '33/2/1',
  '33/2/2',
  '33/2/3',
  '33/2/4',
}

outputs = {
  '33/3/1',
  '33/3/2',
  '33/3/3',
  '33/3/4',
  '33/3/5',
}

value = event.getvalue()

for i, addr in ipairs(inputs) do
  if addr == event.dst then
    index = i
  end
end

grp.write(outputs[ index ], value)

for i = index, #sensors do
  if grp.getvalue(sensors[ i ]) then
    break
  end

  grp.write(outputs[ i + 1 ], value)
end

for i = index - 1, 1, -1 do
  if grp.getvalue(sensors[ i ]) then
    break
  end

  grp.write(outputs[ i ], value)
end

Further assistance can be found in this forum thread