# Turn off all lights except the ones in array

**URL:** <https://community.homey.app/t/turn-off-all-lights-except-the-ones-in-array/5183>\
**Category:** Developers\
**Tags:** zigbee, rf-433\
**Created:** [December 9, 2018, 4:03pm UTC](https://community.homey.app/t/turn-off-all-lights-except-the-ones-in-array/5183 "2018-12-09T16:03:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markus\_Sacramento](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/markus_sacramento/32/1277_2.png) [@Markus\_Sacramento](https://community.homey.app/u/Markus_Sacramento)\
**Post date:** [December 9, 2018, 4:03pm UTC](https://community.homey.app/t/turn-off-all-lights-except-the-ones-in-array/5183/1 "2018-12-09T16:03:49Z")

</div>

Found this script in the old forum:  
let devices = await Homey.devices.getDevices();  
function anyLightOn(devices) {  
let result = false;  
\_.some(devices, device =\> {  
if (device.class === ‘light’ && device.state.onoff) {  
result = true;  
}  
return result;  
});  
return result;  
}  
return anyLightOn(devices)

I would like something similar but I would lika to add an array to exclude som lights and is it possible to temporarilly store all lights turned off in a variable to make a check if light really turned off?  
I have some lights via 433MHz power plug and some ZigBee.

I’ve tried something similar bellow but it doesn’t work as expected:  
`let devices = await Homey.devices.getDevices();`

```
var DeviceNames = [
    "Kitchentable - Right",
    "Kitchentable - Middle",
    "Kitchentable - Left",
    "Lightstripp hall",
    "Master bedroom - Spotlights",
    "Master bedroom - Window lights",
    "Master bedroom - Sandra",
    "Master bedroom - Markus",
    "Second floor - Hall",
    "Livingroom - Window lights",
    "Livingroom lights"
    ];
    
    DeviceNames.forEach(function(element) {

   _.forEach(devices, device => {
        if(device.class != 'light') return;
            if(!device.state.onoff) return;
                if(!device.name != element) return;        
                        device.setCapabilityValue('onoff', false);
                            console.log(device.name);
})});
return true
```

---

<div class="post-metadata">

**Author:** ![Jamie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jamie/32/5274_2.png) [@Jamie](https://community.homey.app/u/Jamie)\
**Post date:** [December 10, 2018, 5:43am UTC](https://community.homey.app/t/turn-off-all-lights-except-the-ones-in-array/5183/2 "2018-12-10T05:43:19Z")

</div>

> [@\[APP\]\[Pro\] \< group \> (3.2.4 - Stable)](https://community.homey.app/t/groups-v1-0/3168):
>
> \< group \> With this app you can group devices with the same capabilities as one device. This means you an control multiple devices from the one place. The general approach for this application is to keep things as simple as possible, especially for the default device classes. (light, sockets, etc). To do anything other then these simple operations please use the advance (other) groups. [Donate](https://PayPal.Me/peakej)[Help me buy a homey to create this and other apps on.](https://PayPal.Me/peakej) Please note that this app now only supports v…
