# Toggle Room On or Off

**URL:** <https://community.homey.app/t/toggle-room-on-or-off/162648>\
**Category:** Questions & Help\
**Created:** [November 24, 2026, 11:09pm UTC](https://community.homey.app/t/toggle-room-on-or-off/162648 "2026-11-24T23:09:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMDPC](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jmdpc/32/121098_2.png) [@JMDPC](https://community.homey.app/u/JMDPC)\
**Post date:** [November 24, 2026, 11:09pm UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/1 "2026-11-24T23:09:07Z")

</div>

Is there a way to toggle all of the lights on or off in a room with one flow card instead of if/then logic or groups?

---

<div class="post-metadata">

**Author:** ![SaylorBennett](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/saylorbennett/32/178900_2.png) [@SaylorBennett](https://community.homey.app/u/SaylorBennett)\
**Post date:** [November 25, 2026, 5:58am UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/2 "2026-11-25T05:58:13Z")

</div>

I ran into the same thing when I started. The simplest way I found was to group the lights for the room first, then use that one group in a flow, rather than adding each light separately. It keeps the flow much tidier, and you can still turn one light on or off by itself when you need to.

---

<div class="post-metadata">

**Author:** ![McMelloW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mcmellow/32/182252_2.png) [@McMelloW](https://community.homey.app/u/McMelloW)\
**Post date:** [November 25, 2026, 8:34am UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/3 "2026-11-25T08:34:44Z")

</div>

HAve a look at the app from **Jamie Peak \< groep \>** for advanced groups etc.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [November 25, 2026, 10:04am UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/4 "2026-11-25T10:04:30Z")

</div>

Ummmm:

> [@JMDPC](#):
>
> instead of if/then logic or groups?

---

<div class="post-metadata">

**Author:** ![Hsd1965](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hsd1965/32/30160_2.png) [@Hsd1965](https://community.homey.app/u/Hsd1965)\
**Post date:** [November 25, 2026, 10:09am UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/5 "2026-11-25T10:09:53Z")

</div>

If you have defined your room as a Zone there is a card that enables you to turn all devices defined as type Lamp on or off:

 ![Screenshot 2026-11-25 110814](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/d/ed5beb25fc14389239e2dd98d9bcfd027bf359e9.png)

In this example ‘Slaapkamer’ is a zone.

Type is ‘Alle lampen’ which translates to all lamps present in the room.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [November 25, 2026, 10:10am UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/6 "2026-11-25T10:10:19Z")

</div>

A flow like this toggles the lights in a zone:

- When one ore more lights are turned on, turn all lights off:  

- When all lights are off, turn all lights on:  

You’ll find these flowcards by adding an ‘And’ or ‘Then’ card, then browse to the main zone (Home):

 ![Screenshot_20261125_110910_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/f/9f2b4bcf5d082182025b76230f75b727ad2e5fa1.jpeg)

and then browse to the preferred zone:

 ![Screenshot_20261125_110935_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/f/6f26bb35042589d3b2620803ada2c534fed707ef.jpeg)

---

<div class="post-metadata">

**Author:** ![JMDPC](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jmdpc/32/121098_2.png) [@JMDPC](https://community.homey.app/u/JMDPC)\
**Post date:** [November 25, 2026, 1:33pm UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/7 "2026-11-25T13:33:49Z")

</div>

I created a Homeyscript to do it so I don’t have to rely on groups. It toggles the lights on or off and sets the brightness and color temperature to a specific level based on variables

Any additions or comments to improve it would be very welcome

```auto
const roomName = String(args[0] ?? '').trim();
if (!roomName) {
  throw new Error('Pass a Homey zone name, such as Dining Room.');
}

const [zones, devices] = await Promise.all([
  Homey.zones.getZones(),
  Homey.devices.getDevices(),
]);

const matchingZones = Object.values(zones).filter(
  zone => zone.name.toLowerCase() === roomName.toLowerCase()
);

if (matchingZones.length === 0) {
  throw new Error(`No Homey zone named "${roomName}".`);
}
if (matchingZones.length > 1) {
  throw new Error(`More than one Homey zone is named "${roomName}".`);
}

const [zone] = matchingZones;
const lights = Object.values(devices).filter(device =>
  device.zone === zone.id &&
  (device.class === 'light' || device.virtualClass === 'light') &&
  device.available !== false &&
  typeof device.capabilitiesObj?.onoff?.value === 'boolean'
);

if (lights.length === 0) {
  throw new Error(`No available lights with a known on/off state in "${zone.name}".`);
}

const onCount = lights.filter(light => light.capabilitiesObj.onoff.value).length;
const turnOn = onCount * 2 < lights.length;

log(`${zone.name}: ${onCount}/${lights.length} on. Setting room ${turnOn ? 'ON' : 'OFF'}.`);

function canSetBrightness(light) {
  const driver = light.driverId ?? '';
  const app = light.ownerUri ?? '';
  const isShelly = /shelly/i.test(driver) || /shelly/i.test(app) || /^shelly\b/i.test(light.name);
  return !isShelly && light.capabilities.includes('dim');
}

function readPercent(setting, name) {
  const value = setting?.value;
  if (Number.isFinite(value) && value >= 0 && value <= 100) return value / 100;
  log(`Warning: ${name} must be a number from 0 to 100.`);
}

let temperature;
let brightness;
const hasTemperatureLights = lights.some(light => light.capabilities.includes('light_temperature'));
const hasBrightnessLights = lights.some(canSetBrightness);
if (turnOn && (hasTemperatureLights || hasBrightnessLights)) {
  try {
    const variables = Object.values(await Homey.logic.getVariables());
    if (hasTemperatureLights) {
      const color = variables.find(variable => variable.name === 'LightColor')
        ?? variables.find(variable => variable.name === 'ColorofLights');
      temperature = readPercent(color, 'LightColor');
    }
    if (hasBrightnessLights) {
      const dim = variables.find(variable => variable.name === 'LightBrightness');
      brightness = readPercent(dim, 'LightBrightness');
    }
  } catch (error) {
    log(`Warning: Could not read light settings: ${error.message ?? error}`);
  }
}

for (const light of lights) {
  if (light.capabilitiesObj.onoff.value !== turnOn) {
    try {
      await light.setCapabilityValue('onoff', turnOn);
    } catch (error) {
      log(`Warning: Could not switch ${light.name}: ${error.message ?? error}`);
      continue;
    }
  }

  if (brightness !== undefined && canSetBrightness(light)) {
    try {
      await light.setCapabilityValue('dim', brightness);
    } catch (error) {
      log(`Warning: Could not set brightness for ${light.name}: ${error.message ?? error}`);
    }
  }

  if (temperature === undefined || !light.capabilities.includes('light_temperature')) continue;

  try {
    if (light.capabilities.includes('light_mode') && light.capabilitiesObj.light_mode?.value === 'color') {
      await light.setCapabilityValue('light_mode', 'temperature');
    }
    await light.setCapabilityValue('light_temperature', temperature);
  } catch (error) {
    log(`Warning: Could not set color temperature for ${light.name}: ${error.message ?? error}`);
  }
}

return true;

```

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [November 25, 2026, 6:39pm UTC](https://community.homey.app/t/toggle-room-on-or-off/162648/8 "2026-11-25T18:39:03Z")

</div>

Hi,

Please format the code part as code.

Howto:  
[https://community.homey.app/t/tip-please-use-preformatted-text-for-logs-and-code-blocks-for-cleaner-posts/149488?u=peter\_kawa](https://community.homey.app/t/tip-please-use-preformatted-text-for-logs-and-code-blocks-for-cleaner-posts/149488)
