(I’m starting with Homey Script )
Can you help me ? This script purpose it’s to turn on, all lights in one (or more zone). I did this as a test… but couldn’t find the issue.
let zoneName = "Bureau";
let devices = await Homey.devices.getDevices();
_.forEach(devices, async (device) => {
if (device.zoneName === zoneName && device.capabilitiesObj && device.capabilitiesObj.onoff) {
// Check if the device is a light
if (device.class === 'light') {
await Homey.devices.setCapabilityValue({
deviceId: device.id,
capabilityId: 'onoff',
value: true
});
console.log(`Turned on light: ${device.name}`);
}
}
});
Thanks
I don’t think there’s a device.zoneName property - I’m a novice myself so I could be wrong. I use device.id which returns the id of the zone the device belongs to.
I use the following to get an array of ids and names…
const zones = await Homey.zones.getZones();
and then to get the zone name for a given id, I use:
let zoneName = 'Unknown';
for (const zone of Object.values(zones)) {
if(zone.id == device.zone) {
zoneName = zone.name;
break;
}
}
You could do something similar/better to get a zone id from a zone name.
Hope it helps,
Andy
This works
Edit: for Pro 2019 that is
let zoneName = "[1.1] Keuken";
let devices = await Homey.devices.getDevices();
_.forEach(devices, async (device) => {
if (device.zoneName === zoneName && device.class === 'light') {
await Homey.devices.setCapabilityValue({
deviceId: device.id,
capabilityId: 'onoff',
value: true
});
console.log(`Turned on light in zone ${device.zoneName}: ${device.name}`);
}
});
return true;
.
It works, it gets ‘proposed’ as well
Sorry, this is @ Pro 2019
Yeah, with older Homey’s, device.zoneName
exists, for the new Homey it doesn’t
2 Likes
My guwdness. Why oh why remove it